From 52e9c347ceca6ebbe362977c32c45ec2cf7175ea Mon Sep 17 00:00:00 2001 From: Caleb Hearon Date: Wed, 12 Aug 2020 18:23:33 -0400 Subject: [PATCH] translate "sans-serif" to "sans" for Pango Fixes #1643 --- CHANGELOG.md | 1 + src/CanvasRenderingContext2d.cc | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 945877590..ca5a6e862 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ project adheres to [Semantic Versioning](http://semver.org/). ### Changed ### Added ### Fixed +* Fix Pango logging "expect ugly output" on Windows (#1643) 2.7.0 ================== diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index 42f331805..79a2a5a71 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -18,6 +18,7 @@ #include #include "Util.h" #include +#include using namespace v8; @@ -232,7 +233,7 @@ void Context2d::resetState(bool init) { state->patternQuality = CAIRO_FILTER_GOOD; state->imageSmoothingEnabled = true; state->textDrawingMode = TEXT_DRAW_PATHS; - state->fontDescription = pango_font_description_from_string("sans serif"); + state->fontDescription = pango_font_description_from_string("sans"); pango_font_description_set_absolute_size(state->fontDescription, 10 * PANGO_SCALE); pango_layout_set_font_description(_layout, state->fontDescription); @@ -2533,7 +2534,15 @@ NAN_SETTER(Context2d::SetFont) { pango_font_description_set_style(desc, Canvas::GetStyleFromCSSString(*style)); pango_font_description_set_weight(desc, Canvas::GetWeightFromCSSString(*weight)); - if (strlen(*family) > 0) pango_font_description_set_family(desc, *family); + if (strlen(*family) > 0) { + // See #1643 - Pango understands "sans" whereas CSS uses "sans-serif" + std::regex r("sans-serif", std::regex_constants::ECMAScript | std::regex_constants::icase); + if (regex_match(*family, r)) { + pango_font_description_set_family(desc, "sans"); + } else { + pango_font_description_set_family(desc, *family); + } + } PangoFontDescription *sys_desc = Canvas::ResolveFontDescription(desc); pango_font_description_free(desc);