ropensci / rsvg

SVG renderer for R based on librsvg2
Other
95 stars 1 forks source link

Fails to render unicode characters #23

Open Sumidu opened 3 years ago

Sumidu commented 3 years ago

Hi, I am trying to add a bolded Unicode characters in a plot that exports SVG. When trying to write the SVG file to a pdf, the Unicode character seems to break. Sorry, for the long example. I can't upload SVG-files to GitHub.

g <- 'digraph G {
  graph [
    charset = "UTF-8",
    rankdir = LR
  ]

  edge []
  "A" -> {"B"}[label = < <B>𝜸 = 0.963</B>>]
}'

plot <- DiagrammeR::grViz(g)
svg_string <- DiagrammeRsvg::export_svg(plot)
fileConn <- file("output.svg")
writeLines(svg_string, fileConn)
close(fileConn)
rsvg::rsvg_pdf(svg = "output.svg", "output.pdf")

output.pdf

Interestingly, when I remove the and bold tags, everything works fine. I have figured out that math symbols have their own "bolded" versions. However, the graph definition in my case would be in "user-land" and I have no clever way of predicting which character would appear with which formatting, so a lookup-table seems out of scope right now.