Last time I logged one issue for duplicated XObjects with subtype image by Cairo 1.8.8.Chris advised me to use the new version of Cairo 1.9.4, which should address this problem.
I just use the Cairo 1.9.4 to generate the pdf output. After I did a simple test and went tthrough the cairo output, I still found many dulplicated objects.
Take object 213 and 216 in the attachment for example. They are duplicated with each object.Can anyone take a look whether we can eliminate the redudant objects.
It seems we are using the unique id of the image surface as the hash key for the surfaces cache, however it's possible to add the same image multiple times using different cairo surfaces. We would need to use the image contents (or even better the mime data if it exists) to make sure we don't duplicate image xobjects.
Fix in git master
A new mime type CAIRO_MIME_TYPE_UNIQUE_ID has been added. Surfaces with the same unique id will only be embedded once even if different surfaces are created. We've offloaded the job of identifying different surfaces with the same content to the application. You can put what ever you want in the UNIQUE_ID to uniquely identify the surface. eg a filename or SHA1 hash.