Skip to content

Commit

Permalink
- Fix Windows 7 specific blank list bug after refreshing list.
Browse files Browse the repository at this point in the history
- Add warning if running on pre-Windows 10 OS about limited functionality.
- If full font name is empty, concatenate family and face name.
- Remove old SDK header usage. Use 10.0.16299.0.
- Enable precompiled headers.
  • Loading branch information
fdwr committed Dec 23, 2018
1 parent dab92f6 commit 4731ea2
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 114 deletions.
68 changes: 40 additions & 28 deletions FontSetViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ HRESULT CopyImageToClipboard(HWND hwnd, HDC hdc, bool isUpsideDown);
namespace
{
std::wstring g_dwriteDllName = L"dwrite.dll"; // Point elsewhere to load a custom one.
bool g_startBlankList = true;
bool g_startBlankList = false;

const static wchar_t* g_locales[][2] = {
{ L"English US", L"en-US"},
Expand Down Expand Up @@ -814,13 +814,12 @@ namespace


int APIENTRY wWinMain(
HINSTANCE hInstance,
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR commandLine,
int nCmdShow
)
{

// The Microsoft Security Development Lifecycle recommends that all
// applications include the following call to ensure that heap corruptions
// do not go unnoticed and therefore do not introduce opportunities
Expand Down Expand Up @@ -935,6 +934,14 @@ HRESULT MainWindow::Initialize()
OnMove();
OnSize(); // update size and reflow

// Check if it's an older version of DirectWrite, like Windows 7, displaying warning in log.
ComPtr<IDWriteFactory3> factory3;
dwriteFactory_->QueryInterface(OUT &factory3);
if (factory3 == nullptr)
{
AppendLog(AppendLogModeImmediate, L"Windows version is older than Windows 10. Application will have very limited functionality.\r\n");
}

InitializeLanguageMenu();
InitializeFontCollectionFilterUI();
InitializeFontCollectionListUI();
Expand Down Expand Up @@ -2338,10 +2345,8 @@ HRESULT MainWindow::InitializeBlankFontCollection()
}
else
{
IFR(dwriteFactory_->GetSystemFontCollection(OUT &fontCollection_));

IFR(CreateFontCollection(
dwriteFactory3,
dwriteFactory_,
L"",
0,
OUT &fontCollection_
Expand Down Expand Up @@ -2382,7 +2387,9 @@ HRESULT MainWindow::RebuildFontCollectionList()
ComPtr<IDWriteFontCollection1> fontCollection1;
fontCollection_->QueryInterface(OUT &fontCollection1);
if (fontCollection1 != nullptr)
{
fontCollection1->GetFontSet(OUT &fontSet_);
}
}
}

Expand Down Expand Up @@ -2539,26 +2546,20 @@ HRESULT MainWindow::RebuildFontCollectionList()

std::vector<ComPtr<IDWriteFont> > fontCollectionFonts;

if (fontCollection_ != previousFontCollection_)
for (uint32_t i = 0, ci = fontCollection_->GetFontFamilyCount(); i < ci; ++i)
{
previousFontCollection_ = fontCollection_;
fontCollectionFonts.clear();
ComPtr<IDWriteFontFamily> fontFamily;
fontCollection_->GetFontFamily(i, OUT &fontFamily);

for (uint32_t i = 0, ci = fontCollection_->GetFontFamilyCount(); i < ci; ++i)
if (fontFamily == nullptr) continue;
for (uint32_t j = 0, cj = fontFamily->GetFontCount(); j < cj; ++j)
{
ComPtr<IDWriteFontFamily> fontFamily;
fontCollection_->GetFontFamily(i, OUT &fontFamily);
ComPtr<IDWriteFont> font;
fontFamily->GetFont(j, OUT &font);
if (font == nullptr || font->GetSimulations() != DWRITE_FONT_SIMULATIONS_NONE)
continue;

if (fontFamily == nullptr) continue;
for (uint32_t j = 0, cj = fontFamily->GetFontCount(); j < cj; ++j)
{
ComPtr<IDWriteFont> font;
fontFamily->GetFont(j, OUT &font);
if (font == nullptr || font->GetSimulations() != DWRITE_FONT_SIMULATIONS_NONE)
continue;

fontCollectionFonts.push_back(font);
}
fontCollectionFonts.push_back(font);
}
}

Expand Down Expand Up @@ -2656,15 +2657,15 @@ HRESULT MainWindow::GetFontProperty(
break;

case FontCollectionFilterMode::WssFamilyName:
GetFontFamilyName(font, languageName, OUT fontPropertyValue);
GetFontFamilyNameWws(font, languageName, OUT fontPropertyValue);
return S_OK;

case FontCollectionFilterMode::TypographicFamilyName:
stringId = DWRITE_INFORMATIONAL_STRING_PREFERRED_FAMILY_NAMES;
break;

case FontCollectionFilterMode::WssFaceName:
GetFaceNames(font, languageName, OUT fontPropertyValue);
GetFontFaceNameWws(font, languageName, OUT fontPropertyValue);
return S_OK;

case FontCollectionFilterMode::TypographicFaceName:
Expand Down Expand Up @@ -2692,7 +2693,7 @@ HRESULT MainWindow::GetFontProperty(
wchar_t const* tags = nullptr;
wchar_t const* scripts = nullptr;
std::wstring familyName;
GetFontFamilyName(font, languageName, OUT familyName);
GetFontFamilyNameWws(font, languageName, OUT familyName);
FindTagsFromKnownFontName(
nullptr, // fullFontName
familyName.c_str(),
Expand Down Expand Up @@ -2806,7 +2807,18 @@ HRESULT MainWindow::GetFontProperty(
// The preferred name is often empty, so use the normal family name in that case.
if (fontPropertyValue.empty() && stringId == DWRITE_INFORMATIONAL_STRING_PREFERRED_FAMILY_NAMES)
{
GetFontFamilyName(font, languageName, OUT fontPropertyValue);
GetFontFamilyNameWws(font, languageName, OUT fontPropertyValue);
}

// The full font name really shouldn't be empty, but if it is, concatenate the family and face name.
if (fontPropertyValue.empty() && stringId == DWRITE_INFORMATIONAL_STRING_FULL_NAME)
{
std::wstring familyName, faceName;
GetFontFamilyNameWws(font, languageName, OUT familyName);
GetFontFaceNameWws(font, languageName, OUT faceName);
familyName += L" ";
familyName += faceName;
fontPropertyValue = std::move(familyName);
}

return S_OK;
Expand Down Expand Up @@ -2858,7 +2870,7 @@ HRESULT MainWindow::AddFontToFontCollectionList(
fontCollectionListStringMap_.insert(std::pair<std::wstring, uint32_t>(name, static_cast<uint32_t>(fontCollectionList_.size())));

std::wstring fontFamilyName;
GetFontFamilyName(font, languageName, OUT fontFamilyName);
GetFontFamilyNameWws(font, languageName, OUT fontFamilyName);

FontCollectionEntry entry = {
name,
Expand Down Expand Up @@ -2907,7 +2919,7 @@ HRESULT MainWindow::PushFilter(

const FontCollectionEntry& entry = fontCollectionList_[selectedFontIndex];

#if 0
#if 0 // Debug to show all properties to log window.
if (filterMode_ == FontCollectionFilterMode::None)
{
std::wstring fontPropertyValue;
Expand Down
1 change: 0 additions & 1 deletion FontSetViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ class MainWindow
ComPtr<IDWriteBitmapRenderTarget> renderTarget_;
ComPtr<IDWriteFontSet> fontSet_;
ComPtr<IDWriteFontCollection> fontCollection_;
IDWriteFontCollection* previousFontCollection_ = nullptr; // weak pointer - no strong ref

uint32_t fontColor_ = 0xFF000000;
uint32_t backgroundColor_ = 0xFFFFFFFF;
Expand Down
21 changes: 19 additions & 2 deletions FontSetViewer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{04E57A88-8763-438D-8E73-8573C01A6AC4}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down Expand Up @@ -96,6 +96,8 @@
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<Optimization>Disabled</Optimization>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>precomp.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<TargetMachine>MachineX86</TargetMachine>
Expand All @@ -110,6 +112,8 @@
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<WarningLevel>Level3</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>precomp.h</PrecompiledHeaderFile>
</ClCompile>
<Link>
<TargetMachine>MachineX86</TargetMachine>
Expand All @@ -124,13 +128,21 @@
<Link>
<AdditionalDependencies>d2d1.lib;DWrite.lib;comctl32.lib;msimg32.lib;usp10.lib;shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
<ClCompile>
<PrecompiledHeaderFile>precomp.h</PrecompiledHeaderFile>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Link>
<AdditionalDependencies>d2d1.lib;DWrite.lib;comctl32.lib;msimg32.lib;usp10.lib;shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<ClCompile>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>precomp.h</PrecompiledHeaderFile>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
Expand All @@ -141,7 +153,12 @@
<ClCompile Include="common\WindowUtility.cpp" />
<ClCompile Include="FontSetViewer.cpp" />
<ClCompile Include="font\DWritEx.cpp" />
<ClCompile Include="precomp.cpp" />
<ClCompile Include="precomp.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="common\AutoResource.h" />
Expand Down
23 changes: 23 additions & 0 deletions License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
MIT License with more permissive conditions

Copyright (c) 2018 Dwayne Robinson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
substantial portions of the software. Copyright and attribution may be omitted
from copied code snippets or even entire code files, so long as the project
isn't copied in substantial whole and marked as your own.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 0 additions & 20 deletions common/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,6 @@
#include "precomp.h"


#if 0
bool TestBit(void const* memoryBase, uint32_t bitIndex) throw()
{
return _bittest( reinterpret_cast<long const*>(memoryBase), bitIndex) != 0;
}


bool ClearBit(void* memoryBase, uint32_t bitIndex) throw()
{
return _bittestandreset( reinterpret_cast<long*>(memoryBase), bitIndex) != 0;
}


bool SetBit(void* memoryBase, uint32_t bitIndex) throw()
{
return _bittestandset( reinterpret_cast<long*>(memoryBase), bitIndex) != 0;
}
#endif


// Internal version. Should call the other two overloads publicly.
void GetFormattedString(IN OUT std::wstring& returnString, bool shouldConcatenate, const wchar_t* formatString, va_list vargs)
{
Expand Down
18 changes: 0 additions & 18 deletions common/sources

This file was deleted.

8 changes: 4 additions & 4 deletions font/DWritEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class CustomCollectionLocalFontFileEnumerator : public ComBase<IDWriteFontFileEn
uint32_t fontFileNamesSize
) throw()
{
if (factory == nullptr || fontFileNames == nullptr || !fontFileNames[0])
if (factory == nullptr || fontFileNames == nullptr)
return E_INVALIDARG;

factory_ = factory;
Expand Down Expand Up @@ -610,7 +610,7 @@ HRESULT GetLocalizedString(
}


HRESULT GetFaceNames(
HRESULT GetFontFaceNameWws(
IDWriteFont* font,
_In_z_ wchar_t const* languageName,
OUT std::wstring& value
Expand All @@ -628,7 +628,7 @@ HRESULT GetFaceNames(
}


HRESULT GetFontFamilyName(
HRESULT GetFontFamilyNameWws(
IDWriteFont* font,
_In_z_ wchar_t const* languageName,
OUT std::wstring& value
Expand All @@ -648,7 +648,7 @@ HRESULT GetFontFamilyName(
}


HRESULT GetFontFamilyName(
HRESULT GetFontFamilyNameWws(
IDWriteFontFamily* fontFamily,
_In_z_ wchar_t const* languageName,
OUT std::wstring& value
Expand Down
6 changes: 3 additions & 3 deletions font/DWritEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ HRESULT GetLocalizedString(
OUT std::wstring& value
) throw();

HRESULT GetFaceNames(
HRESULT GetFontFaceNameWws(
IDWriteFont* font,
_In_z_ wchar_t const* languageName,
OUT std::wstring& value
);

// Returns the family name of thte font (in the language requested, if available, else the default English name).
HRESULT GetFontFamilyName(
HRESULT GetFontFamilyNameWws(
IDWriteFont* font,
_In_z_ wchar_t const* languageName,
OUT std::wstring& value
) throw();

HRESULT GetFontFamilyName(
HRESULT GetFontFamilyNameWws(
IDWriteFontFamily* fontFamily,
_In_z_ wchar_t const* languageName,
OUT std::wstring& value
Expand Down
17 changes: 0 additions & 17 deletions font/sources

This file was deleted.

7 changes: 0 additions & 7 deletions precomp.inc
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,9 @@
//////////////////////////////
// DirectX headers

#if 1 // Newer version if SDK is older.
#include "sdk_headers/DCommon.h"
#include "sdk_headers/DWrite_3.h"
#else
#include <DWrite_3.h>
#endif

#include <D2d1.h>
#include <D2d1Helper.h>
//#include <WinCodec.h>

//////////////////////////////
// Common headers
Expand Down
Loading

0 comments on commit 4731ea2

Please # to comment.