Fix username link QR code in RTL

This commit is contained in:
Fedor Indutny 2024-02-21 10:56:52 -08:00 committed by GitHub
parent c5b8f49f25
commit 47fd4125fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -300,16 +300,19 @@ type CreateTextMeasurerOptionsType = Readonly<{
font: string; font: string;
letterSpacing: number; letterSpacing: number;
maxWidth: number; maxWidth: number;
direction: 'ltr' | 'rtl';
}>; }>;
function createTextMeasurer({ function createTextMeasurer({
font, font,
letterSpacing, letterSpacing,
maxWidth, maxWidth,
direction,
}: CreateTextMeasurerOptionsType): (text: string) => boolean { }: CreateTextMeasurerOptionsType): (text: string) => boolean {
const [, context] = createCanvasAndContext({ width: 1, height: 1 }); const [, context] = createCanvasAndContext({ width: 1, height: 1 });
context.font = font; context.font = font;
context.direction = direction;
// Experimental Chrome APIs // Experimental Chrome APIs
( (
context as unknown as { context as unknown as {
@ -324,6 +327,7 @@ type GenerateImageURLOptionsType = Readonly<{
link: string; link: string;
username: string; username: string;
hint: string; hint: string;
hintDirection: 'ltr' | 'rtl';
colorId: number; colorId: number;
}>; }>;
@ -332,6 +336,7 @@ export async function _generateImageBlob({
link, link,
username, username,
hint, hint,
hintDirection,
colorId, colorId,
}: GenerateImageURLOptionsType): Promise<Blob> { }: GenerateImageURLOptionsType): Promise<Blob> {
const usernameLines = splitText(username, { const usernameLines = splitText(username, {
@ -340,6 +345,7 @@ export async function _generateImageBlob({
maxWidth: USERNAME_MAX_WIDTH, maxWidth: USERNAME_MAX_WIDTH,
font: USERNAME_FONT, font: USERNAME_FONT,
letterSpacing: USERNAME_LETTER_SPACING, letterSpacing: USERNAME_LETTER_SPACING,
direction: 'ltr',
}), }),
}); });
@ -349,6 +355,7 @@ export async function _generateImageBlob({
maxWidth: HINT_MAX_WIDTH, maxWidth: HINT_MAX_WIDTH,
font: HINT_FONT, font: HINT_FONT,
letterSpacing: HINT_LETTER_SPACING, letterSpacing: HINT_LETTER_SPACING,
direction: hintDirection,
}), }),
}); });
@ -381,6 +388,7 @@ export async function _generateImageBlob({
context.save(); context.save();
context.font = USERNAME_FONT; context.font = USERNAME_FONT;
context.direction = 'ltr';
// Experimental Chrome APIs // Experimental Chrome APIs
( (
context as unknown as { context as unknown as {
@ -397,6 +405,7 @@ export async function _generateImageBlob({
context.save(); context.save();
context.font = HINT_FONT; context.font = HINT_FONT;
context.direction = hintDirection;
// Experimental Chrome APIs // Experimental Chrome APIs
( (
context as unknown as { context as unknown as {
@ -586,6 +595,7 @@ export function UsernameLinkModalBody({
username, username,
colorId, colorId,
hint: i18n('icu:UsernameLinkModalBody__hint'), hint: i18n('icu:UsernameLinkModalBody__hint'),
hintDirection: i18n.getLocaleDirection(),
}); });
const arrayBuffer = await blob.arrayBuffer(); const arrayBuffer = await blob.arrayBuffer();
if (isAborted) { if (isAborted) {