@@ -2568,8 +2568,7 @@ Context2d::GetFont(const Napi::CallbackInfo& info) {
25682568 * Set font:
25692569 * - weight
25702570 * - style
2571- * - size
2572- * - unit
2571+ * - size (px)
25732572 * - family
25742573 */
25752574
@@ -2591,37 +2590,12 @@ Context2d::SetFont(const Napi::CallbackInfo& info, const Napi::Value& value) {
25912590 Napi::String empty = Napi::String::New (env, " " );
25922591 Napi::Number zero = Napi::Number::New (env, 0 );
25932592
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 ();
25982596 std::string family = font.Get (" family" ).UnwrapOr (empty).ToString ().UnwrapOr (empty).Utf8Value ();
25992597
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);
26252599 state->font = value.As <Napi::String>().Utf8Value ().c_str ();
26262600}
26272601
0 commit comments