s-u / Cairo

R graphics device using cairo graphics library for creating high-quality output
12 stars 10 forks source link

Add title parameter to specify titles for SVGs and PDFs #15

Closed flying-sheep closed 2 years ago

flying-sheep commented 8 years ago

Both PDFs (through metadata) and SVGs (through title) have the capability for titles.

instead of ignoring the title parameter, it should work for all output types that have the necessary capabilities.

s-u commented 8 years ago

AFAIK cairographics still doesn't support metadata so there is no way for Cairo to do that until that feature is added upstream. At least support for PDF metadata has been discussed on the cairographics lists some 7 years ago, but given that it's still not there I would not hold my breath.

s-u commented 2 years ago

Since cairographics version 1.16 there is now cairo_pdf_surface_set_metadata(surface, CAIRO_PDF_METADATA_TITLE, ...) so we could implement it now ...

flying-sheep commented 2 years ago

Neat!

s-u commented 2 years ago

After such an encouragement ;) this is now implemented for the PDF back-end. I have also added other metadata entries supported by cairo. Note that this requires cairo library version 1.16, the extra arguments will be silently ignored when used with older versions.

Unfortunately, the SVG back-end in cairo has not added this option. I will close this issue for now. If someone is interested in SVG, they may need to file it upstream and it would be then easy to add it here since we have the precedent of handling this for PDF.

flying-sheep commented 2 years ago

It’s the little things! Having a their PDF viewer show something meaningful in its window title could just make the difference between some overworked PhD student rediscovering what that specific plot meant and how it fits into the whole.

Thank you for doing it, I think I couldn’t have quickly figured out how to do the necessary incantations in pdf-backend.c

flying-sheep commented 2 years ago

And it works! With https://github.com/IRkernel/repr/pull/156:

> install.packages("Cairo", repo="https://rforge.net/")
> library(repr)
> plot(sqrt(1:10))
> title('roots')
> recordPlot() |> repr_pdf() |> writeBin('test.pdf')