diff --git a/core/fonts/NotoSansSC-Bold.ttf b/core/fonts/NotoSansSC-Bold.ttf new file mode 100644 index 0000000000000..b9010dfffb071 Binary files /dev/null and b/core/fonts/NotoSansSC-Bold.ttf differ diff --git a/core/fonts/NotoSansSC-Regular.ttf b/core/fonts/NotoSansSC-Regular.ttf new file mode 100644 index 0000000000000..4d4cadb98032c Binary files /dev/null and b/core/fonts/NotoSansSC-Regular.ttf differ diff --git a/lib/private/Avatar/Avatar.php b/lib/private/Avatar/Avatar.php index 020c509b86cb6..1b87cd3b0737c 100644 --- a/lib/private/Avatar/Avatar.php +++ b/lib/private/Avatar/Avatar.php @@ -100,19 +100,7 @@ public function get(int $size = 64, bool $darkTheme = false) { return $avatar; } - /** - * {size} = 500 - * {fill} = hex color to fill - * {letter} = Letter to display - * - * Generate SVG avatar - * - * @param int $size The requested image size in pixel - * @return string - * - */ - protected function getAvatarVector(int $size, bool $darkTheme): string { - $userDisplayName = $this->getDisplayName(); + protected function getAvatarVector(string $userDisplayName, int $size, bool $darkTheme): string { $fgRGB = $this->avatarBackgroundColor($userDisplayName); $bgRGB = $fgRGB->alphaBlending(0.1, $darkTheme ? new Color(0, 0, 0) : new Color(255, 255, 255)); $fill = sprintf("%02x%02x%02x", $bgRGB->red(), $bgRGB->green(), $bgRGB->blue()); @@ -122,6 +110,14 @@ protected function getAvatarVector(int $size, bool $darkTheme): string { return str_replace($toReplace, [$size, $fill, $fgFill, $text], $this->svgTemplate); } + protected function getFont(string $userDisplayName) { + if (preg_match('/\p{Han}/u', $userDisplayName) === 1) { + return __DIR__ . '/../../../core/fonts/NotoSansSC-Regular.ttf'; + } + + return __DIR__ . '/../../../core/fonts/NotoSans-Regular.ttf'; + } + /** * Generate png avatar from svg with Imagick */ @@ -134,9 +130,12 @@ protected function generateAvatarFromSvg(int $size, bool $darkTheme): ?string { if (in_array("RSVG", $formats, true)) { return null; } + + $userDisplayName = $this->getDisplayName(); + $font = $this->getFont($userDisplayName); + try { - $font = __DIR__ . '/../../../core/fonts/NotoSans-Regular.ttf'; - $svg = $this->getAvatarVector($size, $darkTheme); + $svg = $this->getAvatarVector($userDisplayName, $size, $darkTheme); $avatar = new Imagick(); $avatar->setFont($font); $avatar->readImageBlob($svg); @@ -178,7 +177,8 @@ protected function generateAvatar(string $userDisplayName, int $size, bool $dark } imagefilledrectangle($im, 0, 0, $size, $size, $background); - $font = __DIR__ . '/../../../core/fonts/NotoSans-Regular.ttf'; + + $font = $this->getFont($userDisplayName); $fontSize = $size * 0.4; [$x, $y] = $this->imageTTFCenter(