summaryrefslogtreecommitdiff
path: root/vcl/win
diff options
context:
space:
mode:
authorKhaled Hosny <khaled@aliftype.com>2022-11-19 03:03:15 +0200
committerخالد حسني <khaled@aliftype.com>2022-11-19 12:44:10 +0100
commita80239ede3236c84d7a05d0fbc0f299811fee6c0 (patch)
tree988c3c282d356d7864c27c545292eb8a134531e6 /vcl/win
parent042473d4b162c87a27a55e9b9f076b5fc479a55a (diff)
vcl: move creating DWFontFace to WinFontFace
Change-Id: Ie0e94787d962eaec7753ae50d548ad8655dbc209 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142957 Tested-by: Jenkins Reviewed-by: خالد حسني <khaled@aliftype.com>
Diffstat (limited to 'vcl/win')
-rw-r--r--vcl/win/gdi/DWriteTextRenderer.cxx26
-rw-r--r--vcl/win/gdi/salfont.cxx28
2 files changed, 40 insertions, 14 deletions
diff --git a/vcl/win/gdi/DWriteTextRenderer.cxx b/vcl/win/gdi/DWriteTextRenderer.cxx
index 1e44d95ad2cb..c09eeb410199 100644
--- a/vcl/win/gdi/DWriteTextRenderer.cxx
+++ b/vcl/win/gdi/DWriteTextRenderer.cxx
@@ -108,7 +108,7 @@ D2DWriteTextOutRenderer::D2DWriteTextOutRenderer(bool bRenderingModeNatural)
mbRenderingModeNatural(bRenderingModeNatural),
meTextAntiAliasMode(D2DTextAntiAliasMode::Default)
{
- WinSalGraphics::getDWriteFactory(&mpDWriteFactory, &mpGdiInterop);
+ WinSalGraphics::getDWriteFactory(&mpDWriteFactory);
HRESULT hr = S_OK;
hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, __uuidof(ID2D1Factory), nullptr, reinterpret_cast<void **>(&mpD2DFactory));
if (SUCCEEDED(hr))
@@ -217,14 +217,14 @@ bool D2DWriteTextOutRenderer::performRender(GenericSalLayout const & rLayout, Sa
return ExTextOutRenderer()(rLayout, rGraphics, hDC, bRenderingModeNatural);
}
- IDWriteFontFace* pFontFace;
- float lfEmHeight = 0;
- if (!GetDWriteFaceFromHDC(hDC, &pFontFace, &lfEmHeight))
- return false;
-
const WinFontInstance& rWinFont = static_cast<const WinFontInstance&>(rLayout.GetFont());
float fHScale = rWinFont.getHScale();
+ float lfEmHeight = 0;
+ IDWriteFontFace* pFontFace = GetDWriteFace(rWinFont, &lfEmHeight);
+ if (!pFontFace)
+ return false;
+
tools::Rectangle bounds;
bool succeeded = rLayout.GetBoundRect(bounds);
if (succeeded)
@@ -276,8 +276,6 @@ bool D2DWriteTextOutRenderer::performRender(GenericSalLayout const & rLayout, Sa
if (pBrush)
pBrush->Release();
- pFontFace->Release();
-
if (hr == D2DERR_RECREATE_TARGET)
{
CreateRenderTarget(bRenderingModeNatural);
@@ -287,14 +285,14 @@ bool D2DWriteTextOutRenderer::performRender(GenericSalLayout const & rLayout, Sa
return succeeded;
}
-bool D2DWriteTextOutRenderer::GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** ppFontFace, float * lfSize) const
+IDWriteFontFace* D2DWriteTextOutRenderer::GetDWriteFace(const WinFontInstance& rWinFont,
+ float* lfSize) const
{
- bool succeeded = SUCCEEDED(CHECKHR(mpGdiInterop->CreateFontFaceFromHdc(hDC, ppFontFace)));
-
- if (succeeded)
+ auto pFontFace = rWinFont.GetFontFace()->GetDWFontFace();
+ if (pFontFace)
{
LOGFONTW aLogFont;
- HFONT hFont = static_cast<HFONT>(::GetCurrentObject(hDC, OBJ_FONT));
+ HFONT hFont = rWinFont.GetHFONT();
GetObjectW(hFont, sizeof(LOGFONTW), &aLogFont);
float dpix, dpiy;
@@ -305,7 +303,7 @@ bool D2DWriteTextOutRenderer::GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** p
*lfSize *= -1;
}
- return succeeded;
+ return pFontFace;
}
WinFontTransformGuard::WinFontTransformGuard(ID2D1RenderTarget* pRenderTarget, float fHScale,
diff --git a/vcl/win/gdi/salfont.cxx b/vcl/win/gdi/salfont.cxx
index c41d0427f5cb..1db4f0d8c2b0 100644
--- a/vcl/win/gdi/salfont.cxx
+++ b/vcl/win/gdi/salfont.cxx
@@ -51,6 +51,7 @@
#include <vcl/metric.hxx>
#include <vcl/fontcharmap.hxx>
#include <comphelper/scopeguard.hxx>
+#include <comphelper/windowserrorstring.hxx>
#include <font/FontSelectPattern.hxx>
#include <font/PhysicalFontCollection.hxx>
@@ -531,6 +532,33 @@ rtl::Reference<LogicalFontInstance> WinFontFace::CreateFontInstance(const vcl::f
return new WinFontInstance(*this, rFSD);
}
+IDWriteFontFace* WinFontFace::GetDWFontFace() const
+{
+ if (!mxDWFontFace)
+ {
+ IDWriteGdiInterop* pDWriteGdiInterop;
+ WinSalGraphics::getDWriteFactory(nullptr, &pDWriteGdiInterop);
+
+ HDC hDC(::GetDC(nullptr));
+ HFONT hFont = ::CreateFontIndirectW(&maLogFont);
+ HFONT hOldFont = ::SelectFont(hDC, hFont);
+
+ HRESULT hr = pDWriteGdiInterop->CreateFontFaceFromHdc(hDC, &mxDWFontFace);
+ if (FAILED(hr))
+ {
+ SAL_WARN("vcl.fonts", "HRESULT 0x" << OUString::number(hr, 16) << ": "
+ << WindowsErrorStringFromHRESULT(hr));
+ mxDWFontFace = nullptr;
+ }
+
+ ::SelectFont(hDC, hOldFont);
+ ::DeleteFont(hFont);
+ ::ReleaseDC(nullptr, hDC);
+ }
+
+ return mxDWFontFace;
+}
+
namespace
{
struct BlobReference