diff --git a/Common/Gfx/Canvas.h b/Common/Gfx/Canvas.h index 0378d7d0..1285d861 100644 --- a/Common/Gfx/Canvas.h +++ b/Common/Gfx/Canvas.h @@ -19,6 +19,7 @@ #ifndef RM_GFX_CANVAS_H_ #define RM_GFX_CANVAS_H_ +#include "FontCollection.h" #include "TextFormat.h" #include #include @@ -53,6 +54,7 @@ public: virtual HDC GetDC() = 0; virtual void ReleaseDC(HDC dc) = 0; + virtual FontCollection* CreateFontCollection() = 0; virtual TextFormat* CreateTextFormat() = 0; virtual bool IsTransparentPixel(int x, int y) = 0; diff --git a/Common/Gfx/CanvasD2D.h b/Common/Gfx/CanvasD2D.h index 198b7bf2..a1f7cea9 100644 --- a/Common/Gfx/CanvasD2D.h +++ b/Common/Gfx/CanvasD2D.h @@ -20,6 +20,7 @@ #define RM_GFX_CANVASD2D_H_ #include "Canvas.h" +#include "FontCollectionD2D.h" #include "TextFormatD2D.h" #include "WICBitmapDIB.h" #include @@ -48,7 +49,8 @@ public: virtual HDC GetDC() override; virtual void ReleaseDC(HDC dc) override; - + + virtual FontCollection* CreateFontCollection() override { return new FontCollectionD2D(); } virtual TextFormat* CreateTextFormat() override { return new TextFormatD2D(); } virtual bool IsTransparentPixel(int x, int y) override; diff --git a/Common/Gfx/CanvasGDIP.h b/Common/Gfx/CanvasGDIP.h index 455d168c..10e7f102 100644 --- a/Common/Gfx/CanvasGDIP.h +++ b/Common/Gfx/CanvasGDIP.h @@ -20,6 +20,7 @@ #define RM_GFX_CANVASGDIP_H_ #include "Canvas.h" +#include "FontCollectionGDIP.h" #include "TextFormatGDIP.h" #include #include @@ -44,6 +45,7 @@ public: virtual HDC GetDC() override; virtual void ReleaseDC(HDC dc) override; + virtual FontCollection* CreateFontCollection() override { return new FontCollectionGDIP(); } virtual TextFormat* CreateTextFormat() override { return new TextFormatGDIP(); } virtual bool IsTransparentPixel(int x, int y) override; diff --git a/Common/Gfx/FontCollection.cpp b/Common/Gfx/FontCollection.cpp new file mode 100644 index 00000000..dee01f1b --- /dev/null +++ b/Common/Gfx/FontCollection.cpp @@ -0,0 +1,31 @@ +/* + Copyright (C) 2013 Birunthan Mohanathas + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "FontCollection.h" + +namespace Gfx { + +FontCollection::FontCollection() +{ +} + +FontCollection::~FontCollection() +{ +} + +} // namespace Gfx diff --git a/Common/Gfx/FontCollection.h b/Common/Gfx/FontCollection.h new file mode 100644 index 00000000..7c3e5905 --- /dev/null +++ b/Common/Gfx/FontCollection.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2013 Birunthan Mohanathas + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef RM_GFX_FONTCOLLECTION_H_ +#define RM_GFX_FONTCOLLECTION_H_ + +#include + +namespace Gfx { + +// Interface for a collection of fonts that may or may not be installed on the system. +class __declspec(novtable) FontCollection +{ +public: + virtual ~FontCollection(); + + // Adds a file to the collection. Returns true if the file was successfully added. + virtual bool AddFile(const WCHAR* file) = 0; + +protected: + FontCollection(); + +private: + FontCollection(const FontCollection& other) {} +}; + +} // namespace Gfx + +#endif \ No newline at end of file diff --git a/Common/Gfx/FontCollectionD2D.cpp b/Common/Gfx/FontCollectionD2D.cpp new file mode 100644 index 00000000..ff784e30 --- /dev/null +++ b/Common/Gfx/FontCollectionD2D.cpp @@ -0,0 +1,38 @@ +/* + Copyright (C) 2013 Birunthan Mohanathas + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "FontCollectionD2D.h" +#include + +namespace Gfx { + +FontCollectionD2D::FontCollectionD2D() : FontCollection() +{ +} + +FontCollectionD2D::~FontCollectionD2D() +{ +} + +bool FontCollectionD2D::AddFile(const WCHAR* file) +{ + // FIXME. + return true; +} + +} // namespace Gfx diff --git a/Common/Gfx/FontCollectionD2D.h b/Common/Gfx/FontCollectionD2D.h new file mode 100644 index 00000000..2658fa39 --- /dev/null +++ b/Common/Gfx/FontCollectionD2D.h @@ -0,0 +1,48 @@ +/* + Copyright (C) 2013 Birunthan Mohanathas + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef RM_GFX_FONTCOLLECTIOND2D_H_ +#define RM_GFX_FONTCOLLECTIOND2D_H_ + +#include "FontCollection.h" + +namespace Gfx { + +// Wraps the DirectWrite IDWriteFontCollection for use with CanvasD2D. +class FontCollectionD2D final : public FontCollection +{ +public: + virtual ~FontCollectionD2D(); + + virtual bool AddFile(const WCHAR* file) override; + +protected: + FontCollectionD2D(); + +private: + friend class CanvasD2D; + friend class TextFormatD2D; + + FontCollectionD2D(const FontCollectionD2D& other) {} + + void Dispose(); +}; + +} // namespace Gfx + +#endif \ No newline at end of file diff --git a/Common/Gfx/FontCollectionGDIP.cpp b/Common/Gfx/FontCollectionGDIP.cpp new file mode 100644 index 00000000..cbcd61ec --- /dev/null +++ b/Common/Gfx/FontCollectionGDIP.cpp @@ -0,0 +1,54 @@ +/* + Copyright (C) 2013 Birunthan Mohanathas + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "FontCollectionGDIP.h" +#include + +namespace Gfx { + +FontCollectionGDIP::FontCollectionGDIP() : FontCollection(), + m_PrivateCollection() +{ +} + +FontCollectionGDIP::~FontCollectionGDIP() +{ + Dispose(); +} + +void FontCollectionGDIP::Dispose() +{ + if (m_PrivateCollection) + { + delete m_PrivateCollection; + m_PrivateCollection = nullptr; + } +} + +bool FontCollectionGDIP::AddFile(const WCHAR* file) +{ + if (!m_PrivateCollection) + { + m_PrivateCollection = new Gdiplus::PrivateFontCollection(); + } + + const Gdiplus::Status status = m_PrivateCollection->AddFontFile(file); + return status == Gdiplus::Ok; +} + +} // namespace Gfx diff --git a/Common/Gfx/FontCollectionGDIP.h b/Common/Gfx/FontCollectionGDIP.h new file mode 100644 index 00000000..1d82bbad --- /dev/null +++ b/Common/Gfx/FontCollectionGDIP.h @@ -0,0 +1,54 @@ +/* + Copyright (C) 2013 Birunthan Mohanathas + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef RM_GFX_FONTCOLLECTIONGDIP_H_ +#define RM_GFX_FONTCOLLECTIONGDIP_H_ + +#include "FontCollection.h" + +namespace Gdiplus { +class PrivateFontCollection; +} + +namespace Gfx { + +// Wraps the GDI+ PrivateFontCollection for use with CanvasGDIP. +class FontCollectionGDIP final : public FontCollection +{ +public: + virtual ~FontCollectionGDIP(); + + virtual bool AddFile(const WCHAR* file) override; + +protected: + FontCollectionGDIP(); + +private: + friend class CanvasGDIP; + friend class TextFormatGDIP; + + FontCollectionGDIP(const FontCollectionGDIP& other) {} + + void Dispose(); + + Gdiplus::PrivateFontCollection* m_PrivateCollection; +}; + +} // namespace Gfx + +#endif \ No newline at end of file diff --git a/Common/Gfx/TextFormat.h b/Common/Gfx/TextFormat.h index 418f077e..9878e5f0 100644 --- a/Common/Gfx/TextFormat.h +++ b/Common/Gfx/TextFormat.h @@ -20,10 +20,11 @@ #define RM_GFX_TEXTFORMAT_H_ #include -#include namespace Gfx { +class FontCollection; + enum class HorizontalAlignment : BYTE { Left, @@ -44,7 +45,10 @@ public: virtual ~TextFormat(); virtual bool IsInitialized() const = 0; - virtual void SetProperties(const WCHAR* fontFamily, int size, bool bold, bool italic, Gdiplus::PrivateFontCollection* fontCollection) = 0; + + virtual void SetProperties( + const WCHAR* fontFamily, int size, bool bold, bool italic, + const FontCollection* fontCollection) = 0; virtual void SetTrimming(bool trim) = 0; diff --git a/Common/Gfx/TextFormatD2D.cpp b/Common/Gfx/TextFormatD2D.cpp index 9408fadd..3289cb68 100644 --- a/Common/Gfx/TextFormatD2D.cpp +++ b/Common/Gfx/TextFormatD2D.cpp @@ -88,7 +88,9 @@ void TextFormatD2D::CreateLayout(const WCHAR* str, UINT strLen, float maxW, floa } } -void TextFormatD2D::SetProperties(const WCHAR* fontFamily, int size, bool bold, bool italic, Gdiplus::PrivateFontCollection* fontCollection) +void TextFormatD2D::SetProperties( + const WCHAR* fontFamily, int size, bool bold, bool italic, + const FontCollection* fontCollection) { Dispose(); diff --git a/Common/Gfx/TextFormatD2D.h b/Common/Gfx/TextFormatD2D.h index 476b6b0f..02cee99b 100644 --- a/Common/Gfx/TextFormatD2D.h +++ b/Common/Gfx/TextFormatD2D.h @@ -32,7 +32,10 @@ public: virtual ~TextFormatD2D(); virtual bool IsInitialized() const override { return m_TextFormat != nullptr; } - virtual void SetProperties(const WCHAR* fontFamily, int size, bool bold, bool italic, Gdiplus::PrivateFontCollection* fontCollection) override; + + virtual void SetProperties( + const WCHAR* fontFamily, int size, bool bold, bool italic, + const FontCollection* fontCollection) override; virtual void SetTrimming(bool trim) override; virtual void SetHorizontalAlignment(HorizontalAlignment alignment) override; diff --git a/Common/Gfx/TextFormatGDIP.cpp b/Common/Gfx/TextFormatGDIP.cpp index f5eaa5d6..2eb3f43d 100644 --- a/Common/Gfx/TextFormatGDIP.cpp +++ b/Common/Gfx/TextFormatGDIP.cpp @@ -17,6 +17,7 @@ */ #include "TextFormatGDIP.h" +#include "FontCollectionGDIP.h" namespace Gfx { @@ -40,8 +41,12 @@ void TextFormatGDIP::Dispose() m_Font = nullptr; } -void TextFormatGDIP::SetProperties(const WCHAR* fontFamily, int size, bool bold, bool italic, Gdiplus::PrivateFontCollection* fontCollection) +void TextFormatGDIP::SetProperties( + const WCHAR* fontFamily, int size, bool bold, bool italic, + const FontCollection* fontCollection) { + auto fontCollectionGDIP = (FontCollectionGDIP*)fontCollection; + Dispose(); m_FontFamily = new Gdiplus::FontFamily(fontFamily); @@ -51,9 +56,9 @@ void TextFormatGDIP::SetProperties(const WCHAR* fontFamily, int size, bool bold, m_FontFamily = nullptr; // Not found in system collection so try the private collection. - if (fontCollection) + if (fontCollectionGDIP && fontCollectionGDIP->m_PrivateCollection) { - m_FontFamily = new Gdiplus::FontFamily(fontFamily, fontCollection); + m_FontFamily = new Gdiplus::FontFamily(fontFamily, fontCollectionGDIP->m_PrivateCollection); if (m_FontFamily->GetLastStatus() != Gdiplus::Ok) { delete m_FontFamily; diff --git a/Common/Gfx/TextFormatGDIP.h b/Common/Gfx/TextFormatGDIP.h index 1189a5e2..8e294466 100644 --- a/Common/Gfx/TextFormatGDIP.h +++ b/Common/Gfx/TextFormatGDIP.h @@ -31,7 +31,10 @@ public: virtual ~TextFormatGDIP(); virtual bool IsInitialized() const override { return m_Font != nullptr; } - virtual void SetProperties(const WCHAR* fontFamily, int size, bool bold, bool italic, Gdiplus::PrivateFontCollection* fontCollection) override; + + virtual void SetProperties( + const WCHAR* fontFamily, int size, bool bold, bool italic, + const FontCollection* fontCollection) override; virtual void SetTrimming(bool trim) override; virtual void SetHorizontalAlignment(HorizontalAlignment alignment) override; diff --git a/Library/Library.vcxproj b/Library/Library.vcxproj index 4330307e..8dacc5b6 100644 --- a/Library/Library.vcxproj +++ b/Library/Library.vcxproj @@ -68,6 +68,9 @@ + + + @@ -287,6 +290,9 @@ + + + diff --git a/Library/Library.vcxproj.filters b/Library/Library.vcxproj.filters index 47ca06ab..ef35c777 100644 --- a/Library/Library.vcxproj.filters +++ b/Library/Library.vcxproj.filters @@ -342,9 +342,24 @@ Common + + Common\Gfx + + + Common\Gfx + Common\Gfx + + Common\Gfx + + + Common\Gfx + + + Common\Gfx + Common\Gfx @@ -354,21 +369,15 @@ Common\Gfx - - Common\Gfx - - - Common\Gfx - - - Common\Gfx - Common\Gfx Common\Gfx + + Common\Gfx + @@ -614,9 +623,24 @@ Common + + Common\Gfx + + + Common\Gfx + Common\Gfx + + Common\Gfx + + + Common\Gfx + + + Common\Gfx + Common\Gfx @@ -626,21 +650,15 @@ Common\Gfx - - Common\Gfx - - - Common\Gfx - - - Common\Gfx - Common\Gfx Common\Gfx + + Common\Gfx + diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index 06261745..3ff62099 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -157,7 +157,7 @@ void CMeterString::Initialize() m_FontSize, m_Style & BOLD, m_Style & ITALIC, - m_MeterWindow->GetPrivateFontCollection()); + m_MeterWindow->GetFontCollection()); } /* diff --git a/Library/MeterWindow.cpp b/Library/MeterWindow.cpp index d267275e..bc87d9ed 100644 --- a/Library/MeterWindow.cpp +++ b/Library/MeterWindow.cpp @@ -2096,7 +2096,7 @@ bool CMeterWindow::ReadSkin() if (find != INVALID_HANDLE_VALUE) { - m_FontCollection = new PrivateFontCollection(); + m_FontCollection = m_Canvas->CreateFontCollection(); do { @@ -2104,8 +2104,7 @@ bool CMeterWindow::ReadSkin() { std::wstring file(resourcePath, 0, resourcePath.length() - 1); file += fd.cFileName; - Status status = m_FontCollection->AddFontFile(file.c_str()); - if (status != Ok) + if (!m_FontCollection->AddFile(file.c_str())) { std::wstring error = L"Unable to load font: "; error += file.c_str(); @@ -2125,7 +2124,7 @@ bool CMeterWindow::ReadSkin() { if (!m_FontCollection) { - m_FontCollection = new PrivateFontCollection(); + m_FontCollection = m_Canvas->CreateFontCollection(); } int i = 1; @@ -2134,13 +2133,11 @@ bool CMeterWindow::ReadSkin() // Try program folder first std::wstring szFontFile = Rainmeter->GetPath() + L"Fonts\\"; szFontFile += localFont; - Status status = m_FontCollection->AddFontFile(szFontFile.c_str()); - if (status != Ok) + if (!m_FontCollection->AddFile(szFontFile.c_str())) { szFontFile = localFont; MakePathAbsolute(szFontFile); - status = m_FontCollection->AddFontFile(szFontFile.c_str()); - if (status != Ok) + if (!m_FontCollection->AddFile(szFontFile.c_str())) { std::wstring error = L"Unable to load font: "; error += localFont; diff --git a/Library/MeterWindow.h b/Library/MeterWindow.h index a9cf9df9..42d85983 100644 --- a/Library/MeterWindow.h +++ b/Library/MeterWindow.h @@ -152,11 +152,10 @@ class CMeasure; class CMeter; namespace Gfx { - class Canvas; +class FontCollection; class TextFormat; - -} // namespace Gfx +} class CMeterWindow : public CGroup { @@ -249,7 +248,7 @@ public: void MakePathAbsolute(std::wstring& path); - Gdiplus::PrivateFontCollection* GetPrivateFontCollection() { return m_FontCollection; } + Gfx::FontCollection* GetFontCollection() { return m_FontCollection; } CMeter* GetMeter(const std::wstring& meterName); CMeasure* GetMeasure(const std::wstring& measureName) { return m_Parser.GetMeasure(measureName); } @@ -460,7 +459,7 @@ private: int m_UpdateCounter; UINT m_MouseMoveCounter; - Gdiplus::PrivateFontCollection* m_FontCollection; + Gfx::FontCollection* m_FontCollection; bool m_ToolTipHidden;