Skip to content

Commit ce6130f

Browse files
authored
fix: ctx.direction was not working correctly (#24)
1 parent f576d65 commit ce6130f

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

native/include/common.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ enum TextBaseline {
5252
};
5353

5454
enum TextDirection {
55+
kInherit,
5556
kLTR,
5657
kRTL
5758
};

native/src/context2d.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ sk_context_state* create_default_state() {
3030
state->imageSmoothingQuality = kLow;
3131
state->textAlign = kStart;
3232
state->textBaseline = kAlphabetic;
33-
state->direction = kLTR;
33+
state->direction = kInherit;
3434
state->font = new Font();
3535
state->font->size = 10;
3636
state->font->family = strdup("sans-serif");
@@ -298,7 +298,7 @@ extern "C" {
298298
skia::textlayout::ParagraphStyle paraStyle;
299299
paraStyle.setTextAlign(skia::textlayout::TextAlign::kLeft);
300300
paraStyle.setTextStyle(tstyle);
301-
paraStyle.setTextDirection(skia::textlayout::TextDirection(context->state->direction));
301+
paraStyle.setTextDirection(skia::textlayout::TextDirection(context->state->direction == kRTL ? 0 : 1));
302302

303303
auto builder = skia::textlayout::ParagraphBuilderImpl::make(paraStyle, fontCollection, SkUnicode::Make());
304304
builder->addText(text, textLen);
@@ -395,10 +395,10 @@ extern "C" {
395395
paintX = x - lineWidth;
396396
break;
397397
case TextAlign::kStart:
398-
paintX = context->state->direction == TextDirection::kLTR ? x : x - lineWidth;
398+
paintX = context->state->direction == TextDirection::kRTL ? x - lineWidth : x;
399399
break;
400400
case TextAlign::kEnd:
401-
paintX = context->state->direction == TextDirection::kLTR ? x - lineWidth : x;
401+
paintX = context->state->direction == TextDirection::kRTL ? x : x - lineWidth;
402402
break;
403403
}
404404
auto needScale = lineWidth > maxWidth;

src/context2d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ enum CTextAlign {
129129
}
130130

131131
enum CTextDirection {
132-
ltr = 0,
133-
rtl = 1,
132+
inherit = 0,
133+
ltr = 1,
134+
rtl = 2,
134135
}
135136

136137
enum CTextBaseline {

0 commit comments

Comments
 (0)