diff --git a/src/components/shared/SvgTextLogo/SvgTextLogo.tsx b/src/components/shared/SvgTextLogo/SvgTextLogo.tsx index f214190..db5efec 100644 --- a/src/components/shared/SvgTextLogo/SvgTextLogo.tsx +++ b/src/components/shared/SvgTextLogo/SvgTextLogo.tsx @@ -1,51 +1,74 @@ -"use client"; - -import { memo } from "react"; -import useSvgTextLogo from "./useSvgTextLogo"; -import { cls } from "@/lib/utils"; +import React from 'react'; interface SvgTextLogoProps { - logoText: string; - adjustHeightFactor?: number; - verticalAlign?: "top" | "center"; + text: string; className?: string; + fontSize?: number; + fontWeight?: number | string; + letterSpacing?: number; + dominantBaseline?: 'auto' | 'middle' | 'hanging' | 'mathematical' | 'central'; } -const SvgTextLogo = memo(function SvgTextLogo({ - logoText, - adjustHeightFactor, - verticalAlign = "top", - className = "", -}) { - const { svgRef, textRef, viewBox, aspectRatio } = useSvgTextLogo(logoText, false, adjustHeightFactor); +const SvgTextLogo: React.FC = ({ + text, + className = '', + fontSize = 64, + fontWeight = 700, + letterSpacing = 0, + dominantBaseline = 'middle', +}) => { + const canvas = React.useRef(null); + const [dimensions, setDimensions] = React.useState({ width: 0, height: 0 }); + + React.useEffect(() => { + if (!canvas.current) return; + + const ctx = canvas.current.getContext('2d'); + if (!ctx) return; + + const fontString = `${fontWeight} ${fontSize}px -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif`; + ctx.font = fontString; + + const metrics = ctx.measureText(text); + const width = Math.ceil(metrics.width + letterSpacing * text.length); + const height = Math.ceil(fontSize * 1.2); + + canvas.current.width = width; + canvas.current.height = height; + + ctx.font = fontString; + ctx.fillStyle = 'black'; + ctx.textAlign = 'left'; + ctx.textBaseline = dominantBaseline === 'middle' ? 'middle' : 'top'; + + let x = 0; + for (let i = 0; i < text.length; i++) { + ctx.fillText(text[i], x, height / 2); + x += ctx.measureText(text[i]).width + letterSpacing; + } + + setDimensions({ width, height }); + }, [text, fontSize, fontWeight, letterSpacing, dominantBaseline]); return ( - - {logoText} - + + + ); -}); - -SvgTextLogo.displayName = "SvgTextLogo"; +}; export default SvgTextLogo;