Twips, Pixels, and Inches oh my!

  • Ok... I don't know about you, but when I look at drawing a graphic for a watermark or drawing whatever to the canvas (both wPDF and wpTools) I sometimes just glaze over. Mainly because I have only done it a few times and haven't done an in depth study of the different calculations and all the different units that might be used and what coordinate system and so forth.

    So what I thought would be useful would be someone giving a good fundamentals of drawing to the canvas and the mathmatical background behind it and the units being used... especially pertaining to wptools and wpdf.

    For instance when you look at some of the source code or examples you see things that might reference CM (Centimeters) or pixels or twips or x per inch, or MulDiv this or round that. And what happens if you switch from dealing with the screen and now deal with the printer. In some areas I see it changes things all over again.

    My point is it can be a little confusing when you first start looking at this and it would be great if we had a good tutorial along with clear examples of things like:

    wPDF Canvas and WPTools Canvas and when printing...
    - Drawing a graphic to fill the entire page
    - Drawing a graphic to be positioned in the center of the page and stay the original dimensions (no streching)
    - Drawing a graphic and rotating it x degrees on the center of the page
    - Positioning text
    - Drawing graphics to be in the various corners of the canvas.
    - What to do when printing versus to the screen if anything.

    On reason I bring this up is because I am simply trying to use the DrawTGraphic to place a graphic (like a watermark) on the cavas of the wpdf and I am having a heck of a time just centering the stink'n thing. In other areas I see the MulDiv(w, xres, WPScreenPixelsPerInch) and xres and yres get their falues from the FFont?PixeslPerInch so then I start wondering what the heck do I use for x, y, w, h of the DrawTGraphic to get this thing in the center of the page, but no matter what I just miss the mark.

    Like when do I need to use the MulDiv and when not?

    Anyway... I think you get the picture and any feedback or helpful things you do to help you follow the Delphi coordinate, graphic, unit system would be helpful.

    • Offizieller Beitrag

    First,

    please note: DrawTGraphic does NOT draw on the "Canvas" of wPDF. Instead it exports an image directly to PDF. If it is a metafdile the vectors will be translated to PDF code, if it is an image, the image will be embedded and used. (It can be used later again with UseBitmap and the ID)

    When printing a wptools watermark You should use Canvas.StretchDraw, not DrawTGraphic.

    According to the resolution Twips/Pixels ...

    Twips are used like inch or cm, they are device independent.
    twip = inch/1440 = (cm / 2.54)/1440

    I think the problem You have is caused by the combination of several report outputs, esspecially ACE which I do not have anymore and so cannot create a prototype for You.

    Solving such problems I would start to simplify the process, first export each individual output into seperate PDF files.

    When this works - in case of WPTools there should be no problem when You use the PDFExport.Print, incl. the watermarks - we can work on combining those.

    Ideally calling the ouput routines after a PDFExport.BeginDoc should create a "big" PDF file. The file is closed with EndDoc.

    Julian

  • Zitat von wpsupport

    First,

    please note: DrawTGraphic does NOT draw on the "Canvas" of wPDF. Instead it exports an image directly to PDF. If it is a metafdile the vectors will be translated to PDF code, if it is an image, the image will be embedded and used. (It can be used later again with UseBitmap and the ID)

    Sorry for my incorrect terminology... I have studied through it and more and more it is clearing up.

    Zitat von wpsupport

    When printing a wptools watermark You should use Canvas.StretchDraw, not DrawTGraphic.

    Yes... I have only used the StretchDraw (played with Draw) for the OnWatermark event. I used the DrawTGraphic only for wPDF.

    I have been working with the different reports individually for testing so I don't have any issues do to mixing reports... I think for me the biggest problem is just understanding the whole graphic system and what to do to calculate the left, rigth, top, bottom, width, height values needed for various methods. Like when am I looking at twips versus some other unit. Or what units am I looking at in the first place. Or what resolution do I deal with... screen or printer. I think it is mostly just understanding these new things as I have mostly done database work and not anything related to drawing on a canvas or anything dealing in the graphic world.

    And in the other post you will see the the issue with the OnWatermark and going to wPDF and how it also caused issues with the DrawTGraphic. But that's another post.

    Thanks

    • Offizieller Beitrag

    Hi,

    Zitat

    I think for me the biggest problem is just understanding the whole graphic system

    If you use SetMapMode(Canvas.Handle, MM_TEXT) You are back in the device dependent resolution coordinate system. Then You can use the usual prointing code to draw to a page. You can read the resolution using GetDeviceCaps and calculate Your coordinates accordingly.

    It would be best to use SaveDC/RestoreDC to avoid problems with the rest of the drawing code.

    Julian