diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2020-03-16 15:08:11 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2020-03-18 10:48:19 +0100 |
commit | 271e8c99a2a1e28b7eb9fdc5fe16f8be1e8ee763 (patch) | |
tree | 9235764f08b015ec92716c1f6f1cf777e55ca3cc /external | |
parent | 2ff6fce634ff173b9eb8a703b7f2f265f6e3ecb1 (diff) |
implement text rendering using directly Skia (Windows)
The Windows code needed for Skia text rendering. Like with the X11
code, the font is slightly lighter than with Skia disabled, but
otherwise it seems to work.
And like the X11 code this also requires patching Skia to use
the font we want.
Change-Id: Ib5ba52e4ba51b6523617072b77ed5446e7343f46
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90582
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'external')
-rw-r--r-- | external/skia/UnpackedTarball_skia.mk | 1 | ||||
-rw-r--r-- | external/skia/windows-hfont-typeface.patch.0 | 134 |
2 files changed, 135 insertions, 0 deletions
diff --git a/external/skia/UnpackedTarball_skia.mk b/external/skia/UnpackedTarball_skia.mk index 6ffde2006590..42276177ab33 100644 --- a/external/skia/UnpackedTarball_skia.mk +++ b/external/skia/UnpackedTarball_skia.mk @@ -28,6 +28,7 @@ skia_patches := \ msvc-vectorcall-sse.patch.1 \ clang11-flax-vector-conversion.patch.0 \ fontconfig-get-typeface.patch.0 \ + windows-hfont-typeface.patch.0 \ $(eval $(call gb_UnpackedTarball_set_patchlevel,skia,1)) diff --git a/external/skia/windows-hfont-typeface.patch.0 b/external/skia/windows-hfont-typeface.patch.0 new file mode 100644 index 000000000000..459595a7b3d6 --- /dev/null +++ b/external/skia/windows-hfont-typeface.patch.0 @@ -0,0 +1,134 @@ +--- ./include/ports/SkTypeface_win.h.sav 2019-09-19 11:38:00.943185300 +0200 ++++ ./include/ports/SkTypeface_win.h 2020-03-16 15:11:38.347067100 +0100 +@@ -28,6 +28,8 @@ + */ + SK_API SkTypeface* SkCreateTypefaceFromLOGFONT(const LOGFONT&); + ++SK_API SkTypeface* SkCreateTypefaceFromLOGFONT(const LOGFONT&, HFONT); ++ + /** + * Copy the LOGFONT associated with this typeface into the lf parameter. Note + * that the lfHeight will need to be set afterwards, since the typeface does +--- ./src/ports/SkFontHost_win.cpp.sav 2020-03-16 15:22:02.620518100 +0100 ++++ ./src/ports/SkFontHost_win.cpp 2020-03-16 15:27:12.733594400 +0100 +@@ -215,6 +215,11 @@ + , fFont(::CreateFontIndirect(&lf)) + , fSavefont((HFONT)::SelectObject(fHdc, fFont)) + { } ++ explicit SkAutoHDC(const HFONT hf) ++ : fHdc(::CreateCompatibleDC(nullptr)) ++ , fFont(nullptr) ++ , fSavefont((HFONT)::SelectObject(fHdc, hf)) ++ { } + ~SkAutoHDC() { + if (fHdc) { + ::SelectObject(fHdc, fSavefont); +@@ -238,8 +243,22 @@ + : SkTypeface(style, false) + , fLogFont(lf) + , fSerializeAsStream(serializeAsStream) ++ , hFont(nullptr) + { + SkAutoHDC hdc(fLogFont); ++ init(hdc, style, lf); ++ } ++ LogFontTypeface(const SkFontStyle& style, const LOGFONT& lf, HFONT hf, bool serializeAsStream) ++ : SkTypeface(style, false) ++ , fLogFont(lf) ++ , fSerializeAsStream(serializeAsStream) ++ , hFont(hf) ++ { ++ SkAutoHDC hdc(hFont); ++ init(hdc, style, lf); ++ } ++ void init(SkAutoHDC& hdc, const SkFontStyle& style, const LOGFONT& lf) ++ { + TEXTMETRIC textMetric; + if (0 == GetTextMetrics(hdc, &textMetric)) { + call_ensure_accessible(lf); +@@ -260,6 +279,7 @@ + } + + LOGFONT fLogFont; ++ HFONT hFont; + bool fSerializeAsStream; + bool fCanBeLCD; + +@@ -267,6 +287,10 @@ + return sk_sp<LogFontTypeface>(new LogFontTypeface(get_style(lf), lf, false)); + } + ++ static sk_sp<LogFontTypeface> Make(const LOGFONT& lf, HFONT hf) { ++ return sk_sp<LogFontTypeface>(new LogFontTypeface(get_style(lf), lf, hf, false)); ++ } ++ + static void EnsureAccessible(const SkTypeface* face) { + call_ensure_accessible(static_cast<const LogFontTypeface*>(face)->fLogFont); + } +@@ -348,7 +372,7 @@ + */ + SkTypeface* SkCreateTypefaceFromLOGFONT(const LOGFONT& origLF) { + LOGFONT lf = origLF; +- make_canonical(&lf); ++// make_canonical(&lf); + sk_sp<SkTypeface> face = SkTypefaceCache::FindByProcAndRef(FindByLogFont, &lf); + if (!face) { + face = LogFontTypeface::Make(lf); +@@ -357,12 +381,33 @@ + return face.release(); + } + ++static bool FindByLogFontAndHFont(SkTypeface* face, void* ctx) { ++ LogFontTypeface* lface = static_cast<LogFontTypeface*>(face); ++ const std::pair<LOGFONT*,HFONT>* data = reinterpret_cast<const std::pair<LOGFONT*,HFONT>*>(ctx); ++ const LOGFONT* lf = data->first; ++ const HFONT hf = data->second; ++ ++ return !memcmp(&lface->fLogFont, lf, sizeof(LOGFONT)) && lface->hFont == hf; ++} ++ ++SkTypeface* SkCreateTypefaceFromLOGFONT(const LOGFONT& origLF, HFONT hFont) { ++ LOGFONT lf = origLF; ++// make_canonical(&lf); ++ std::pair<LOGFONT*,HFONT> data = std::make_pair(&lf,hFont); ++ sk_sp<SkTypeface> face = SkTypefaceCache::FindByProcAndRef(FindByLogFontAndHFont, &data); ++ if (!face) { ++ face = LogFontTypeface::Make(lf,hFont); ++ SkTypefaceCache::Add(face); ++ } ++ return face.release(); ++} ++ + /** + * The created SkTypeface takes ownership of fontMemResource. + */ + sk_sp<SkTypeface> SkCreateFontMemResourceTypefaceFromLOGFONT(const LOGFONT& origLF, HANDLE fontMemResource) { + LOGFONT lf = origLF; +- make_canonical(&lf); ++// make_canonical(&lf); + // We'll never get a cache hit, so no point in putting this in SkTypefaceCache. + return FontMemResourceTypeface::Make(lf, fontMemResource); + } +@@ -686,7 +731,10 @@ + LOGFONT lf = typeface->fLogFont; + lf.lfHeight = -SkScalarTruncToInt(gdiTextSize); + lf.lfQuality = compute_quality(fRec); +- fFont = CreateFontIndirect(&lf); ++ if(typeface->hFont != nullptr) ++ fFont = typeface->hFont; ++ else ++ fFont = CreateFontIndirect(&lf); + if (!fFont) { + return; + } +@@ -788,7 +836,9 @@ + ::DeleteDC(fDDC); + } + if (fFont) { +- ::DeleteObject(fFont); ++ LogFontTypeface* typeface = static_cast<LogFontTypeface*>(this->getTypeface()); ++ if(typeface->hFont != fFont) ++ ::DeleteObject(fFont); + } + if (fSC) { + ::ScriptFreeCache(&fSC); |