1010namespace OC \Avatar ;
1111
1212use Imagick ;
13+ use OC \User \User ;
1314use OCP \Color ;
1415use OCP \Files \NotFoundException ;
1516use OCP \IAvatar ;
16- use Psr \Log \LoggerInterface ;
17- use OC \User \User ;
1817use OCP \IConfig ;
18+ use Psr \Log \LoggerInterface ;
1919
2020/**
2121 * This class gets and sets users avatars.
2222 */
2323abstract class Avatar implements IAvatar {
24- protected LoggerInterface $ logger ;
25-
2624 /**
2725 * https://github.com/sebdesign/cap-height -- for 500px height
2826 * Automated check: https://codepen.io/skjnldsv/pen/PydLBK/
@@ -37,8 +35,10 @@ abstract class Avatar implements IAvatar {
3735 <text x="50%" y="350" style="font-weight:normal;font-size:280px;font-family: \'Noto Sans \';text-anchor:middle;fill:#{fgFill}">{letter}</text>
3836 </svg> ' ;
3937
40- public function __construct (LoggerInterface $ logger ) {
41- $ this ->logger = $ logger ;
38+ public function __construct (
39+ protected IConfig $ config ,
40+ protected LoggerInterface $ logger ,
41+ ) {
4242 }
4343
4444 /**
@@ -97,12 +97,11 @@ protected function getAvatarVector(string $userDisplayName, int $size, bool $dar
9797 }
9898
9999 /**
100- * Select the rendering font based on the user's display name and language
100+ * Select the rendering font based on the user's display name and language
101101 */
102102 private function getFont (string $ userDisplayName ): string {
103103 if (preg_match ('/\p{Han}/u ' , $ userDisplayName ) === 1 ) {
104- $ userlang = $ this ->config ->getUserValue ($ this ->user ->getUID (), 'core ' , 'lang ' , '' );
105- switch ($ userlang ) {
104+ switch ($ this ->getAvatarLanguage ()) {
106105 case 'zh_TW ' :
107106 return __DIR__ . '/../../../core/fonts/NotoSansTC-Regular.ttf ' ;
108107 case 'zh_HK ' :
@@ -129,7 +128,7 @@ protected function generateAvatarFromSvg(string $userDisplayName, int $size, boo
129128 // Avatar generation breaks if RSVG format is enabled. Fall back to gd in that case
130129 if (in_array ('RSVG ' , $ formats , true )) {
131130 return null ;
132- }
131+ }
133132 $ text = $ this ->getAvatarText ();
134133 try {
135134 $ font = $ this ->getFont ($ text );
@@ -282,4 +281,12 @@ public function avatarBackgroundColor(string $hash): Color {
282281
283282 return $ finalPalette [$ this ->hashToInt ($ hash , $ steps * 3 )];
284283 }
284+
285+ /**
286+ * Get the language to be used for avatar generation.
287+ * This is used to determine the font to use for the avatar text (e.g. CJK characters).
288+ */
289+ protected function getAvatarLanguage (): string {
290+ return $ this ->config ->getSystemValueString ('default_language ' , 'en ' );
291+ }
285292}
0 commit comments