@@ -54,8 +54,8 @@ class MCFontnode : public MCDLlist
5454
5555
5656// Forward declarations
57- static MCSysFontHandle emscripten_get_font_by_name (MCNameRef p_name, uint16_t p_style);
58- static MCSysFontHandle emscripten_get_font_from_file (MCStringRef p_file);
57+ static sk_sp<SkTypeface> emscripten_get_font_by_name (MCNameRef p_name, uint16_t p_style);
58+ static sk_sp<SkTypeface> emscripten_get_font_from_file (MCStringRef p_file);
5959
6060
6161/* ================================================================
@@ -70,11 +70,11 @@ MCFontnode::MCFontnode(MCNameRef p_name,
7070 m_requested_style(p_style)
7171{
7272 // Load the font as requested
73- m_font_info. fid = emscripten_get_font_by_name (p_name, p_style);
73+ auto t_typeface = emscripten_get_font_by_name (p_name, p_style);
7474
7575 // Calculate the metrics for this typeface and size
7676 SkPaint t_paint;
77- t_paint.setTypeface ((SkTypeface*)m_font_info. fid );
77+ t_paint.setTypeface (t_typeface );
7878 t_paint.setTextSize (p_size);
7979
8080 SkPaint::FontMetrics t_metrics;
@@ -86,7 +86,7 @@ MCFontnode::MCFontnode(MCNameRef p_name,
8686 m_font_info.m_descent = t_metrics.fDescent ;
8787 m_font_info.m_leading = t_metrics.fLeading ;
8888 m_font_info.m_xheight = t_metrics.fXHeight ;
89-
89+ m_font_info. fid = reinterpret_cast <MCSysFontHandle>(t_typeface. release ());
9090 m_font_info.size = p_size;
9191}
9292
@@ -253,45 +253,46 @@ MCFontlist::getfontstructinfo(MCNameRef & r_name,
253253}
254254
255255
256- MCSysFontHandle emscripten_get_font_by_name (MCNameRef p_name,
257- uint16_t p_style)
256+ sk_sp<SkTypeface> emscripten_get_font_by_name (MCNameRef p_name,
257+ uint16_t p_style)
258258{
259259 /* Decode style */
260260 bool t_italic = (0 != (p_style & FA_ITALIC ));
261261 bool t_bold = (0x05 < (p_style & FA_WEIGHT ));
262- SkTypeface::Style t_style;
263- if (t_italic && t_bold)
264- {
265- t_style = SkTypeface::kBoldItalic ;
266- }
267- else if (t_italic)
268- {
269- t_style = SkTypeface::kItalic ;
270- }
271- else if (t_bold)
272- {
273- t_style = SkTypeface::kBold ;
274- }
275- else
276- {
277- t_style = SkTypeface::kNormal ;
278- }
279262
280- MCAutoStringRefAsSysString t_sys_name;
263+ SkFontStyle::Weight t_weight;
264+ SkFontStyle::Width t_width;
265+ SkFontStyle::Slant t_slant;
266+
267+ if (t_bold)
268+ t_weight = SkFontStyle::kBold_Weight ;
269+ else
270+ t_weight = SkFontStyle::kNormal_Weight ;
271+
272+ t_width = SkFontStyle::kNormal_Width ;
273+
274+ if (t_italic)
275+ t_slant = SkFontStyle::kItalic_Slant ;
276+ else
277+ t_slant = SkFontStyle::kUpright_Slant ;
278+
279+ SkFontStyle t_style (t_weight, t_width, t_slant);
280+
281+ MCAutoStringRefAsSysString t_sys_name;
281282 /* UNCHECKED */ t_sys_name.Lock (MCNameGetString (p_name));
282283
283- MCSysFontHandle t_handle =
284- MCSysFontHandle (SkTypeface::CreateFromName (*t_sys_name, t_style));
285- MCAssert (nil != t_handle);
286- return t_handle;
284+ sk_sp<SkTypeface> t_typeface = SkTypeface::MakeFromName (*t_sys_name, t_style);
285+
286+ return t_typeface;
287287}
288288
289- MCSysFontHandle emscripten_get_font_from_file (MCStringRef p_file)
289+ sk_sp<SkTypeface> emscripten_get_font_from_file (MCStringRef p_file)
290290{
291291 MCAutoStringRefAsSysString t_sys_path;
292292 /* UNCHECKED */ t_sys_path.Lock (p_file);
293293
294- MCSysFontHandle t_handle = (MCSysFontHandle) SkTypeface::CreateFromFile (*t_sys_path);
295- MCAssert (t_handle != nil);
296- return t_handle ;
294+ sk_sp<SkTypeface> t_typeface = SkTypeface::MakeFromFile (*t_sys_path);
295+ MCAssert (t_typeface != nil);
296+ return t_typeface ;
297297}
298+
0 commit comments