aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2021-06-04 13:36:18 -0500
committerSean Hall <r.sean.hall@gmail.com>2021-06-04 14:57:11 -0500
commit34639850c2c07a35c1e502e174866cd8630eb8ec (patch)
tree3b48ca384fed9d9bcaa1b3e7762dbe706b1fbc27
parentc0fa77405e0cc1e231dfef357b9ca6e1645c1fe3 (diff)
downloadwix-34639850c2c07a35c1e502e174866cd8630eb8ec.tar.gz
wix-34639850c2c07a35c1e502e174866cd8630eb8ec.tar.bz2
wix-34639850c2c07a35c1e502e174866cd8630eb8ec.zip
Allow arbitrary strings for thmutil Font ids.
-rw-r--r--src/libs/dutil/WixToolset.DUtil/inc/thmutil.h3
-rw-r--r--src/libs/dutil/WixToolset.DUtil/thmutil.cpp52
2 files changed, 39 insertions, 16 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/thmutil.h b/src/libs/dutil/WixToolset.DUtil/inc/thmutil.h
index d21c3e17..c8c6b340 100644
--- a/src/libs/dutil/WixToolset.DUtil/inc/thmutil.h
+++ b/src/libs/dutil/WixToolset.DUtil/inc/thmutil.h
@@ -295,6 +295,8 @@ struct THEME_FONT_INSTANCE
295 295
296struct THEME_FONT 296struct THEME_FONT
297{ 297{
298 LPWSTR sczId;
299 DWORD dwIndex;
298 LONG lfHeight; 300 LONG lfHeight;
299 LONG lfWeight; 301 LONG lfWeight;
300 BYTE lfUnderline; 302 BYTE lfUnderline;
@@ -353,6 +355,7 @@ struct THEME
353 THEME_CONTROL* rgControls; 355 THEME_CONTROL* rgControls;
354 356
355 // internal state variables -- do not use outside ThmUtil.cpp 357 // internal state variables -- do not use outside ThmUtil.cpp
358 STRINGDICT_HANDLE sdhFontDictionary;
356 HWND hwndParent; // parent for loaded controls 359 HWND hwndParent; // parent for loaded controls
357 HWND hwndHover; // current hwnd hovered over 360 HWND hwndHover; // current hwnd hovered over
358 DWORD dwCurrentPageId; 361 DWORD dwCurrentPageId;
diff --git a/src/libs/dutil/WixToolset.DUtil/thmutil.cpp b/src/libs/dutil/WixToolset.DUtil/thmutil.cpp
index 5292d1e3..ab320b1d 100644
--- a/src/libs/dutil/WixToolset.DUtil/thmutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/thmutil.cpp
@@ -134,6 +134,7 @@ static HRESULT GetAttributeCoordinateOrDimension(
134 __inout int* pnValue 134 __inout int* pnValue
135 ); 135 );
136static HRESULT GetAttributeFontId( 136static HRESULT GetAttributeFontId(
137 __in THEME* pTheme,
137 __in IXMLDOMNode* pixn, 138 __in IXMLDOMNode* pixn,
138 __in LPCWSTR wzAttribute, 139 __in LPCWSTR wzAttribute,
139 __inout DWORD* pdwValue 140 __inout DWORD* pdwValue
@@ -710,6 +711,7 @@ DAPI_(void) ThemeFree(
710 ReleaseMem(pTheme->rgFonts); 711 ReleaseMem(pTheme->rgFonts);
711 712
712 ReleaseStr(pTheme->sczCaption); 713 ReleaseStr(pTheme->sczCaption);
714 ReleaseDict(pTheme->sdhFontDictionary);
713 ReleaseMem(pTheme); 715 ReleaseMem(pTheme);
714 } 716 }
715} 717}
@@ -2248,30 +2250,37 @@ LExit:
2248} 2250}
2249 2251
2250static HRESULT GetAttributeFontId( 2252static HRESULT GetAttributeFontId(
2253 __in THEME* pTheme,
2251 __in IXMLDOMNode* pixn, 2254 __in IXMLDOMNode* pixn,
2252 __in LPCWSTR wzAttribute, 2255 __in LPCWSTR wzAttribute,
2253 __inout DWORD* pdwValue 2256 __inout DWORD* pdwValue
2254 ) 2257 )
2255{ 2258{
2256 HRESULT hr = S_OK; 2259 HRESULT hr = S_OK;
2257 DWORD dwValue = 0; 2260 BSTR bstrId = NULL;
2261 THEME_FONT* pFont = NULL;
2258 BOOL fXmlFound = FALSE; 2262 BOOL fXmlFound = FALSE;
2259 2263
2260 hr = XmlGetAttributeUInt32(pixn, wzAttribute, &dwValue); 2264 hr = XmlGetAttribute(pixn, wzAttribute, &bstrId);
2261 ThmExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get font id attribute."); 2265 ThmExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed to get font id attribute.");
2262 2266
2263 if (!fXmlFound) 2267 if (!fXmlFound)
2264 { 2268 {
2265 ExitFunction1(hr = E_NOTFOUND); 2269 ExitFunction1(hr = E_NOTFOUND);
2266 } 2270 }
2267 else if (THEME_INVALID_ID == dwValue) 2271
2272 hr = DictGetValue(pTheme->sdhFontDictionary, bstrId, reinterpret_cast<void**>(&pFont));
2273 if (E_NOTFOUND == hr)
2268 { 2274 {
2269 ThmExitWithRootFailure(hr, E_INVALIDDATA, "Invalid font id value: %u", dwValue); 2275 ThmExitWithRootFailure(hr, E_INVALIDDATA, "Unknown font id: %ls", bstrId);
2270 } 2276 }
2277 ThmExitOnFailure(hr, "Failed to find font with id: %ls", bstrId);
2271 2278
2272 *pdwValue = dwValue; 2279 *pdwValue = pFont->dwIndex;
2273 2280
2274LExit: 2281LExit:
2282 ReleaseBSTR(bstrId);
2283
2275 return hr; 2284 return hr;
2276} 2285}
2277 2286
@@ -2441,7 +2450,7 @@ static HRESULT ParseWindow(
2441 pTheme->nMinimumHeight = pTheme->nDefaultDpiMinimumHeight = nValue; 2450 pTheme->nMinimumHeight = pTheme->nDefaultDpiMinimumHeight = nValue;
2442 } 2451 }
2443 2452
2444 hr = GetAttributeFontId(pixn, L"FontId", &pTheme->dwFontId); 2453 hr = GetAttributeFontId(pTheme, pixn, L"FontId", &pTheme->dwFontId);
2445 ThmExitOnRequiredXmlQueryFailure(hr, "Failed to get window FontId attribute."); 2454 ThmExitOnRequiredXmlQueryFailure(hr, "Failed to get window FontId attribute.");
2446 2455
2447 // Get the optional window icon from a resource. 2456 // Get the optional window icon from a resource.
@@ -2546,6 +2555,7 @@ static HRESULT ParseFonts(
2546 HRESULT hr = S_OK; 2555 HRESULT hr = S_OK;
2547 IXMLDOMNodeList* pixnl = NULL; 2556 IXMLDOMNodeList* pixnl = NULL;
2548 IXMLDOMNode* pixn = NULL; 2557 IXMLDOMNode* pixn = NULL;
2558 LPWSTR sczFontId = NULL;
2549 BSTR bstrName = NULL; 2559 BSTR bstrName = NULL;
2550 DWORD dwId = 0; 2560 DWORD dwId = 0;
2551 BOOL fXmlFound = FALSE; 2561 BOOL fXmlFound = FALSE;
@@ -2568,21 +2578,26 @@ static HRESULT ParseFonts(
2568 pTheme->rgFonts = static_cast<THEME_FONT*>(MemAlloc(sizeof(THEME_FONT) * pTheme->cFonts, TRUE)); 2578 pTheme->rgFonts = static_cast<THEME_FONT*>(MemAlloc(sizeof(THEME_FONT) * pTheme->cFonts, TRUE));
2569 ThmExitOnNull(pTheme->rgFonts, hr, E_OUTOFMEMORY, "Failed to allocate theme fonts."); 2579 ThmExitOnNull(pTheme->rgFonts, hr, E_OUTOFMEMORY, "Failed to allocate theme fonts.");
2570 2580
2581 hr = DictCreateWithEmbeddedKey(&pTheme->sdhFontDictionary, pTheme->cFonts, reinterpret_cast<void**>(&pTheme->rgFonts), offsetof(THEME_FONT, sczId), DICT_FLAG_NONE);
2582 ThmExitOnFailure(hr, "Failed to create font dictionary.");
2583
2571 while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL))) 2584 while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL)))
2572 { 2585 {
2573 hr = GetAttributeFontId(pixn, L"Id", &dwId); 2586 hr = XmlGetAttributeEx(pixn, L"Id", &sczFontId);
2574 ThmExitOnRequiredXmlQueryFailure(hr, "Failed to find font id."); 2587 ThmExitOnRequiredXmlQueryFailure(hr, "Failed to find font id.");
2575 2588
2576 if (pTheme->cFonts <= dwId) 2589 hr = DictKeyExists(pTheme->sdhFontDictionary, sczFontId);
2590 if (E_NOTFOUND != hr)
2577 { 2591 {
2578 ThmExitWithRootFailure(hr, E_INVALIDDATA, "Invalid theme font id: %u.", dwId); 2592 ThmExitOnFailure(hr, "Failed to check for duplicate font id.");
2593 ThmExitWithRootFailure(hr, E_INVALIDDATA, "Theme font id duplicated: %ls", sczFontId);
2579 } 2594 }
2580 2595
2581 THEME_FONT* pFont = pTheme->rgFonts + dwId; 2596 THEME_FONT* pFont = pTheme->rgFonts + dwId;
2582 if (pFont->cFontInstances) 2597 pFont->sczId = sczFontId;
2583 { 2598 sczFontId = NULL;
2584 ThmExitWithRootFailure(hr, E_INVALIDDATA, "Theme font id duplicated."); 2599 pFont->dwIndex = dwId;
2585 } 2600 ++dwId;
2586 2601
2587 pFont->lfQuality = CLEARTYPE_QUALITY; 2602 pFont->lfQuality = CLEARTYPE_QUALITY;
2588 2603
@@ -2631,6 +2646,9 @@ static HRESULT ParseFonts(
2631 ThmExitOnNull(pFont->hBackground, hr, E_OUTOFMEMORY, "Failed to create text background brush."); 2646 ThmExitOnNull(pFont->hBackground, hr, E_OUTOFMEMORY, "Failed to create text background brush.");
2632 } 2647 }
2633 2648
2649 hr = DictAddValue(pTheme->sdhFontDictionary, pFont);
2650 ThmExitOnFailure(hr, "Failed to add font to dictionary.");
2651
2634 ReleaseNullBSTR(bstrName); 2652 ReleaseNullBSTR(bstrName);
2635 ReleaseNullObject(pixn); 2653 ReleaseNullObject(pixn);
2636 } 2654 }
@@ -2643,6 +2661,7 @@ static HRESULT ParseFonts(
2643 2661
2644LExit: 2662LExit:
2645 ReleaseBSTR(bstrName); 2663 ReleaseBSTR(bstrName);
2664 ReleaseStr(sczFontId);
2646 ReleaseObject(pixn); 2665 ReleaseObject(pixn);
2647 ReleaseObject(pixnl); 2666 ReleaseObject(pixnl);
2648 2667
@@ -3185,7 +3204,7 @@ static HRESULT ParseControl(
3185 } 3204 }
3186 3205
3187 3206
3188 hr = GetAttributeFontId(pixn, L"FontId", &pControl->dwFontId); 3207 hr = GetAttributeFontId(pTheme, pixn, L"FontId", &pControl->dwFontId);
3189 ThmExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed when querying control FontId attribute."); 3208 ThmExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed when querying control FontId attribute.");
3190 3209
3191 // Parse the optional window style. 3210 // Parse the optional window style.
@@ -3291,10 +3310,10 @@ static HRESULT ParseControl(
3291 } 3310 }
3292 else if (THEME_CONTROL_TYPE_HYPERLINK == pControl->type || THEME_CONTROL_TYPE_BUTTON == pControl->type) 3311 else if (THEME_CONTROL_TYPE_HYPERLINK == pControl->type || THEME_CONTROL_TYPE_BUTTON == pControl->type)
3293 { 3312 {
3294 hr = GetAttributeFontId(pixn, L"HoverFontId", &pControl->dwFontHoverId); 3313 hr = GetAttributeFontId(pTheme, pixn, L"HoverFontId", &pControl->dwFontHoverId);
3295 ThmExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed when querying control HoverFontId attribute."); 3314 ThmExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed when querying control HoverFontId attribute.");
3296 3315
3297 hr = GetAttributeFontId(pixn, L"SelectedFontId", &pControl->dwFontSelectedId); 3316 hr = GetAttributeFontId(pTheme, pixn, L"SelectedFontId", &pControl->dwFontSelectedId);
3298 ThmExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed when querying control SelectedFontId attribute."); 3317 ThmExitOnOptionalXmlQueryFailure(hr, fXmlFound, "Failed when querying control SelectedFontId attribute.");
3299 } 3318 }
3300 else if (THEME_CONTROL_TYPE_LABEL == pControl->type) 3319 else if (THEME_CONTROL_TYPE_LABEL == pControl->type)
@@ -4697,6 +4716,7 @@ static void FreeFont(
4697 4716
4698 ReleaseMem(pFont->rgFontInstances); 4717 ReleaseMem(pFont->rgFontInstances);
4699 ReleaseStr(pFont->sczFaceName); 4718 ReleaseStr(pFont->sczFaceName);
4719 ReleaseStr(pFont->sczId);
4700 } 4720 }
4701} 4721}
4702 4722