@@ -72,6 +72,7 @@ type SVGConfig struct {
7272 FontData string
7373 FontMIME string
7474 FontFormat string
75+ TitleFont svgFont
7576}
7677
7778// TerminalState represents a unique terminal state for deduplication.
@@ -145,6 +146,14 @@ type SVGGenerator struct {
145146
146147// NewSVGGenerator creates a new SVG generator.
147148func NewSVGGenerator (opts SVGConfig ) * SVGGenerator {
149+ if opts .FontData != "" && strings .Contains (opts .FontFamily , "," ) {
150+ opts .FontFamily = captureFontFamily
151+ if opts .Style != nil {
152+ style := * opts .Style
153+ style .FontFamily = captureFontFamily
154+ opts .Style = & style
155+ }
156+ }
148157 // Get character dimensions from the first frame if available
149158 charWidth := float64 (opts .FontSize ) * 0.55 // fallback
150159 charHeight := float64 (opts .FontSize ) * 1.2 // fallback
@@ -994,8 +1003,15 @@ func (g *SVGGenerator) generateStyles() string {
9941003 g .writeNewline (& sb )
9951004
9961005 if g .options .FontData != "" {
997- fmt .Fprintf (& sb , `@font-face { font-family: "%s"; src: url("data:%s;base64,%s") format("%s"); }` ,
998- captureFontFamily , g .options .FontMIME , g .options .FontData , g .options .FontFormat )
1006+ family := g .options .FontFamily
1007+ if family == "" {
1008+ family = svgDefaultFontFamily
1009+ }
1010+ sb .WriteString ((svgFont {data : g .options .FontData , mime : g .options .FontMIME , format : g .options .FontFormat }).cssFace (family ))
1011+ g .writeNewline (& sb )
1012+ }
1013+ if g .options .TitleFont .data != "" {
1014+ sb .WriteString (g .options .TitleFont .cssFace (titleFontFamily ))
9991015 g .writeNewline (& sb )
10001016 }
10011017
@@ -1078,8 +1094,8 @@ func (g *SVGGenerator) generateStyles() string {
10781094 foregroundColor = defaultForegroundColor
10791095 }
10801096 // Use a simpler font stack for better compatibility
1081- textStyle := fmt .Sprintf ("fill: %s; font-family: %s, monospace ; font-size: %spx;" ,
1082- foregroundColor , fontFamily , formatCoord (g .fontSize ))
1097+ textStyle := fmt .Sprintf ("fill: %s; font-family: %s; font-size: %spx;" ,
1098+ foregroundColor , buildSVGFontFamily ( fontFamily ) , formatCoord (g .fontSize ))
10831099 // Don't apply letter-spacing in SVG as it causes cursor misalignment
10841100 // The character positions from xterm.js already account for the terminal's letter spacing
10851101 _ , _ = fmt .Fprintf (& sb , ".%s { %s }" , textClass , textStyle )
@@ -1747,6 +1763,9 @@ func (g *SVGGenerator) generateWindowBar() string {
17471763 if style .WindowBarTitle != "" {
17481764 // Get the appropriate font family with fallbacks
17491765 fontFamily := getWindowBarFontFamily (style , g .options .FontFamily )
1766+ if g .options .TitleFont .data != "" {
1767+ fontFamily = buildSVGFontFamily (titleFontFamily )
1768+ }
17501769 // Get the appropriate font size with fallback
17511770 fontSize := style .WindowBarFontSize
17521771 if fontSize == 0 {
@@ -1783,7 +1802,7 @@ func (g *SVGGenerator) generateWindowBar() string {
17831802 // Window controls occupy roughly 80px on each side
17841803 centerX := g .options .Width / 2
17851804 _ , _ = fmt .Fprintf (& sb , `<text x="%d" y="%d" text-anchor="middle" font-family="%s" font-size="%d" fill="#cccccc">` ,
1786- centerX , yPos , fontFamily , fontSize )
1805+ centerX , yPos , html . EscapeString ( fontFamily ) , fontSize )
17871806 sb .WriteString (html .EscapeString (style .WindowBarTitle ))
17881807 sb .WriteString (`</text>` )
17891808 g .writeNewline (& sb )
@@ -2103,20 +2122,19 @@ func parseFontFamily(fontFamily string) []string {
21032122func buildSVGFontFamily (fontFamily string ) string {
21042123 fonts := parseFontFamily (fontFamily )
21052124
2106- // Build a new list without quotes - SVG will handle the attribute quoting
2125+ // Preserve ordinary names and quote names with CSS metacharacters.
21072126 fontList := make ([]string , 0 , len (fonts )+ 1 )
21082127 hasMonospace := false
21092128
21102129 for _ , font := range fonts {
21112130 // Check if this is a generic font family
21122131 if font == svgDefaultFontFamily || font == uiMonospaceFont || font == "sans-serif" || font == "serif" {
2113- fontList = append (fontList , font )
2132+ fontList = append (fontList , cssFontFamily ( font ) )
21142133 if font == svgDefaultFontFamily {
21152134 hasMonospace = true
21162135 }
21172136 } else {
2118- // Add font names as-is, SVG attribute will be quoted
2119- fontList = append (fontList , font )
2137+ fontList = append (fontList , cssFontFamily (font ))
21202138 }
21212139 }
21222140
0 commit comments