PROGRAM-ID. QRSAMPLE.

      

       CONFIGURATION SECTION.

       REPOSITORY.

           CLASS JFile           AS "java.io.File"

           CLASS FileInputStream AS "java.io.FileInputStream"

           CLASS HashMap         AS "java.util.HashMap"

           CLASS Map             AS "java.util.Map"

           CLASS ImageIO         AS "javax.imageio.ImageIO"

           CLASS BarcodeFormat   AS "com.google.zxing.BarcodeFormat"

           CLASS BinaryBitmap    AS "com.google.zxing.BinaryBitmap"

           CLASS EncodeHintType  AS "com.google.zxing.EncodeHintType"

           CLASS MultiFormatReader

                                 AS "com.google.zxing.MultiFormatReader"

           CLASS MultiFormatWriter

                                 AS "com.google.zxing.MultiFormatWriter"

           CLASS Result          AS "com.google.zxing.Result"

           CLASS WriterException AS "com.google.zxing.WriterException"

           CLASS BufferedImageLuminanceSource                     

                                 AS "com.google.zxing.client.j2se.Buffer

      -                                         "edImageLuminanceSource"

           CLASS MatrixToImageWriter

                   AS "com.google.zxing.client.j2se.MatrixToImageWriter"

           CLASS BitMatrix       AS "com.google.zxing.common.BitMatrix"

           CLASS HybridBinarizer

                            AS "com.google.zxing.common.HybridBinarizer"

           CLASS ErrorCorrectionLevel

               AS "com.google.zxing.qrcode.decoder.ErrorCorrectionLevel"

           .

          

       INPUT-OUTPUT SECTION.

       FILE-CONTROL.

           SELECT PRINT-FILE ASSIGN TO PRINT "-P PREVIEW".

          

       FILE SECTION.

       FD PRINT-FILE.

       01 PRINT-RECORD PIC X(80).

          

       WORKING-STORAGE SECTION.

           COPY "isgui.def".

           COPY "isprint.def".

       77  hintMap      OBJECT REFERENCE Map.

       77  mfw          OBJECT REFERENCE MultiFormatWriter.

       77  matrix       OBJECT REFERENCE BitMatrix.

       77  bbitmap      OBJECT REFERENCE BinaryBitmap.

       77  buffimage    OBJECT REFERENCE BufferedImageLuminanceSource.

       77  qrCodeResult OBJECT REFERENCE Result.

       77  bb           OBJECT REFERENCE BinaryBitmap.

           

       77  imgPath   PIC X(14) VALUE "veryant_qr.png".      

       77  imgType   PIC X(3VALUE "PNG".

       77  qrText    PIC X(22) VALUE "http://www.veryant.com".

       77  imgWidth  PIC 9(5VALUE 200.

       77  imgHeight PIC 9(5VALUE 200.

      

       77  QR-HANDLE PIC S9(9) COMP-4.     

      

       77  KEY-STATUS SPECIAL-NAMES CRT STATUS PIC 9(5).

       78  PRINT-QR   VALUE 100.

       78  ESC        VALUE 27.

          

       SCREEN SECTION.

       01 SCREEN-1.

          03 LABEL TITLE "Use the QR below to reach our site"

             LINE 3, COL 3, SIZE 60 CELLS

             .

          03 BMP-QR BITMAP

             LINE 5, COL 3, LINES 200, SIZE 200

             BITMAP-HANDLE QR-HANDLE

             .

          03 PUSH-BUTTON TITLE "&Print"

             LINE 20, COL 3, SIZE 12 CELLS

             EXCEPTION-VALUE PRINT-QR

             .

       PROCEDURE DIVISION.

       MAIN-LOGIC.     

           PERFORM GENERATE-QR-IMAGE.

           CALL "W$BITMAP" USING WBITMAP-LOAD, imgPath

                          GIVING QR-HANDLE.

      

           DISPLAY STANDARD GRAPHICAL WINDOW.

           DISPLAY SCREEN-1.

           PERFORM UNTIL KEY-STATUS = ESC

              ACCEPT SCREEN-1

                 ON EXCEPTION

                    IF KEY-STATUS = PRINT-QR

                       PERFORM PRINT-QR-IMAGE

                    END-IF

              END-ACCEPT

           END-PERFORM.

           DESTROY SCREEN-1.

           CALL "W$BITMAP" USING WBITMAP-DESTROY, QR-HANDLE.

           GOBACK.

 

       GENERATE-QR-IMAGE.

           TRY

              SET hintMap TO HashMap:>new() AS Map

              hintMap:>put(EncodeHintType:>ERROR_CORRECTION,

                           ErrorCorrectionLevel:>L)

              SET mfw TO MultiFormatWriter:>new()              

              SET matrix TO mfw:>encode(qrText,

                                        BarcodeFormat:>QR_CODE,

                                        imgWidth,

                                        imgHeight,

                                        hintMap) AS BitMatrix

              MatrixToImageWriter:>writeToFile(matrix,

                                               imgType,

                                               JFile:>new(imgPath)

                                               )

           CATCH EXCEPTION

              DISPLAY MESSAGE EXCEPTION-OBJECT ICON MB-ERROR-ICON

              EXIT PARAGRAPH

           END-TRY.     

          

       PRINT-QR-IMAGE.

           OPEN OUTPUT PRINT-FILE.

          

           INITIALIZE WPRTDATA-DRAW.

           MOVE 2  TO WPRTDATA-DRAW-START-X.

           MOVE 2  TO WPRTDATA-DRAW-START-Y.

           MOVE WPRTUNITS-CENTIMETERS TO WPRTDATA-DRAW-UNITS.

           CALL "WIN$PRINTER" USING WINPRINT-SET-CURSOR

                                    WINPRINT-DATA.

           WRITE PRINT-RECORD FROM "Use the QR below to reach our site"

                              WITH NO CONTROL.

                             

           INITIALIZE WPRTDATA-PRINT-BITMAP.

           MOVE QR-HANDLE TO WPRTDATA-BITMAP.

           MOVE 3         TO WPRTDATA-BITMAP-ROW.

           MOVE 2         TO WPRTDATA-BITMAP-COL.

           MOVE 2         TO WPRTDATA-BITMAP-WIDTH.          

           MOVE 2         TO WPRTDATA-BITMAP-HEIGHT.

           COMPUTE WPRTDATA-BITMAP-FLAGS = WPRTBITMAP-UNITS-CENTIMETERS

                                         + WPRTBITMAP-SCALE-CENTIMETERS.

           CALL "WIN$PRINTER" USING WINPRINT-PRINT-BITMAP

                                    WINPRINT-DATA.

           CLOSE PRINT-FILE.