From cfcf0dfcd2bf350edfee6336a9876d872daa5c4a Mon Sep 17 00:00:00 2001 From: Filip Sykala Date: Wed, 29 Sep 2021 17:35:58 +0200 Subject: [PATCH] Fix for loading collection(.ttc) from font dialog --> HFONT --- src/libslic3r/Emboss.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libslic3r/Emboss.cpp b/src/libslic3r/Emboss.cpp index 8da400977c..f2b73436eb 100644 --- a/src/libslic3r/Emboss.cpp +++ b/src/libslic3r/Emboss.cpp @@ -398,18 +398,22 @@ std::optional Emboss::load_font(HFONT hfont) return {}; } + // To retrieve the data from the beginning of the file for TrueType + // Collection files specify 'ttcf' (0x66637474). + DWORD dwTable = 0x66637474; + DWORD dwOffset = 0; + ::SelectObject(hdc, hfont); - size_t size = ::GetFontData(hdc, 0, 0, NULL, 0); - if (size == 0) { + size_t size = ::GetFontData(hdc, dwTable, dwOffset, NULL, 0); + if (size == 0 || size == GDI_ERROR) { std::cerr << "HFONT doesn't have size."; ::DeleteDC(hdc); return {}; } std::vector buffer(size); - size_t loaded_size = ::GetFontData(hdc, 0, 0, buffer.data(), size); + size_t loaded_size = ::GetFontData(hdc, dwTable, dwOffset, buffer.data(), size); ::DeleteDC(hdc); - if (size != loaded_size) { std::cerr << "Different loaded(from HFONT) data size."; return {};