Kaydet (Commit) f6db8af1 authored tarafından Akash Jain's avatar Akash Jain Kaydeden (comit) Khaled Hosny

GSoC: Integrate new CommonSalLayout in win/ code

Change-Id: Ifeb2fa7ca9e2cd0da1c504d4e770aa0bb1b0b0de
üst 828b8cf4
...@@ -57,7 +57,12 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU ...@@ -57,7 +57,12 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU
hb_blob_t* pBlob = nullptr; hb_blob_t* pBlob = nullptr;
if (pBuffer != nullptr) if (pBuffer != nullptr)
#if defined(_WIN32)
pBlob = hb_blob_create(reinterpret_cast<const char*>(pBuffer), nLength, HB_MEMORY_MODE_READONLY,
const_cast<unsigned char*>(pBuffer), [](void* data){ delete[] reinterpret_cast<unsigned char*>(data); });
#else
pBlob = hb_blob_create(reinterpret_cast<const char*>(pBuffer), nLength, HB_MEMORY_MODE_READONLY, nullptr, nullptr); pBlob = hb_blob_create(reinterpret_cast<const char*>(pBuffer), nLength, HB_MEMORY_MODE_READONLY, nullptr, nullptr);
#endif
return pBlob; return pBlob;
} }
...@@ -74,12 +79,18 @@ static hb_unicode_funcs_t* getUnicodeFuncs() ...@@ -74,12 +79,18 @@ static hb_unicode_funcs_t* getUnicodeFuncs()
#if defined(_WIN32) #if defined(_WIN32)
CommonSalLayout::CommonSalLayout(HDC hDC, WinFontInstance& rWinFontInstance) CommonSalLayout::CommonSalLayout(HDC hDC, WinFontInstance& rWinFontInstance)
: mhDC(hDC), : mhDC(hDC),
mhFont((HFONT)GetCurrentObject(hDC, OBJ_FONT)),
mpHbFace(nullptr), mpHbFace(nullptr),
maFontSelData(rWinFontInstance.maFontSelData) maFontSelData(rWinFontInstance.maFontSelData)
{ {
mpHbFace = hb_face_create_for_tables(getFontTable, &hDC, nullptr); mpHbFace = hb_face_create_for_tables(getFontTable, &hDC, nullptr);
} }
void CommonSalLayout::InitFont() const
{
SelectObject(mhDC, mhFont);
}
#elif defined(MACOSX) || defined(IOS) #elif defined(MACOSX) || defined(IOS)
CommonSalLayout::CommonSalLayout(const CoreTextStyle& rCoreTextStyle) CommonSalLayout::CommonSalLayout(const CoreTextStyle& rCoreTextStyle)
: mpHbFace(nullptr), : mpHbFace(nullptr),
......
...@@ -2454,7 +2454,4 @@ void WinSalGraphics::GetGlyphWidths( const PhysicalFontFace* pFont, ...@@ -2454,7 +2454,4 @@ void WinSalGraphics::GetGlyphWidths( const PhysicalFontFace* pFont,
} }
} }
void WinSalGraphics::DrawSalLayout( const CommonSalLayout& )
{}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "sft.hxx" #include "sft.hxx"
#include "sallayout.hxx" #include "sallayout.hxx"
#include "CommonSalLayout.hxx"
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
...@@ -67,7 +68,7 @@ public: ...@@ -67,7 +68,7 @@ public:
virtual ~TextOutRenderer() = default; virtual ~TextOutRenderer() = default;
virtual bool operator ()(WinLayout const &rLayout, HDC hDC, virtual bool operator ()(SalLayout const &rLayout, HDC hDC,
const Rectangle* pRectToErase, const Rectangle* pRectToErase,
Point* pPos, int* pGetNextGlypInfo) = 0; Point* pPos, int* pGetNextGlypInfo) = 0;
}; };
...@@ -81,7 +82,7 @@ public: ...@@ -81,7 +82,7 @@ public:
explicit ExTextOutRenderer() = default; explicit ExTextOutRenderer() = default;
virtual ~ExTextOutRenderer() override = default; virtual ~ExTextOutRenderer() override = default;
bool operator ()(WinLayout const &rLayout, HDC hDC, bool operator ()(SalLayout const &rLayout, HDC hDC,
const Rectangle* pRectToErase, const Rectangle* pRectToErase,
Point* pPos, int* pGetNextGlypInfo) override; Point* pPos, int* pGetNextGlypInfo) override;
}; };
...@@ -106,7 +107,7 @@ public: ...@@ -106,7 +107,7 @@ public:
explicit D2DWriteTextOutRenderer(); explicit D2DWriteTextOutRenderer();
virtual ~D2DWriteTextOutRenderer() override; virtual ~D2DWriteTextOutRenderer() override;
bool operator ()(WinLayout const &rLayout, HDC hDC, bool operator ()(SalLayout const &rLayout, HDC hDC,
const Rectangle* pRectToErase, const Rectangle* pRectToErase,
Point* pPos, int* pGetNextGlypInfo) override; Point* pPos, int* pGetNextGlypInfo) override;
...@@ -138,7 +139,7 @@ private: ...@@ -138,7 +139,7 @@ private:
D2DWriteTextOutRenderer & operator = (const D2DWriteTextOutRenderer &) = delete; D2DWriteTextOutRenderer & operator = (const D2DWriteTextOutRenderer &) = delete;
bool GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** ppFontFace, float * lfSize) const; bool GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** ppFontFace, float * lfSize) const;
bool GetDWriteInkBox(IDWriteFontFace & rFontFace, WinLayout const &rLayout, float const lfEmHeight, Rectangle &) const; bool GetDWriteInkBox(IDWriteFontFace & rFontFace, SalLayout const &rLayout, float const lfEmHeight, Rectangle &) const;
ID2D1Factory * mpD2DFactory; ID2D1Factory * mpD2DFactory;
IDWriteFactory * mpDWriteFactory; IDWriteFactory * mpDWriteFactory;
...@@ -3483,7 +3484,7 @@ TextOutRenderer & TextOutRenderer::get() ...@@ -3483,7 +3484,7 @@ TextOutRenderer & TextOutRenderer::get()
} }
bool ExTextOutRenderer::operator ()(WinLayout const &rLayout, HDC hDC, bool ExTextOutRenderer::operator ()(SalLayout const &rLayout, HDC hDC,
const Rectangle* pRectToErase, const Rectangle* pRectToErase,
Point* pPos, int* pGetNextGlypInfo) Point* pPos, int* pGetNextGlypInfo)
{ {
...@@ -3542,7 +3543,7 @@ D2DWriteTextOutRenderer::~D2DWriteTextOutRenderer() ...@@ -3542,7 +3543,7 @@ D2DWriteTextOutRenderer::~D2DWriteTextOutRenderer()
CleanupModules(); CleanupModules();
} }
bool D2DWriteTextOutRenderer::operator ()(WinLayout const &rLayout, HDC hDC, bool D2DWriteTextOutRenderer::operator ()(SalLayout const &rLayout, HDC hDC,
const Rectangle* pRectToErase, const Rectangle* pRectToErase,
Point* pPos, int* pGetNextGlypInfo) Point* pPos, int* pGetNextGlypInfo)
{ {
...@@ -3708,7 +3709,7 @@ bool D2DWriteTextOutRenderer::GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** p ...@@ -3708,7 +3709,7 @@ bool D2DWriteTextOutRenderer::GetDWriteFaceFromHDC(HDC hDC, IDWriteFontFace ** p
return succeeded; return succeeded;
} }
bool D2DWriteTextOutRenderer::GetDWriteInkBox(IDWriteFontFace & rFontFace, WinLayout const &rLayout, float const /*lfEmHeight*/, Rectangle & rOut) const bool D2DWriteTextOutRenderer::GetDWriteInkBox(IDWriteFontFace & rFontFace, SalLayout const &rLayout, float const /*lfEmHeight*/, Rectangle & rOut) const
{ {
rOut.SetEmpty(); rOut.SetEmpty();
...@@ -3903,66 +3904,73 @@ SalLayout* WinSalGraphics::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackLe ...@@ -3903,66 +3904,73 @@ SalLayout* WinSalGraphics::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackLe
const WinFontFace& rFontFace = *mpWinFontData[ nFallbackLevel ]; const WinFontFace& rFontFace = *mpWinFontData[ nFallbackLevel ];
WinFontInstance& rFontInstance = *mpWinFontEntry[ nFallbackLevel ]; WinFontInstance& rFontInstance = *mpWinFontEntry[ nFallbackLevel ];
bool bUseOpenGL = OpenGLHelper::isVCLOpenGLEnabled() && !mbPrinter; if (getenv("SAL_USE_COMMON_LAYOUT"))
if (!bUspInited)
InitUSP();
if( !(rArgs.mnFlags & SalLayoutFlags::ComplexDisabled) )
{ {
#if ENABLE_GRAPHITE return new CommonSalLayout(getHDC(), rFontInstance);
if (rFontFace.SupportsGraphite())
{
pWinLayout = new GraphiteWinLayout(getHDC(), rFontFace, rFontInstance, bUseOpenGL);
}
else
#endif // ENABLE_GRAPHITE
{
// script complexity is determined in upper layers
pWinLayout = new UniscribeLayout(getHDC(), rFontFace, rFontInstance, bUseOpenGL);
// NOTE: it must be guaranteed that the WinSalGraphics lives longer than
// the created UniscribeLayout, otherwise the data passed into the
// constructor might become invalid too early
}
} }
else else
{ {
#if ENABLE_GRAPHITE bool bUseOpenGL = OpenGLHelper::isVCLOpenGLEnabled() && !mbPrinter;
if (rFontFace.SupportsGraphite())
{
pWinLayout = new GraphiteWinLayout(getHDC(), rFontFace, rFontInstance, bUseOpenGL);
}
else
#endif // ENABLE_GRAPHITE
{
static bool bAvoidSimpleWinLayout = (std::getenv("VCL_NO_SIMPLEWINLAYOUT") != nullptr);
if (!bAvoidSimpleWinLayout) if (!bUspInited)
{ InitUSP();
if( (rArgs.mnFlags & SalLayoutFlags::KerningPairs) && !rFontInstance.HasKernData() )
{
// TODO: directly cache kerning info in the rFontInstance
// TODO: get rid of kerning methods+data in WinSalGraphics object
GetKernPairs();
rFontInstance.SetKernData( mnFontKernPairCount, mpFontKernPairs );
}
pWinLayout = new SimpleWinLayout(getHDC(), rFontFace, rFontInstance, bUseOpenGL); if( !(rArgs.mnFlags & SalLayoutFlags::ComplexDisabled) )
{
#if ENABLE_GRAPHITE
if (rFontFace.SupportsGraphite())
{
pWinLayout = new GraphiteWinLayout(getHDC(), rFontFace, rFontInstance, bUseOpenGL);
} }
else else
#endif // ENABLE_GRAPHITE
{ {
// script complexity is determined in upper layers
pWinLayout = new UniscribeLayout(getHDC(), rFontFace, rFontInstance, bUseOpenGL); pWinLayout = new UniscribeLayout(getHDC(), rFontFace, rFontInstance, bUseOpenGL);
// NOTE: it must be guaranteed that the WinSalGraphics lives longer than // NOTE: it must be guaranteed that the WinSalGraphics lives longer than
// the created UniscribeLayout, otherwise the data passed into the // the created UniscribeLayout, otherwise the data passed into the
// constructor might become invalid too early // constructor might become invalid too early
} }
} }
} else
{
#if ENABLE_GRAPHITE
if (rFontFace.SupportsGraphite())
{
pWinLayout = new GraphiteWinLayout(getHDC(), rFontFace, rFontInstance, bUseOpenGL);
}
else
#endif // ENABLE_GRAPHITE
{
static bool bAvoidSimpleWinLayout = (std::getenv("VCL_NO_SIMPLEWINLAYOUT") != nullptr);
if( mfFontScale[nFallbackLevel] != 1.0 ) if (!bAvoidSimpleWinLayout)
pWinLayout->SetFontScale( mfFontScale[nFallbackLevel] ); {
if( (rArgs.mnFlags & SalLayoutFlags::KerningPairs) && !rFontInstance.HasKernData() )
{
// TODO: directly cache kerning info in the rFontInstance
// TODO: get rid of kerning methods+data in WinSalGraphics object
GetKernPairs();
rFontInstance.SetKernData( mnFontKernPairCount, mpFontKernPairs );
}
return pWinLayout; pWinLayout = new SimpleWinLayout(getHDC(), rFontFace, rFontInstance, bUseOpenGL);
}
else
{
pWinLayout = new UniscribeLayout(getHDC(), rFontFace, rFontInstance, bUseOpenGL);
// NOTE: it must be guaranteed that the WinSalGraphics lives longer than
// the created UniscribeLayout, otherwise the data passed into the
// constructor might become invalid too early
}
}
}
if( mfFontScale[nFallbackLevel] != 1.0 )
pWinLayout->SetFontScale( mfFontScale[nFallbackLevel] );
return pWinLayout;
}
} }
int WinSalGraphics::GetMinKashidaWidth() int WinSalGraphics::GetMinKashidaWidth()
...@@ -4071,4 +4079,32 @@ LogicalFontInstance* WinFontFace::CreateFontInstance( FontSelectPattern& rFSD ) ...@@ -4071,4 +4079,32 @@ LogicalFontInstance* WinFontFace::CreateFontInstance( FontSelectPattern& rFSD )
return pFontInstance; return pFontInstance;
} }
void WinSalGraphics::DrawSalLayout(const CommonSalLayout& rLayout)
{
HDC hDC = getHDC();
if (getenv("SAL_DWRITE_COMMON_LAYOUT"))
{
Point aPos(0, 0);
int nGlyphCount(0);
TextOutRenderer &render = TextOutRenderer::get();
bool result = render(rLayout, hDC, nullptr, &aPos, &nGlyphCount);
assert(!result);
}
else
{
Point aPos;
sal_GlyphId aGlyphId;
int nFetchedGlyphs = 0;
UINT oldTa = GetTextAlign(hDC);
SetTextAlign(hDC, (oldTa & ~TA_NOUPDATECP));
while (rLayout.GetNextGlyphs(1, &aGlyphId, aPos, nFetchedGlyphs))
{
ExtTextOutW(hDC, aPos.X(), aPos.Y(), ETO_GLYPH_INDEX, nullptr, reinterpret_cast<LPCWSTR>(&aGlyphId),
1, nullptr);
}
SetTextAlign(hDC, oldTa);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment