-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Set pango language through ctx.lang #2526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0d3abd3
9a0d513
dc7eac9
b5fcf9b
f865df7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -43,7 +43,7 @@ constexpr double twoPi = M_PI * 2.; | |||
#define PANGO_LAYOUT_GET_METRICS(LAYOUT) pango_context_get_metrics( \ | ||||
pango_layout_get_context(LAYOUT), \ | ||||
pango_layout_get_font_description(LAYOUT), \ | ||||
pango_context_get_language(pango_layout_get_context(LAYOUT))) | ||||
pango_language_from_string(state->lang.c_str())) | ||||
|
||||
inline static bool checkArgs(const Napi::CallbackInfo&info, double *args, int argsNum, int offset = 0){ | ||||
Napi::Env env = info.Env(); | ||||
|
@@ -162,7 +162,8 @@ Context2d::Initialize(Napi::Env& env, Napi::Object& exports) { | |||
InstanceAccessor<&Context2d::GetFont, &Context2d::SetFont>("font", napi_default_jsproperty), | ||||
InstanceAccessor<&Context2d::GetTextBaseline, &Context2d::SetTextBaseline>("textBaseline", napi_default_jsproperty), | ||||
InstanceAccessor<&Context2d::GetTextAlign, &Context2d::SetTextAlign>("textAlign", napi_default_jsproperty), | ||||
InstanceAccessor<&Context2d::GetDirection, &Context2d::SetDirection>("direction", napi_default_jsproperty) | ||||
InstanceAccessor<&Context2d::GetDirection, &Context2d::SetDirection>("direction", napi_default_jsproperty), | ||||
InstanceAccessor<&Context2d::GetLanguage, &Context2d::SetLanguage>("lang", napi_default_jsproperty) | ||||
}); | ||||
|
||||
exports.Set("CanvasRenderingContext2d", ctor); | ||||
|
@@ -786,6 +787,25 @@ Context2d::SetDirection(const Napi::CallbackInfo& info, const Napi::Value& value | |||
state->direction = dir; | ||||
} | ||||
|
||||
/* | ||||
* Get language. | ||||
*/ | ||||
Napi::Value | ||||
Context2d::GetLanguage(const Napi::CallbackInfo& info) { | ||||
return Napi::String::New(env, state->lang); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this call
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense, done ✅ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the second commit, I don't think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case, should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The layout should be up-to-date there, but good call looking at that. I'll start a review with my thoughts... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe the better way to get the language before it is lazily committed?
|
||||
} | ||||
|
||||
/* | ||||
* Set language. | ||||
*/ | ||||
void | ||||
Context2d::SetLanguage(const Napi::CallbackInfo& info, const Napi::Value& value) { | ||||
if (!value.IsString()) return; | ||||
|
||||
std::string lang = value.As<Napi::String>(); | ||||
state->lang = lang; | ||||
} | ||||
|
||||
/* | ||||
* Put image data. | ||||
* | ||||
|
@@ -2490,6 +2510,9 @@ Context2d::paintText(const Napi::CallbackInfo& info, bool stroke) { | |||
|
||||
checkFonts(); | ||||
pango_layout_set_text(layout, str.c_str(), -1); | ||||
if (state->lang != "") { | ||||
pango_context_set_language(pango_layout_get_context(_layout), pango_language_from_string(state->lang.c_str())); | ||||
} | ||||
pango_cairo_update_layout(context(), layout); | ||||
|
||||
PangoDirection pango_dir = state->direction == "ltr" ? PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL; | ||||
|
@@ -2802,6 +2825,9 @@ Context2d::MeasureText(const Napi::CallbackInfo& info) { | |||
|
||||
checkFonts(); | ||||
pango_layout_set_text(layout, str.Utf8Value().c_str(), -1); | ||||
if (state->lang != "") { | ||||
pango_context_set_language(pango_layout_get_context(_layout), pango_language_from_string(state->lang.c_str())); | ||||
} | ||||
pango_cairo_update_layout(ctx, layout); | ||||
|
||||
// Normally you could use pango_layout_get_pixel_extents and be done, or use | ||||
|
Uh oh!
There was an error while loading. Please reload this page.