On Sun, Apr 1, 2012 at 6:16 AM, Julian Viereck <
[email protected]> wrote:

> The second argument might look like this:
>
> sndArgument = {
>   DPI: 200,
>   preview: false
> };
>
> It's intended to expose more print related information to the user.
>

Hmm. Can you explain this a bit more?


> -- Is there a way to figure out the DPI resolution of the printout in C++?
>>
>
> Yes, cairo_surface_get_fallback_resolution. You should add a wrapper to
> gfxContext to return it.
>
>
> cairo_surface_get_fallback_resolution requires a cairo surface. Therefore
> I've added a new `GetFallbackResolution` on the gfxASurface class.
>
> Calling this function always return 300 by 300 pixels per inch. That's
> independent of the print quality I set on my printer or wether I choose
> "Save as PDF". The cairo documentation states
>
>     "This function returns the previous fallback resolution set
> by cairo_surface_set_fallback_resolution(), or default fallback resolution
> if never set."
>
> Therefore I'm wondering if this is really related to the actual DPI of the
> printer or just picks up some default value.
>

We probably need to set it somewhere.


> -- How can one figure out the actual size of the canvas when printed to
>> paper? I guess I can get some size-information from the CanvasFrame, but is
>> that the actual/resulting size on paper?
>>
>
> When printing, CSS units are rendered as physical units if the zoom factor
> is 100%. Each CSS px is 1/96 of an inch. Changing the zoom factor will
> change this of course.
>
> What do you need this for?
>
>
> Imagine you print a canvas that contains some computed image data. If you
> know the actual size of the canvas on the paper and the DPI resolution, one
> can compute what dimension the image data has to be in order to look good
> on the printout (e.g. if you don't compute a high enough resolution, the
> user will see pixels in the printout).
>
> Even in the case that the DPI of the printer might not be determinable,
> using 300DPI as the default value and multiply it by the size would still
> give a good guess what the image data size has to be.
>

I see. What sort of image data computation are we talking about? Probably
the proposed getImageData extensions, or some other API to get the actual
DPI of the canvas, would cover this.

I've played around with some CSS units (code in [1], resulting PDF in [2]).
> The "mm"-size used for the ctx.font has nothing to do with the actual
> printout size. This feels consistent to me and therefore right, as it
> renders to the same size/way the DOM canvas does, but it can confuse people
> that expect to get really 5mm on the printout.
>
> What's the way it should be?
>

I see what you mean. The problem is that setting the CSS width and height
of the canvas scales "canvas units", and the font size you specify is in
canvas units.

Changing this would make printing behave differently from normal drawing,
so we probably shouldn't change anything by default.

I looked into this today. I moved the code to swap the surface and call the
> mozPrintCallback function from the nsSimplePageSequence::
> PrintNextPage() into the nsPageFrame::paintPageContent function. Within
> preview the mozPrintCallback gets called now as well.
>
> However, the drawing looks pixeled (like it does without calling the
> callback/printing a normal canvas) and not like the print/"Save as PDF" at
> high/vector resolution. I did a
>
>       std::cout << "SurfaceType: " << printSurface->GetType();
>
> and it states the type is the same for printing and print preview.
>

We shouldn't switch the canvas type here, that's just wasteful (since
internally we'd render to a PDF surface or something and then render that
to a raster surface). Print preview should use the same canvas type as
normal screen drawing.

What we really need to do here is render to a higher-resolution backing
surface of the screen type. That's going to require a bit more canvas work.

Rob
-- 
“You have heard that it was said, ‘Love your neighbor and hate your enemy.’
But I tell you, love your enemies and pray for those who persecute you,
that you may be children of your Father in heaven. ... If you love those
who love you, what reward will you get? Are not even the tax collectors
doing that? And if you greet only your own people, what are you doing more
than others?" [Matthew 5:43-47]
_______________________________________________
dev-tech-layout mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-layout

Reply via email to