vcl/quartz/CoreTextFont.cxx | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
New commits: commit 3a1ff39d026530b3bc5f75052822fe9480034cb5 Author: Patrick Luby <[email protected]> AuthorDate: Fri Jul 11 18:18:45 2025 -0400 Commit: Adolfo Jayme Barrientos <[email protected]> CommitDate: Sat Jul 12 14:53:04 2025 +0200 tdf#159529 Use macOS font table memory directly instead of copying Per Apple's documentation, the CFDataRef returned by the CTFontCopyTable() function is "A retained reference to the font table data as a CFDataRef object. The table data is not actually copied; however, the data reference must be released." So, instead of making a copy of the CFDataRef's data, just use the CFDataRef's data pointer for the HarfBuzz blob and release the CFDataRef in the blob's destroy function. Change-Id: Ia670d036b20ca268b203eedcb1abbaad471d5384 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187761 Reviewed-by: Khaled Hosny <[email protected]> Tested-by: Jenkins Signed-off-by: Xisco Fauli <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187766 Reviewed-by: Adolfo Jayme Barrientos <[email protected]> diff --git a/vcl/quartz/CoreTextFont.cxx b/vcl/quartz/CoreTextFont.cxx index 6248a255c64e..5e6fda77bc24 100644 --- a/vcl/quartz/CoreTextFont.cxx +++ b/vcl/quartz/CoreTextFont.cxx @@ -142,6 +142,13 @@ static void MyCGPathApplierFunc(void* pData, const CGPathElement* pElement) } } +static void MyDestroyCFDataRef(void* pUserData) +{ + CFDataRef pData = static_cast<CFDataRef>(pUserData); + if (pData) + CFRelease(pData); +} + bool CoreTextFont::GetGlyphOutline(sal_GlyphId nId, basegfx::B2DPolyPolygon& rResult, bool) const { rResult.clear(); @@ -216,15 +223,20 @@ hb_blob_t* CoreTextFontFace::GetHbTable(hb_tag_t nTag) const const CFIndex nLength = pData ? CFDataGetLength(pData) : 0; if (nLength > 0) { - auto pBuffer = new UInt8[nLength]; - const CFRange aRange = CFRangeMake(0, nLength); - CFDataGetBytes(pData, aRange, pBuffer); - - pBlob = hb_blob_create(reinterpret_cast<const char*>(pBuffer), nLength, - HB_MEMORY_MODE_READONLY, pBuffer, - [](void* data) { delete[] static_cast<UInt8*>(data); }); + // tdf#159529 Use macOS font table memory directly instead of copying + // Per Apple's documentation, the CFDataRef returned by the + // CTFontCopyTable() function is "A retained reference to the + // font table data as a CFDataRef object. The table data is not + // actually copied; however, the data reference must be released." + // So, instead of making a copy of the CFDataRef's data, just use + // the CFDataRef's data pointer for the HarfBuzz blob and release + // the CFDataRef in the blob's destroy function. + pBlob = hb_blob_create(reinterpret_cast<const char*>(CFDataGetBytePtr(pData)), nLength, + HB_MEMORY_MODE_READONLY, + const_cast<void*>(static_cast<CFTypeRef>(pData)), + MyDestroyCFDataRef); } - if (pData) + else if (pData) CFRelease(pData); }
