@@ -43,7 +43,7 @@ constexpr double twoPi = M_PI * 2.;
4343#define PANGO_LAYOUT_GET_METRICS (LAYOUT ) pango_context_get_metrics( \
4444 pango_layout_get_context (LAYOUT), \
4545 pango_layout_get_font_description(LAYOUT), \
46- pango_context_get_language(pango_layout_get_context(LAYOUT )))
46+ pango_language_from_string(state->lang.c_str( )))
4747
4848inline static bool checkArgs(const Napi::CallbackInfo&info, double *args, int argsNum, int offset = 0 ){
4949 Napi::Env env = info.Env ();
@@ -162,7 +162,8 @@ Context2d::Initialize(Napi::Env& env, Napi::Object& exports) {
162162 InstanceAccessor<&Context2d::GetFont, &Context2d::SetFont>(" font" , napi_default_jsproperty),
163163 InstanceAccessor<&Context2d::GetTextBaseline, &Context2d::SetTextBaseline>(" textBaseline" , napi_default_jsproperty),
164164 InstanceAccessor<&Context2d::GetTextAlign, &Context2d::SetTextAlign>(" textAlign" , napi_default_jsproperty),
165- InstanceAccessor<&Context2d::GetDirection, &Context2d::SetDirection>(" direction" , napi_default_jsproperty)
165+ InstanceAccessor<&Context2d::GetDirection, &Context2d::SetDirection>(" direction" , napi_default_jsproperty),
166+ InstanceAccessor<&Context2d::GetLanguage, &Context2d::SetLanguage>(" lang" , napi_default_jsproperty)
166167 });
167168
168169 exports.Set (" CanvasRenderingContext2d" , ctor);
@@ -786,6 +787,25 @@ Context2d::SetDirection(const Napi::CallbackInfo& info, const Napi::Value& value
786787 state->direction = dir;
787788}
788789
790+ /*
791+ * Get language.
792+ */
793+ Napi::Value
794+ Context2d::GetLanguage (const Napi::CallbackInfo& info) {
795+ return Napi::String::New (env, state->lang );
796+ }
797+
798+ /*
799+ * Set language.
800+ */
801+ void
802+ Context2d::SetLanguage (const Napi::CallbackInfo& info, const Napi::Value& value) {
803+ if (!value.IsString ()) return ;
804+
805+ std::string lang = value.As <Napi::String>();
806+ state->lang = lang;
807+ }
808+
789809/*
790810 * Put image data.
791811 *
@@ -2490,6 +2510,9 @@ Context2d::paintText(const Napi::CallbackInfo& info, bool stroke) {
24902510
24912511 checkFonts ();
24922512 pango_layout_set_text (layout, str.c_str (), -1 );
2513+ if (state->lang != " " ) {
2514+ pango_context_set_language (pango_layout_get_context (_layout), pango_language_from_string (state->lang .c_str ()));
2515+ }
24932516 pango_cairo_update_layout (context (), layout);
24942517
24952518 PangoDirection pango_dir = state->direction == " ltr" ? PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL;
@@ -2802,6 +2825,9 @@ Context2d::MeasureText(const Napi::CallbackInfo& info) {
28022825
28032826 checkFonts ();
28042827 pango_layout_set_text (layout, str.Utf8Value ().c_str (), -1 );
2828+ if (state->lang != " " ) {
2829+ pango_context_set_language (pango_layout_get_context (_layout), pango_language_from_string (state->lang .c_str ()));
2830+ }
28052831 pango_cairo_update_layout (ctx, layout);
28062832
28072833 // Normally you could use pango_layout_get_pixel_extents and be done, or use
0 commit comments