mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Gfx: Add Util::GetAdjustedDWriteTextLayoutMetrics to reduce code duplication
This commit is contained in:
@ -18,10 +18,34 @@
|
||||
|
||||
#include "DWriteHelpers.h"
|
||||
#include <wrl/client.h>
|
||||
#include <cmath>
|
||||
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
DWRITE_TEXT_METRICS GetAdjustedDWriteTextLayoutMetrics(
|
||||
IDWriteTextLayout* textLayout, bool gdiEmulation)
|
||||
{
|
||||
DWRITE_TEXT_METRICS metrics;
|
||||
textLayout->GetMetrics(&metrics);
|
||||
|
||||
if (gdiEmulation)
|
||||
{
|
||||
float size = 0.0f;
|
||||
textLayout->GetFontSize(0, &size);
|
||||
metrics.width = floor(metrics.width + (size / 2.05f) + (metrics.width / 55.0f) - 0.5f);
|
||||
metrics.height = floor(metrics.height + (size / 9.25f) + 0.3f);
|
||||
}
|
||||
else
|
||||
{
|
||||
// GDI+ draws multi-line text even though the last line may be clipped slightly at the bottom.
|
||||
// This is a workaround to emulate that behaviour.
|
||||
metrics.height += 1.0f;
|
||||
}
|
||||
|
||||
return metrics;
|
||||
}
|
||||
|
||||
HRESULT GetDWritePropertiesFromGDIProperties(
|
||||
IDWriteFactory* factory, const WCHAR* gdiFamilyName, const bool gdiBold, const bool gdiItalic,
|
||||
DWRITE_FONT_WEIGHT& dwriteFontWeight, DWRITE_FONT_STYLE& dwriteFontStyle,
|
||||
|
@ -24,6 +24,11 @@
|
||||
namespace Gfx {
|
||||
namespace Util {
|
||||
|
||||
// If |gdiEmulation| is true, the returns metrics have similar characteristics to those provided
|
||||
// by GDI+.
|
||||
DWRITE_TEXT_METRICS GetAdjustedDWriteTextLayoutMetrics(
|
||||
IDWriteTextLayout* textLayout, bool gdiEmulation);
|
||||
|
||||
// Maps the GDI family name and italic/bold flags to the DirectWrite family name, weight, style,
|
||||
// and stretch.
|
||||
HRESULT GetDWritePropertiesFromGDIProperties(
|
||||
|
Reference in New Issue
Block a user