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>
22 #include <skia/x11/textrender.hxx>
24 #include <unx/fc_fontoptions.hxx>
25 #include <unx/freetype_glyphcache.hxx>
26 #include <vcl/svapp.hxx>
27 #include <sallayout.hxx>
28 #include <skia/gdiimpl.hxx>
31 #include <SkFontMgr_fontconfig.h>
33 void SkiaTextRender::DrawTextLayout(const GenericSalLayout
& rLayout
, const SalGraphics
& rGraphics
)
35 const FreetypeFontInstance
& rInstance
= static_cast<FreetypeFontInstance
&>(rLayout
.GetFont());
36 const FreetypeFont
& rFont
= rInstance
.GetFreetypeFont();
37 const vcl::font::FontSelectPattern
& rFSD
= rInstance
.GetFontSelectPattern();
38 int nHeight
= rFSD
.mnHeight
;
39 int nWidth
= rFSD
.mnWidth
? rFSD
.mnWidth
: nHeight
;
40 if (nWidth
== 0 || nHeight
== 0)
45 // Get the global FcConfig that our VCL fontconfig code uses, and refcount it.
46 fontManager
= SkFontMgr_New_FontConfig(FcConfigReference(nullptr));
48 sk_sp
<SkTypeface
> typeface
49 = SkFontMgr_createTypefaceFromFcPattern(fontManager
, rFont
.GetFontOptions()->GetPattern());
50 SkFont
font(typeface
);
51 font
.setSize(nHeight
);
52 font
.setScaleX(1.0 * nWidth
/ nHeight
);
53 if (rInstance
.NeedsArtificialItalic())
54 font
.setSkewX(-1.0 * ARTIFICIAL_ITALIC_SKEW
);
55 if (rInstance
.NeedsArtificialBold())
56 font
.setEmbolden(true);
58 bool bSubpixelPositioning
= rLayout
.GetTextRenderModeForResolutionIndependentLayout();
59 SkFont::Edging ePreferredAliasing
60 = bSubpixelPositioning
? SkFont::Edging::kSubpixelAntiAlias
: SkFont::Edging::kAntiAlias
;
61 if (bSubpixelPositioning
)
63 // note that SkFont defaults to a BaselineSnap of true, so I think really only
64 // subpixel in text direction
65 font
.setSubpixel(true);
67 SkFontHinting eHinting
= font
.getHinting();
68 bool bAllowedHintStyle
69 = eHinting
== SkFontHinting::kNone
|| eHinting
== SkFontHinting::kSlight
;
70 if (!bAllowedHintStyle
)
71 font
.setHinting(SkFontHinting::kSlight
);
74 font
.setEdging(rFont
.GetAntialiasAdvice() ? ePreferredAliasing
: SkFont::Edging::kAlias
);
76 // Vertical font, use width as "height".
77 SkFont
verticalFont(font
);
78 verticalFont
.setSize(nWidth
);
79 verticalFont
.setScaleX(1.0 * nHeight
/ nWidth
);
81 assert(dynamic_cast<SkiaSalGraphicsImpl
*>(rGraphics
.GetImpl()));
82 SkiaSalGraphicsImpl
* impl
= static_cast<SkiaSalGraphicsImpl
*>(rGraphics
.GetImpl());
83 impl
->drawGenericLayout(rLayout
, mnTextColor
, font
, verticalFont
);
86 void SkiaTextRender::ClearDevFontCache() { fontManager
.reset(); }
90 void FontConfigFontOptions::cairo_font_options_substitute(FcPattern
* pPattern
)
92 ImplSVData
* pSVData
= ImplGetSVData();
93 const cairo_font_options_t
* pFontOptions
= pSVData
->mpDefInst
->GetCairoFontOptions();
96 cairo_ft_font_options_substitute(pFontOptions
, pPattern
);
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */