1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
23 #pragma clang diagnostic push
24 #pragma clang diagnostic ignored "-Wunused-value"
26 #if defined __GNUC__ && !defined __clang__
27 #pragma GCC diagnostic push
28 #pragma GCC diagnostic ignored "-Wunused-value"
31 #include <skia/x11/textrender.hxx>
33 #include <unx/fc_fontoptions.hxx>
34 #include <unx/freetype_glyphcache.hxx>
35 #include <vcl/svapp.hxx>
36 #include <sallayout.hxx>
37 #include <skia/gdiimpl.hxx>
40 #include <SkFontMgr_fontconfig.h>
41 #include <SkFontTypes.h>
43 #if defined __GNUC__ && !defined __clang__
44 #pragma GCC diagnostic pop
47 #pragma clang diagnostic pop
50 void SkiaTextRender::DrawTextLayout(const GenericSalLayout
& rLayout
, const SalGraphics
& rGraphics
)
52 const FreetypeFontInstance
& rInstance
= static_cast<FreetypeFontInstance
&>(rLayout
.GetFont());
53 const FreetypeFont
& rFont
= rInstance
.GetFreetypeFont();
54 const vcl::font::FontSelectPattern
& rFSD
= rInstance
.GetFontSelectPattern();
55 if (rFSD
.mnHeight
== 0)
57 double nHeight
= rFSD
.mnHeight
;
58 double nWidth
= rFSD
.mnWidth
? rFSD
.mnWidth
: nHeight
;
62 // Get the global FcConfig that our VCL fontconfig code uses, and refcount it.
63 fontManager
= SkFontMgr_New_FontConfig(FcConfigReference(nullptr));
65 sk_sp
<SkTypeface
> typeface
66 = SkFontMgr_createTypefaceFromFcPattern(fontManager
, rFont
.GetFontOptions()->GetPattern());
67 SkFont
font(typeface
);
68 font
.setSize(nHeight
);
69 font
.setScaleX(nWidth
/ nHeight
);
70 if (rInstance
.NeedsArtificialItalic())
71 font
.setSkewX(-1.0 * ARTIFICIAL_ITALIC_SKEW
);
72 if (rInstance
.NeedsArtificialBold())
73 font
.setEmbolden(true);
75 bool bSubpixelPositioning
= rLayout
.GetSubpixelPositioning();
76 SkFont::Edging ePreferredAliasing
77 = bSubpixelPositioning
? SkFont::Edging::kSubpixelAntiAlias
: SkFont::Edging::kAntiAlias
;
78 if (bSubpixelPositioning
)
80 // note that SkFont defaults to a BaselineSnap of true, so I think really only
81 // subpixel in text direction
82 font
.setSubpixel(true);
84 SkFontHinting eHinting
= font
.getHinting();
85 static bool bAllowDefaultHinting
= getenv("SAL_ALLOW_DEFAULT_HINTING") != nullptr;
86 bool bAllowedHintStyle
87 = bAllowDefaultHinting
88 || (eHinting
== SkFontHinting::kNone
|| eHinting
== SkFontHinting::kSlight
);
89 if (!bAllowedHintStyle
)
90 font
.setHinting(SkFontHinting::kSlight
);
93 font
.setEdging(rFont
.GetAntialiasAdvice() ? ePreferredAliasing
: SkFont::Edging::kAlias
);
95 // Vertical font, use width as "height".
96 SkFont
verticalFont(font
);
97 verticalFont
.setSize(nWidth
);
98 verticalFont
.setScaleX(nHeight
/ nWidth
);
100 assert(dynamic_cast<SkiaSalGraphicsImpl
*>(rGraphics
.GetImpl()));
101 SkiaSalGraphicsImpl
* impl
= static_cast<SkiaSalGraphicsImpl
*>(rGraphics
.GetImpl());
102 impl
->drawGenericLayout(rLayout
, mnTextColor
, font
, verticalFont
);
105 void SkiaTextRender::ClearDevFontCache() { fontManager
.reset(); }
109 void FontConfigFontOptions::cairo_font_options_substitute(FcPattern
* pPattern
)
111 ImplSVData
* pSVData
= ImplGetSVData();
112 const cairo_font_options_t
* pFontOptions
= pSVData
->mpDefInst
->GetCairoFontOptions();
115 cairo_ft_font_options_substitute(pFontOptions
, pPattern
);
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */