diff --git a/apps/api/src/routers/cert/gen.tsx b/apps/api/src/routers/cert/gen.tsx index 143c70d..dd3dcd5 100644 --- a/apps/api/src/routers/cert/gen.tsx +++ b/apps/api/src/routers/cert/gen.tsx @@ -48,6 +48,7 @@ Font.register({ interface MemberInfo { type: "member" | "adviser" thaiFirstname: string | null + thaiMiddlename: string | null thaiLastname: string | null award?: AwardKeys } @@ -177,7 +178,7 @@ const styles = StyleSheet.create({ flexDirection: "row", justifyContent: "flex-end", alignItems: "flex-start", - gap: 20, + gap: 8, }, nameText2Text: { color: "#282828", @@ -254,6 +255,24 @@ const styles = StyleSheet.create({ }, }) +function calculateNameFontSize( + firstname: string | null, + middlename: string | null, + lastname: string | null +): number { + const combinedLength = (firstname?.length || 0) + (middlename?.length || 0) + (lastname?.length || 0) + const MIN_SIZE = 8 + const MAX_SIZE = 40 + const SHORT_NAME_THRESHOLD = 10 + const LONG_NAME_THRESHOLD = 40 + + if (combinedLength <= SHORT_NAME_THRESHOLD) return MAX_SIZE + if (combinedLength >= LONG_NAME_THRESHOLD) return MIN_SIZE + + const ratio = (combinedLength - SHORT_NAME_THRESHOLD) / (LONG_NAME_THRESHOLD - SHORT_NAME_THRESHOLD) + return Math.max(MIN_SIZE, Math.round(MAX_SIZE - ratio * (MAX_SIZE - MIN_SIZE))) +} + interface CertificateDocumentProps { memberInfo: MemberInfo team: TeamInfo @@ -277,6 +296,11 @@ const CertificateDocument = ({ memberInfo, team }: CertificateDocumentProps) => const bottomLeftArtPath = path.join(__dirname, "imgs", config.lowerImage) const topRightArtPath = path.join(__dirname, "imgs", config.topImage) const awardFontSize = config.of === "ACHIEVEMENT" ? 24 : 20 + const nameFontSize = calculateNameFontSize( + memberInfo.thaiFirstname, + memberInfo.thaiMiddlename, + memberInfo.thaiLastname + ) return ( @@ -301,8 +325,17 @@ const CertificateDocument = ({ memberInfo, team }: CertificateDocumentProps) => ประกาศนียบัตรฉบับนี้ ให้ไว้เพื่อแสดงว่า - {memberInfo.thaiFirstname} - {memberInfo.thaiLastname} + + {memberInfo.thaiFirstname} + + {memberInfo.thaiMiddlename && ( + + {memberInfo.thaiMiddlename} + + )} + + {memberInfo.thaiLastname} + {teamPrefix} diff --git a/apps/api/src/routers/cert/index.ts b/apps/api/src/routers/cert/index.ts index 3f9a9a1..ee4b708 100644 --- a/apps/api/src/routers/cert/index.ts +++ b/apps/api/src/routers/cert/index.ts @@ -59,6 +59,7 @@ export const certRouter = { { type: "adviser", thaiFirstname: adviserInfo.thaiFirstname, + thaiMiddlename: adviserInfo.thaiMiddlename, thaiLastname: adviserInfo.thaiLastname, }, team @@ -109,6 +110,7 @@ export const certRouter = { { type: "member", thaiFirstname: memberInfo.thaiFirstname, + thaiMiddlename: memberInfo.thaiMiddlename, thaiLastname: memberInfo.thaiLastname, award: team.award as AwardKeys, },