## Printer Device Driver

[prev][next][parent][TOC]

### Example Code

Retrieving Strings From String Sorter During Band Processing

Following is an example of retrieving strings from string sorter during band processing in a raster printer driver:

     HSORTER hSorter;

     CharString( PDDC pddc, ..., LONG cChars, PCH pchString, ... )

     {

       if( bDeviceFont )                        // If we have a device font to manage

       {

         if( ! hSorter )                        // If we have not yet created a sorter

         {

           // Create a string sorter to handle our device fonts

           apiret = GplStringSorterCreateInstance( pddc,&hSorter, 0L, 0L );

         } /* end if */

         // Calculate text box of string from our character-width tables

         // Insert character string into sorter

         apiret = GplStringSorterInsertString( hSorter,

                                               (PSZ)pchString,

                                               rectlTextBox,

                                               (PVOID)NULL,

                                               (PVOID)NULL );

         // Example: check number of strings currently in sorter

         apiret = GplStringSorterQueryNumStrings( hSorter,&ulNumStr );

       } /* end if */

     } /* end CharString */

     Usage Notes:

       Used default values for heap size and options during 'StringCreate' API (LTR, TTB).

       Used default value for during 'StringInsert' API.

       For 'StringInsert' API, we could have allocated and filled in our own

       structure that helps us process this string (for example, font name, identifier,

       color, etc.).

Removing Strings From a String Sorter During Processing of a Graphics Band

Following is an example of removing strings from a string sorter during processing of a graphics band (banding):

     ProcessBand( PDDC pddc, ...)

     {

       APIRET  apiret;

       RECTL   rectlString, rectlBand;

       PSZ     pszString;

       // Retrieve first sting in the raster band we are processing

       apiret = GplStringSorterGetFirstString(

                    hSorter,

                    STR_INCL_TOP_LEFT_IN_BAND,

                                     // Retrieve strings whose Top-Left corner are in band

                    rectlBand,

                                     // Rectangle of the graphic band we are processing

                    &pszString,

                                     // Pointer that first string will be returned in

                    &rectlString,

                                     // Text box of the string

                    (PVOID)NULL );

                                     // We had no user-defined data to retrieve

       // if we have a string meeting retrieval criteria

       while( apiret != ERROR_NO_MORE_ITEMS )

       {

         // Get next string (uses same retrieve option as "GetFirst")

         apiret = GplStringSorterGetNextString( hSorter,

                                                &pszString,

                                                &rectlString,

                                                (PVOID)NULL );

       } /* end while */

     } /* end ProcessBand */

Removing Strings From a String Sorter After Retrieving Them

Following is an example of removing strings from a string sorter after retrieving them (during graphics band processing):

     ProcessBand( PDDC pddc, ... )

     {

       // After retrieving all strings from band and sending them to printer

       // See the previous example

       // We can remove these strings from the sorter

       // since we do not need to process them again

       apiret = GplStringSorterRemoveStrings( hSorter,

                                              STR_INCL_TOP_LEFT_IN_BAND,

                                              rectlBand );

     } /* end ProcessBand */

Resetting and Destroying the String Sorter During Escape Processing

Following is an example of resetting and destroying the string sorter during escape processing in a printer driver:

     Escape( PDDC pddc, ... )

     {

       APIRET apiret;

       case DEVESC_NEWFRAME:

       {

         // Process all graphics bands on page

         // Reset sorter for next page

         apiret = GplStringSorterReset( hSorter );

        } /* end case */

        break;

        case DEVESC_ENDDOC:

        {

          // Process the last page (implied NewFrame)

          // Sorter no longer needed for this print job

          apiret = GplStringSorterDeleteInstance( hSorter );

        } /* end case */

        break;

     } /* end Escape */