@@ -43,7 +43,7 @@ constexpr double twoPi = M_PI * 2.;
43
43
#define PANGO_LAYOUT_GET_METRICS (LAYOUT ) pango_context_get_metrics( \
44
44
pango_layout_get_context (LAYOUT), \
45
45
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( )))
47
47
48
48
inline static bool checkArgs(const Napi::CallbackInfo&info, double *args, int argsNum, int offset = 0 ){
49
49
Napi::Env env = info.Env ();
@@ -162,7 +162,8 @@ Context2d::Initialize(Napi::Env& env, Napi::Object& exports) {
162
162
InstanceAccessor<&Context2d::GetFont, &Context2d::SetFont>(" font" , napi_default_jsproperty),
163
163
InstanceAccessor<&Context2d::GetTextBaseline, &Context2d::SetTextBaseline>(" textBaseline" , napi_default_jsproperty),
164
164
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)
166
167
});
167
168
168
169
exports.Set (" CanvasRenderingContext2d" , ctor);
@@ -786,6 +787,25 @@ Context2d::SetDirection(const Napi::CallbackInfo& info, const Napi::Value& value
786
787
state->direction = dir;
787
788
}
788
789
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
+
789
809
/*
790
810
* Put image data.
791
811
*
@@ -2490,6 +2510,9 @@ Context2d::paintText(const Napi::CallbackInfo& info, bool stroke) {
2490
2510
2491
2511
checkFonts ();
2492
2512
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
+ }
2493
2516
pango_cairo_update_layout (context (), layout);
2494
2517
2495
2518
PangoDirection pango_dir = state->direction == " ltr" ? PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL;
@@ -2802,6 +2825,9 @@ Context2d::MeasureText(const Napi::CallbackInfo& info) {
2802
2825
2803
2826
checkFonts ();
2804
2827
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
+ }
2805
2831
pango_cairo_update_layout (ctx, layout);
2806
2832
2807
2833
// Normally you could use pango_layout_get_pixel_extents and be done, or use
0 commit comments