diff options
author | Caolán McNamara <caolanm@redhat.com> | 2023-04-04 17:15:13 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2023-04-04 22:26:47 +0200 |
commit | c9c463af22d1c7ea75c8af2d7cf5e2c0a152e40f (patch) | |
tree | d2afeb8b894ba8489ab95f8b2c425d9d778d68a6 /vcl/unx | |
parent | 1ca2edf4efaea9824613aaf02e854da6a2241f07 (diff) |
split out the pieces that apply the font to the cairo context
Change-Id: I0577832f57b15621d150da4cb50e134c9c06bae7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150029
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/unx')
-rw-r--r-- | vcl/unx/generic/gdi/cairotextrender.cxx | 70 |
1 files changed, 39 insertions, 31 deletions
diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx b/vcl/unx/generic/gdi/cairotextrender.cxx index 664c8dbea9cd..f3fb3bde6b83 100644 --- a/vcl/unx/generic/gdi/cairotextrender.cxx +++ b/vcl/unx/generic/gdi/cairotextrender.cxx @@ -162,6 +162,44 @@ CairoTextRender::~CairoTextRender() cairo_font_options_destroy(mpRoundGlyphPosOffOptions); } +static void ApplyFont(cairo_t* cr, const CairoFontsCache::CacheId& rId, double nWidth, double nHeight, int nGlyphRotation, + const GenericSalLayout& rLayout) +{ + cairo_font_face_t* font_face = CairoFontsCache::FindCachedFont(rId); + if (!font_face) + { + const FontConfigFontOptions *pOptions = rId.mpOptions; + FcPattern *pPattern = pOptions->GetPattern(); + font_face = cairo_ft_font_face_create_for_pattern(pPattern); + CairoFontsCache::CacheFont(font_face, rId); + } + cairo_set_font_face(cr, font_face); + + cairo_set_font_size(cr, nHeight); + + cairo_matrix_t m; + cairo_matrix_init_identity(&m); + + if (rLayout.GetOrientation()) + cairo_matrix_rotate(&m, toRadian(rLayout.GetOrientation())); + + cairo_matrix_scale(&m, nWidth, nHeight); + + if (nGlyphRotation) + cairo_matrix_rotate(&m, toRadian(Degree10(nGlyphRotation * 900))); + + const FreetypeFontInstance& rInstance = static_cast<FreetypeFontInstance&>(rLayout.GetFont()); + if (rInstance.NeedsArtificialItalic()) + { + cairo_matrix_t shear; + cairo_matrix_init_identity(&shear); + shear.xy = -shear.xx * ARTIFICIAL_ITALIC_SKEW; + cairo_matrix_multiply(&m, &shear, &m); + } + + cairo_set_font_matrix(cr, &m); +} + void CairoTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalGraphics& rGraphics) { const FreetypeFontInstance& rInstance = static_cast<FreetypeFontInstance&>(rLayout.GetFont()); @@ -326,8 +364,6 @@ void CairoTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalG aId.mpOptions = rFont.GetFontOptions(); aId.mbEmbolden = rInstance.NeedsArtificialBold(); - cairo_matrix_t m; - std::vector<int>::const_iterator aEnd = glyph_extrarotation.end(); std::vector<int>::const_iterator aStart = glyph_extrarotation.begin(); std::vector<int>::const_iterator aI = aStart; @@ -341,37 +377,9 @@ void CairoTextRender::DrawTextLayout(const GenericSalLayout& rLayout, const SalG size_t nLen = std::distance(aI, aNext); aId.mbVerticalMetrics = nGlyphRotation != 0.0; - cairo_font_face_t* font_face = CairoFontsCache::FindCachedFont(aId); - if (!font_face) - { - const FontConfigFontOptions *pOptions = aId.mpOptions; - FcPattern *pPattern = pOptions->GetPattern(); - font_face = cairo_ft_font_face_create_for_pattern(pPattern); - CairoFontsCache::CacheFont(font_face, aId); - } - cairo_set_font_face(cr, font_face); - - cairo_set_font_size(cr, nHeight); - cairo_matrix_init_identity(&m); - - if (rLayout.GetOrientation()) - cairo_matrix_rotate(&m, toRadian(rLayout.GetOrientation())); - - cairo_matrix_scale(&m, nWidth, nHeight); - - if (nGlyphRotation) - cairo_matrix_rotate(&m, toRadian(Degree10(nGlyphRotation * 900))); - - if (rInstance.NeedsArtificialItalic()) - { - cairo_matrix_t shear; - cairo_matrix_init_identity(&shear); - shear.xy = -shear.xx * ARTIFICIAL_ITALIC_SKEW; - cairo_matrix_multiply(&m, &shear, &m); - } + ApplyFont(cr, aId, nWidth, nHeight, nGlyphRotation, rLayout); - cairo_set_font_matrix(cr, &m); cairo_show_glyphs(cr, &cairo_glyphs[nStartIndex], nLen); if (cairo_status(cr) != CAIRO_STATUS_SUCCESS) { |