@@ -2568,8 +2568,7 @@ Context2d::GetFont(const Napi::CallbackInfo& info) {
2568
2568
* Set font:
2569
2569
* - weight
2570
2570
* - style
2571
- * - size
2572
- * - unit
2571
+ * - size (px)
2573
2572
* - family
2574
2573
*/
2575
2574
@@ -2591,37 +2590,12 @@ Context2d::SetFont(const Napi::CallbackInfo& info, const Napi::Value& value) {
2591
2590
Napi::String empty = Napi::String::New (env, " " );
2592
2591
Napi::Number zero = Napi::Number::New (env, 0 );
2593
2592
2594
- std::string weight = font.Get (" weight" ).UnwrapOr (empty).ToString ().UnwrapOr (empty).Utf8Value ();
2595
- std::string style = font.Get (" style" ).UnwrapOr (empty).ToString ().UnwrapOr (empty).Utf8Value ();
2596
- double size = font.Get (" size" ).UnwrapOr (zero).ToNumber ().UnwrapOr (zero).DoubleValue ();
2597
- std::string unit = font.Get (" unit" ).UnwrapOr (empty).ToString ().UnwrapOr (empty).Utf8Value ();
2593
+ uint32_t weight = font.Get (" weight" ).UnwrapOr (zero).ToNumber ().UnwrapOr (empty).Uint32Value ();
2594
+ FontDescription::Style = font.Get (" style" ).UnwrapOr (zero).ToNumber ().UnwrapOr (empty).Uint32Value ();
2595
+ float size = font.Get (" size" ).UnwrapOr (zero).ToNumber ().UnwrapOr (zero).FloatValue ();
2598
2596
std::string family = font.Get (" family" ).UnwrapOr (empty).ToString ().UnwrapOr (empty).Utf8Value ();
2599
2597
2600
- PangoFontDescription *desc = pango_font_description_copy (state->fontDescription );
2601
- pango_font_description_free (state->fontDescription );
2602
-
2603
- pango_font_description_set_style (desc, Canvas::GetStyleFromCSSString (style.c_str ()));
2604
- pango_font_description_set_weight (desc, Canvas::GetWeightFromCSSString (weight.c_str ()));
2605
-
2606
- if (family.length () > 0 ) {
2607
- // See #1643 - Pango understands "sans" whereas CSS uses "sans-serif"
2608
- std::string s1 (family);
2609
- std::string s2 (" sans-serif" );
2610
- if (streq_casein (s1, s2)) {
2611
- pango_font_description_set_family (desc, " sans" );
2612
- } else {
2613
- pango_font_description_set_family (desc, family.c_str ());
2614
- }
2615
- }
2616
-
2617
- PangoFontDescription *sys_desc = Canvas::ResolveFontDescription (desc);
2618
- pango_font_description_free (desc);
2619
-
2620
- if (size > 0 ) pango_font_description_set_absolute_size (sys_desc, size * PANGO_SCALE);
2621
-
2622
- state->fontDescription = sys_desc;
2623
- pango_layout_set_font_description (_layout, sys_desc);
2624
-
2598
+ state->fontDescription = FontDescription (family, weight, style, size);
2625
2599
state->font = value.As <Napi::String>().Utf8Value ().c_str ();
2626
2600
}
2627
2601
0 commit comments