Skip to content

Commit

Permalink
Fix diagram text encoding on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
atextor committed Oct 11, 2023
1 parent c96bcae commit 0fb5572
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ public void generateSvg( final Locale language, final OutputStream out )
final Graphviz graphviz = render( diagram );

try ( final InputStream fontStream = getInputStream( FONT_FILE ) ) {
final String svgDocument = graphviz.toSvgStr().replaceAll( "«", "«" )
.replaceAll( "»", "»" );
final String svgDocument = new String( graphviz.toSvgStr().getBytes( System.getProperty( "file.encoding" ) ),
StandardCharsets.UTF_8 )
.replace( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "" )
.replace( "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">", "" );

// To make the font available in the generated SVG, it needs to be Base64-encoded
// and embedded in the file.
Expand All @@ -150,8 +152,6 @@ public void generateSvg( final Locale language, final OutputStream out )
+ "}\n"
+ "</style>";
final String result = svgDocument
.replace( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "" )
.replace( "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">", "" )
.replaceFirst( ">", ">" + css );
out.write( result.getBytes( StandardCharsets.UTF_8 ) );
} catch ( final ExecuteException exception ) {
Expand Down

0 comments on commit 0fb5572

Please sign in to comment.