Skip to content

Commit 5054b7b

Browse files
chearonzbjornson
authored andcommittedAug 19, 2020
translate "sans-serif" to "sans" for Pango
Fixes #1643
1 parent 58bc728 commit 5054b7b

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
1010
### Changed
1111
### Added
1212
### Fixed
13+
* Fix Pango logging "expect ugly output" on Windows (#1643)
1314

1415
2.7.0
1516
==================

‎src/Canvas.cc

-6
Original file line numberDiff line numberDiff line change
@@ -837,12 +837,6 @@ Canvas::GetWeightFromCSSString(const char *weight) {
837837
return w;
838838
}
839839

840-
bool streq_casein(std::string& str1, std::string& str2) {
841-
return str1.size() == str2.size() && std::equal(str1.begin(), str1.end(), str2.begin(), [](char& c1, char& c2) {
842-
return c1 == c2 || std::toupper(c1) == std::toupper(c2);
843-
});
844-
}
845-
846840
/*
847841
* Given a user description, return a description that will select the
848842
* font either from the system or @font-face

‎src/CanvasRenderingContext2d.cc

+11-2
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void Context2d::resetState(bool init) {
232232
state->patternQuality = CAIRO_FILTER_GOOD;
233233
state->imageSmoothingEnabled = true;
234234
state->textDrawingMode = TEXT_DRAW_PATHS;
235-
state->fontDescription = pango_font_description_from_string("sans serif");
235+
state->fontDescription = pango_font_description_from_string("sans");
236236
pango_font_description_set_absolute_size(state->fontDescription, 10 * PANGO_SCALE);
237237
pango_layout_set_font_description(_layout, state->fontDescription);
238238

@@ -2533,7 +2533,16 @@ NAN_SETTER(Context2d::SetFont) {
25332533
pango_font_description_set_style(desc, Canvas::GetStyleFromCSSString(*style));
25342534
pango_font_description_set_weight(desc, Canvas::GetWeightFromCSSString(*weight));
25352535

2536-
if (strlen(*family) > 0) pango_font_description_set_family(desc, *family);
2536+
if (strlen(*family) > 0) {
2537+
// See #1643 - Pango understands "sans" whereas CSS uses "sans-serif"
2538+
std::string s1(*family);
2539+
std::string s2("sans-serif");
2540+
if (streq_casein(s1, s2)) {
2541+
pango_font_description_set_family(desc, "sans");
2542+
} else {
2543+
pango_font_description_set_family(desc, *family);
2544+
}
2545+
}
25372546

25382547
PangoFontDescription *sys_desc = Canvas::ResolveFontDescription(desc);
25392548
pango_font_description_free(desc);

‎src/Util.h

+6
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ inline void SetProtoAccessor(
2525
v8::AccessorSignature::New(v8::Isolate::GetCurrent(), ctor)
2626
);
2727
}
28+
29+
inline bool streq_casein(std::string& str1, std::string& str2) {
30+
return str1.size() == str2.size() && std::equal(str1.begin(), str1.end(), str2.begin(), [](char& c1, char& c2) {
31+
return c1 == c2 || std::toupper(c1) == std::toupper(c2);
32+
});
33+
}

0 commit comments

Comments
 (0)
Please sign in to comment.