Announcement

Collapse
No announcement yet.

printing even columns with non-fixed font

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • printing even columns with non-fixed font

    Is there any easy way of printing to a printer with a variable-length
    font and still keeping the columns even and right-justified when
    necessary, or do I have to go through all the trouble of coding the
    lengths line by line? I have an application that creates reports and
    writes them to a file in ascii with the columns lined up correctly, but
    now I have come across occasion to print this file using a variable len
    font. Anyone ever tackled this before?

    Regards,
    Jim

    -------------
    Jim Seekamp

    Jim Seekamp

  • #2
    There are 2 third party libraries that I know of for pbdll/pbcc that will make what you're trying to do much easier ...
    1. Lance's DLL/PRINT - I don't know the URL, but Lance will probably post it. I've heard only good things about this utility - especially from those that come from DOS-land.
    2. I have a print/preview engine that makes this trivial - www.basicguru.com/dickinson

    If you want to code it yourself, have a look at the SetTextAlign API call - you can set it so that text prints justified
    Don Dickinson
    www.greatwebdivide.com

    Comment


    • #3
      Thanks for the "plug" Don!

      DOSPRINT and DLLPRINT can make this task trivial if you use a fixed-pitch font, but there are a few possible solutions.

      For example, the "soon to be released" update to DOSPRINT includes a new feature that allows you to use a proportional-pitch font but with "columnized" output... think of it as "emulated" fixed-pitch printing!

      Another way could be to set a tab stop and print the "text" at that position... tab stops and font changes are quite straight forward with DOSPRINT and DLLPRINT.

      For those that are not familiar with DOSPRINT (available as an EXE for use with DOS and windows applications) and DLLPRINT (available as a DLL for your with PB/CC and PB/DLL applications), this "utilities" enable formatting of text onto *ANY* printer, using a single set of "Escape Codes" (based on Epson's ESC/P2 codes) to control the print formatting.

      For example, your code only ever needs to generate one type of "output" regardless of the type of printer you want to use or how it is connected, such as USB, serial, network, etc. Even Windows-only (GDI) printers can now be used with DOS code!

      With DOSPRINT and DLLPRINT, you can change fonts, scale the fonts, draw DOS-like "graphic" boxes, etc. The next generation will even allow images to be included in your print jobs, plus a Print Preview mode too!

      If you would like to take a look at the (current version of the) DOSPRINT demo, visit http://www.amerimports.com/dosprint

      Feel free to ask any questions you may have.

      Regards,
      Lance.

      Lance
      mailto:lanceed[email protected]

      Comment


      • #4
        I'm not quite clear on whether either of these products allow you to print VARIABLE-pitch
        fonts in a Windows (PBDLL v6.0) application with ablity to line up columns evenly. (?)

        - Jim


        -------------
        Jim Seekamp


        Jim Seekamp

        Comment


        • #5
          I may be misunderstanding your question ... My print engine (ddoc) has calls that let you print anywhere on the page at any alignment. Tell the dll to print 1" down 1"over, right aligned and it will do it. It also has a command that lets you define tab stops and print a row of tab-delimited text. I don't have anything that will take a proportional font and turn it into a fixed width font - it sounds like Lance's next release will have this feature.

          Best Regards,
          Don
          Don Dickinson
          www.greatwebdivide.com

          Comment


          • #6
            Sorry for the confusion Don; and thanks for your responses.
            Maybe I'm just wording it wrong, but all I'm looking for is the ability
            to print text to a printer using a variable-pitch font, and have the
            columns still line up when the numbers are right-justified.
            Does your application do this?

            Regards
            Jim


            -------------
            Jim Seekamp


            Jim Seekamp

            Comment


            • #7
              Jim,
              Don's ddoc does it easily using column settings. I use it
              to shell from DOS programs and print using Windows! The
              program also supports e-mailing, color, fonts, faxing, printing
              to any printer, printing bmps, previewing, label support and much more.
              The program is very inexpensive and comes with the source code.
              If I was a reviewer, I would give it a "buy recommendation".

              Mike Doty
              How long is an idea? Write it down.

              Comment


              • #8
                Mike:
                Thanks for the vote of confidence!

                Jim:
                My engine doesn't do what you're looking for. It does not take a proportional font and print it like a fixed width font. It sounds to me like Lance's might be doing this in an upcoming version. My engine does have commands easily print columns of text.

                Best Regards,
                Don
                Don Dickinson
                www.greatwebdivide.com

                Comment


                • #9
                  OK - thanks anyways.

                  Best Regards,
                  Jim


                  -------------
                  Jim Seekamp

                  Jim Seekamp

                  Comment


                  • #10
                    Guys --
                    English is not my first language, but like I understand, Jim wants to be able to print like in Excel (right-justified columns), not more. He don't want to justify separate digits.
                    I didn't tried DDOC, but don't beleive that Don's engine is not able to do it - this is too typical operation.

                    Comment


                    • #11
                      I think Semen is right; the only thing I need to line up exactly is the decimal point...
                      however, if the numbers are different lengths, then I suppose Don is right. (???)
                      I'm beginning to wonder how painstaking this process will end up to be.
                      Is this all really that complex? Excel IS a good example of what I'm trying to do; have the numbers line up even though the font is, say, Arial or something.


                      -------------
                      Jim Seekamp

                      Jim Seekamp

                      Comment


                      • #12
                        Lance; after reading your reply again, I have a feeling your next version has what I'm looking for;
                        any idea when it will come out?


                        -------------
                        Jim Seekamp

                        Jim Seekamp

                        Comment


                        • #13
                          Jim ---
                          Like I understand, you want to print numbers with fixed point's place
                          for example
                          Code:
                             123.56
                            4567.3274
                          This means that you have two fields: right justified (left part of number, including .) and left justified (right part of number, after .)
                          Sure, that Don's and Lance's programs are able to do it.
                          Printing in Windows, like drawing, is enough complex. You can open books and see a lot of statements. Even in VB it's not very easy.
                          I think that if you want to have nice printing, better to use external software.

                          [This message has been edited by Semen Matusovski (edited January 26, 2000).]

                          Comment


                          • #14
                            Aligning on the decimal is not a problem. Decide on the position of the decimal and print the number at the decimal position - the printer's text width of the text up to the decimal.

                            Don't forget to allow for other decimal characters like a comma.

                            Dennis

                            Comment


                            • #15
                              In printing (as in newspapers, for example) figures have a set width, even in variable width fonts (except fancy stuff) such as Times and Helvetica.

                              An "Em" space in printing represents a square equal to the size of the type while an "En" space is half the width. For example, in 12-point type an "Em" space is 12 points wide and an "En" space in 6 points wide.

                              Figures are normally equal to an "En" Space so if one can find a character equal to the width of an "En" space and pad up the right-hand side of a decimal number, one will get easy alignment.

                              I deal mainly with postscript printers and I can't remember the codes off hand but I do know an "En" dash - the same width as a figure - is octal 261 and an "Em" dash is octal 320.

                              I'll look it up - all that data is at work - and maybe I can be of some help.

                              Regards,
                              Brian.


                              Brian.

                              Comment


                              • #16
                                I think I phrased a couple of things badly in my contribution.

                                Where, in the first par, I refer to fancy type I don't mean that Times and Helvetica come into that category.

                                Where I suggest you find a character and pad up the right-hand side of decimal lines, what I meant was to find a space character to pad it up with.

                                Hope that clarifies my contribution.

                                Regards,
                                Brian.
                                Brian.

                                Comment


                                • #17
                                  Thanks to all you who responded.

                                  Best Regards
                                  Jim


                                  -------------
                                  Jim Seekamp

                                  Jim Seekamp

                                  Comment


                                  • #18
                                    Hi Jim,

                                    For any printouts in any programing languages, you just need to get the size of every elements to be able to align it. The GetDeviceCaps API function will help you very well to do that. Here is a simple exemple of how to print a bitmap in a device context and aligning a text bellow.

                                    It is in C++, but it is soo easy to understand!

                                    Good Luck!

                                    Francis Beaulieu
                                    [email protected] Softwares

                                    Code:
                                    The following example shows the code required to print a string of text and a bitmapped image. The string of text, centered at the top of the page, identifies the path and filename for the file that contains the bitmapped image. The bitmapped image, centered vertically and horizontally on the page, is drawn so that the same proportions used to draw the image in the application's window are maintained. 
                                    
                                                    /*  
                                                     * Initialize the members of a DOCINFO  
                                                     * structure. 
                                                     */ 
                                     
                                                     di.cbSize = sizeof(DOCINFO); 
                                                     di.lpszDocName = "Bitmap Printing Test"; 
                                                     di.lpszOutput = (LPTSTR) NULL; 
                                                     di.lpszDataType = (LPTSTR) NULL; 
                                                     di.fwType = 0; 
                                     
                                                    /* 
                                                     * Begin a print job by calling the StartDoc 
                                                     * function. 
                                    
                                                     */ 
                                     
                                                     nError = StartDoc(pd.hDC, &di); 
                                                     if (nError == SP_ERROR) { 
                                                         errhandler("StartDoc", hwnd); 
                                                         goto Error; 
                                                        } 
                                     
                                                    /* 
                                                     * Inform the driver that the application is 
                                                     * about to begin sending data. 
                                                     */ 
                                     
                                                     nError = StartPage(pd.hDC); 
                                                     if (nError <= 0) { 
                                    
                                                         errhandler("StartPage", hwnd); 
                                                         goto Error; 
                                                        } 
                                     
                                                    /* 
                                                     * Retrieve the number of pixels-per-logical-inch 
                                                     * in the horizontal and vertical directions 
                                                     * for the display upon which the bitmap 
                                                     * was created. 
                                                     */ 
                                     
                                                     fLogPelsX1 = (float) GetDeviceCaps(pd.hDC, LOGPIXELSX);  
                                                     fLogPelsY1 = (float) GetDeviceCaps(pd.hDC, LOGPIXELSY); 
                                    
                                      
                                     
                                                    /* 
                                                     * Retrieve the number of pixels-per-logical-inch 
                                                     * in the horizontal and vertical directions 
                                                     * for the printer upon which the bitmap 
                                                     * will be printed. 
                                                     */ 
                                     
                                                     fLogPelsX2 = (float) GetDeviceCaps(pd.hDC, 
                                                         LOGPIXELSX); 
                                                     fLogPelsY2 = (float) GetDeviceCaps(pd.hDC, 
                                                         LOGPIXELSY); 
                                    
                                     
                                                    /* 
                                                     * Determine the scaling factors required to 
                                                     * print the bitmap and retain its original 
                                                     * proportions. 
                                                     */ 
                                     
                                                     if (fLogPelsX1 > fLogPelsX2) 
                                                        fScaleX = (fLogPelsX1 / fLogPelsX2); 
                                                     else 
                                                        fScaleX = (fLogPelsX2 / fLogPelsX1); 
                                     
                                                     if (fLogPelsY1 > fLogPelsY2) 
                                                        fScaleY = (fLogPelsY1 / fLogPelsY2); 
                                    
                                                     else 
                                                        fScaleY = (fLogPelsY2 / fLogPelsY1); 
                                     
                                                    /* 
                                                     * Compute the coordinate of the upper left 
                                                     * corner of the centered bitmap. 
                                                     */ 
                                     
                                                     cWidthPels = GetDeviceCaps(pd.hDC, HORZRES); 
                                                     xLeft = ((cWidthPels / 2) - 
                                                                ((int) (((float) bmih.biWidth) 
                                                                 * fScaleX)) / 2); 
                                                     cHeightPels = GetDeviceCaps(pd.hDC, VERTRES); 
                                    
                                                     yTop = ((cHeightPels / 2) - 
                                                                ((int) (((float) bmih.biHeight) 
                                                                 * fScaleY)) / 2); 
                                     
                                                    /* 
                                                     * Create a memory DC that is compatible with 
                                                     * the printer and select the bitmap (which 
                                                     * the user requested) into this DC. 
                                                     */ 
                                     
                                                     hdcMem = CreateCompatibleDC(pd.hDC); 
                                     
                                                     if (!SelectObject(hdcMem, hbm)) 
                                    
                                                        errhandler("SelectObject Failed", hwnd); 
                                     
                                     
                                                    /* 
                                                     * Use the StretchBlt function to scale the 
                                                     * bitmap and maintain its original proportions 
                                                     * (that is, if the bitmap was square when it 
                                                     * appeared in the application's client area, 
                                                     * it should also appear square on the page). 
                                                     */ 
                                     
                                     
                                                     if (!StretchBlt(pd.hDC, xLeft, yTop, 
                                    
                                                             (int) ((float) bmih.biWidth * fScaleX), 
                                                             (int) ((float) bmih.biHeight * fScaleY), 
                                                             hdcMem, 0, 0, 
                                                             bmih.biWidth, bmih.biHeight, 
                                                             SRCCOPY)) 
                                                         errhandler("StretchBlt Failed", hwnd); 
                                     
                                     
                                                    /* Delete the memory DC. */ 
                                     
                                                     DeleteDC(hdcMem); 
                                     
                                                    /* 
                                                     * Retrieve the width of the string that 
                                    
                                                     * specifies the full path and filename for the 
                                                     * file that contains the bitmap. 
                                                     */ 
                                     
                                                     GetTextExtentPoint32(pd.hDC, ofn.lpstrFile, 
                                                         ofn.nFileExtension + 3, 
                                                         &szMetric); 
                                     
                                                    /* 
                                                     * Compute the starting point for the 
                                                     * text-output operation. The string will 
                                                     * be centered horizontally and positioned 
                                    
                                                     * three-lines down from the top of the page. 
                                                     */ 
                                     
                                                     xLeft = ((cWidthPels / 2) - (szMetric.cx / 2)); 
                                                     yTop = (szMetric.cy * 3); 
                                     
                                                    /* 
                                                     * Print the path and filename for the bitmap, 
                                                     * centered at the top of the page. 
                                                     */ 
                                     
                                                     TextOut(pd.hDC, xLeft, yTop, ofn.lpstrFile, 
                                                         ofn.nFileExtension + 3); 
                                    
                                     
                                                    /* 
                                                     * Determine whether the user has pressed 
                                                     * the Cancel button in the AbortPrintJob 
                                                     * dialog box; if the button has been pressed, 
                                                     * call the AbortDoc function. Otherwise, inform 
                                                     * the spooler that the page is complete. 
                                                     */ 
                                     
                                                     nError = EndPage(pd.hDC); 
                                     
                                                     if (nError <= 0) { 
                                                        errhandler("EndPage", hwnd); 
                                    
                                                        goto Error; 
                                                     } 
                                     
                                                    /* Inform the driver that document has ended. */ 
                                     
                                                     nError = EndDoc(pd.hDC); 
                                                     if (nError <= 0) 
                                                        errhandler("EndDoc", hwnd); 
                                     
                                    Error: 
                                                    /* Enable the application's window. */ 
                                     
                                                    EnableWindow(hwnd, TRUE); 
                                     
                                                    /* Remove the AbortPrintJob dialog box. */ 
                                     
                                                    DestroyWindow(hdlgCancel); 
                                    
                                     
                                                    /* Delete the printer DC. */ 
                                     
                                                    DeleteDC(pd.hDC); 
                                     
                                    
                                    Because the pixels on a screen typically have different dimensions than the dots on a printer, it is necessary to scale bitmapped images to obtain a WYSIWYG effect. This is done by obtaining horizontal and vertical scaling factors and then applying those factors to the width and height values passed to the StretchBlt function. In the sample application, the scaling factors were obtained by retrieving the horizontal and vertical logical-pixel count for the two devices. Once the scaling factors were obtained, they were used to adjust the bitmap width and height. 
                                    
                                    To center the bitmap on the page, the application first computed the width and height of the scaled bitmap. (The bitmap was scaled to maintain the original proportions of the image.) These values were divided by two and then subtracted from half of the width and height of the page. The result defines the coordinates of the upper left corner of the bitmap. 
                                    To center the text at the top of the page, the application called the GetTextExtentPoint32 function to retrieve the width and height of the string specifying the path names and filenames. Once these values were obtained, the application used the height to position the string three lines down the page and the width to position the string horizontally centered on the page. 
                                    
                                    The following illustration shows a representation of the page that appeared when the application printed the bitmapped image in the WINLOGO.BMP file. This illustration also depicts the variables used to position the text and to position and scale the bitmap.
                                    Francis Beaulieu
                                    Prog senior of 17 years.
                                    Microsoft Specialist

                                    Comment


                                    • #19
                                      I picked up a book recently called Print Programming in Windows by
                                      Jeff Potts, published by R&D Books, ISBN 0-87930-585-1, $39.95USD.
                                      It looks like it was just released several months ago. It explains
                                      in detail how to print text/graphics using both VB and C. A very easy
                                      book to read.

                                      I have ddoc, and also works like a charm. It is nice having the source
                                      code so I could strip it down and include it into my main EXE.

                                      Regards, Jules
                                      Best regards
                                      Jules
                                      www.rpmarchildon.com

                                      Comment


                                      • #20
                                        Lance; after reading your reply again, I have a feeling your next version has what I'm looking for; any idea when it will come out?
                                        Thanks for asking!

                                        Jim, the update to the DOSPRINT print engine itself is complete, I'm just finishing off the print-preview interface. Contact me privately if you'd like to sneak-a-peek at the alpha version. Once this is completed, DLLPRINT will be updated within a day or two (much of the code base is shared between both utilities).

                                        The DOSPRINT engine can be used with Win32 app's as well as DOS app's, the launch method is the key difference (DOSPRINT is launched with a SHELL, DLLPRINT is launched with a call to the DLL itself).

                                        Regards,
                                        Lance.
                                        Lance
                                        mailto:[email protected]

                                        Comment

                                        Working...
                                        X