|
|
1.1 ! root 1: //-------------------------------------------------------------------------- ! 2: // ! 3: // Module Name: OUTPUT.C ! 4: // ! 5: // Brief Description: This module contains the PSCRIPT driver's output ! 6: // functions and related routines. ! 7: // ! 8: // Author: Kent Settle (kentse) ! 9: // Created: 20-Nov-1990 ! 10: // ! 11: // Copyright (c) 1990 - 1993 Microsoft Corporation ! 12: // ! 13: // This routine contains routines to handle opening, writing to, and ! 14: // closing the output channel. ! 15: //-------------------------------------------------------------------------- ! 16: ! 17: #include "stdlib.h" ! 18: #include "pscript.h" ! 19: #include "enable.h" ! 20: #include "stdarg.h" ! 21: ! 22: // external declarations. ! 23: ! 24: extern BOOL bOutputHeader(PDEVDATA); ! 25: ! 26: // declarations of routines residing within this module. ! 27: ! 28: DWORD PSFIXToBuffer(CHAR *, PS_FIX); ! 29: ! 30: // we are using PS_FIX numbers, which are 24.8. therefore, there are only ! 31: // 256 possible fractional values, so here is a table containing their ! 32: // ASCII equivalents. ! 33: ! 34: static char *Fracs[] = ! 35: { ! 36: "", // 0.00000 0 / 256. ! 37: "004", // 0.00391 1 / 256. ! 38: "008", // 0.00781 2 / 256. ! 39: "012", // 0.01172 3 / 256. ! 40: "016", // 0.01563 4 / 256. ! 41: "020", // 0.01953 5 / 256. ! 42: "023", // 0.02344 6 / 256. ! 43: "027", // 0.02734 7 / 256. ! 44: "031", // 0.03125 8 / 256. ! 45: "035", // 0.03516 9 / 256. ! 46: "039", // 0.03906 10 / 256. ! 47: "043", // 0.04297 11 / 256. ! 48: "047", // 0.04688 12 / 256. ! 49: "051", // 0.05078 13 / 256. ! 50: "055", // 0.05469 14 / 256. ! 51: "059", // 0.05859 15 / 256. ! 52: "063", // 0.06250 16 / 256. ! 53: "066", // 0.06641 17 / 256. ! 54: "070", // 0.07031 18 / 256. ! 55: "074", // 0.07422 19 / 256. ! 56: "078", // 0.07813 20 / 256. ! 57: "082", // 0.08203 21 / 256. ! 58: "086", // 0.08594 22 / 256. ! 59: "090", // 0.08984 23 / 256. ! 60: "094", // 0.09375 24 / 256. ! 61: "098", // 0.09766 25 / 256. ! 62: "102", // 0.10156 26 / 256. ! 63: "105", // 0.10547 27 / 256. ! 64: "109", // 0.10938 28 / 256. ! 65: "113", // 0.11328 29 / 256. ! 66: "117", // 0.11719 30 / 256. ! 67: "121", // 0.12109 31 / 256. ! 68: "125", // 0.12500 32 / 256. ! 69: "129", // 0.12891 33 / 256. ! 70: "133", // 0.13281 34 / 256. ! 71: "137", // 0.13672 35 / 256. ! 72: "141", // 0.14063 36 / 256. ! 73: "145", // 0.14453 37 / 256. ! 74: "148", // 0.14844 38 / 256. ! 75: "152", // 0.15234 39 / 256. ! 76: "156", // 0.15625 40 / 256. ! 77: "160", // 0.16016 41 / 256. ! 78: "164", // 0.16406 42 / 256. ! 79: "168", // 0.16797 43 / 256. ! 80: "172", // 0.17188 44 / 256. ! 81: "176", // 0.17578 45 / 256. ! 82: "180", // 0.17969 46 / 256. ! 83: "184", // 0.18359 47 / 256. ! 84: "188", // 0.18750 48 / 256. ! 85: "191", // 0.19141 49 / 256. ! 86: "195", // 0.19531 50 / 256. ! 87: "199", // 0.19922 51 / 256. ! 88: "203", // 0.20313 52 / 256. ! 89: "207", // 0.20703 53 / 256. ! 90: "211", // 0.21094 54 / 256. ! 91: "215", // 0.21484 55 / 256. ! 92: "219", // 0.21875 56 / 256. ! 93: "223", // 0.22266 57 / 256. ! 94: "227", // 0.22656 58 / 256. ! 95: "230", // 0.23047 59 / 256. ! 96: "234", // 0.23438 60 / 256. ! 97: "238", // 0.23828 61 / 256. ! 98: "242", // 0.24219 62 / 256. ! 99: "246", // 0.24609 63 / 256. ! 100: "25", // 0.25000 64 / 256. ! 101: "254", // 0.25391 65 / 256. ! 102: "258", // 0.25781 66 / 256. ! 103: "262", // 0.26172 67 / 256. ! 104: "266", // 0.26563 68 / 256. ! 105: "270", // 0.26953 69 / 256. ! 106: "273", // 0.27344 70 / 256. ! 107: "277", // 0.27734 71 / 256. ! 108: "281", // 0.28125 72 / 256. ! 109: "285", // 0.28516 73 / 256. ! 110: "289", // 0.28906 74 / 256. ! 111: "293", // 0.29297 75 / 256. ! 112: "297", // 0.29688 76 / 256. ! 113: "301", // 0.30078 77 / 256. ! 114: "305", // 0.30469 78 / 256. ! 115: "309", // 0.30859 79 / 256. ! 116: "313", // 0.31250 80 / 256. ! 117: "316", // 0.31641 81 / 256. ! 118: "320", // 0.32031 82 / 256. ! 119: "324", // 0.32422 83 / 256. ! 120: "328", // 0.32813 84 / 256. ! 121: "332", // 0.33203 85 / 256. ! 122: "336", // 0.33594 86 / 256. ! 123: "340", // 0.33984 87 / 256. ! 124: "344", // 0.34375 88 / 256. ! 125: "348", // 0.34766 89 / 256. ! 126: "352", // 0.35156 90 / 256. ! 127: "355", // 0.35547 91 / 256. ! 128: "359", // 0.35938 92 / 256. ! 129: "363", // 0.36328 93 / 256. ! 130: "367", // 0.36719 94 / 256. ! 131: "371", // 0.37109 95 / 256. ! 132: "375", // 0.37500 96 / 256. ! 133: "379", // 0.37891 97 / 256. ! 134: "383", // 0.38281 98 / 256. ! 135: "387", // 0.38672 99 / 256. ! 136: "391", // 0.39063 100 / 256. ! 137: "394", // 0.39453 101 / 256. ! 138: "398", // 0.39844 102 / 256. ! 139: "402", // 0.40234 103 / 256. ! 140: "406", // 0.40625 104 / 256. ! 141: "410", // 0.41016 105 / 256. ! 142: "414", // 0.41406 106 / 256. ! 143: "418", // 0.41797 107 / 256. ! 144: "422", // 0.42188 108 / 256. ! 145: "426", // 0.42578 109 / 256. ! 146: "430", // 0.42969 110 / 256. ! 147: "434", // 0.43359 111 / 256. ! 148: "438", // 0.43750 112 / 256. ! 149: "441", // 0.44141 113 / 256. ! 150: "445", // 0.44531 114 / 256. ! 151: "449", // 0.44922 115 / 256. ! 152: "453", // 0.45313 116 / 256. ! 153: "457", // 0.45703 117 / 256. ! 154: "461", // 0.46094 118 / 256. ! 155: "465", // 0.46484 119 / 256. ! 156: "469", // 0.46875 120 / 256. ! 157: "473", // 0.47266 121 / 256. ! 158: "477", // 0.47656 122 / 256. ! 159: "480", // 0.48047 123 / 256. ! 160: "484", // 0.48438 124 / 256. ! 161: "488", // 0.48828 125 / 256. ! 162: "492", // 0.49219 126 / 256. ! 163: "496", // 0.49609 127 / 256. ! 164: "5", // 0.50000 128 / 256. ! 165: "504", // 0.50391 129 / 256. ! 166: "508", // 0.50781 130 / 256. ! 167: "512", // 0.51172 131 / 256. ! 168: "516", // 0.51563 132 / 256. ! 169: "520", // 0.51953 133 / 256. ! 170: "523", // 0.52344 134 / 256. ! 171: "527", // 0.52734 135 / 256. ! 172: "531", // 0.53125 136 / 256. ! 173: "535", // 0.53516 137 / 256. ! 174: "539", // 0.53906 138 / 256. ! 175: "543", // 0.54297 139 / 256. ! 176: "547", // 0.54688 140 / 256. ! 177: "551", // 0.55078 141 / 256. ! 178: "555", // 0.55469 142 / 256. ! 179: "559", // 0.55859 143 / 256. ! 180: "563", // 0.56250 144 / 256. ! 181: "566", // 0.56641 145 / 256. ! 182: "570", // 0.57031 146 / 256. ! 183: "574", // 0.57422 147 / 256. ! 184: "578", // 0.57813 148 / 256. ! 185: "582", // 0.58203 149 / 256. ! 186: "586", // 0.58594 150 / 256. ! 187: "590", // 0.58984 151 / 256. ! 188: "594", // 0.59375 152 / 256. ! 189: "598", // 0.59766 153 / 256. ! 190: "602", // 0.60156 154 / 256. ! 191: "605", // 0.60547 155 / 256. ! 192: "609", // 0.60938 156 / 256. ! 193: "613", // 0.61328 157 / 256. ! 194: "617", // 0.61719 158 / 256. ! 195: "621", // 0.62109 159 / 256. ! 196: "625", // 0.62500 160 / 256. ! 197: "629", // 0.62891 161 / 256. ! 198: "633", // 0.63281 162 / 256. ! 199: "637", // 0.63672 163 / 256. ! 200: "641", // 0.64063 164 / 256. ! 201: "645", // 0.64453 165 / 256. ! 202: "648", // 0.64844 166 / 256. ! 203: "652", // 0.65234 167 / 256. ! 204: "656", // 0.65625 168 / 256. ! 205: "660", // 0.66016 169 / 256. ! 206: "664", // 0.66406 170 / 256. ! 207: "668", // 0.66797 171 / 256. ! 208: "672", // 0.67188 172 / 256. ! 209: "676", // 0.67578 173 / 256. ! 210: "680", // 0.67969 174 / 256. ! 211: "684", // 0.68359 175 / 256. ! 212: "688", // 0.68750 176 / 256. ! 213: "691", // 0.69141 177 / 256. ! 214: "691", // 0.69531 178 / 256. ! 215: "699", // 0.69922 179 / 256. ! 216: "703", // 0.70313 180 / 256. ! 217: "707", // 0.70703 181 / 256. ! 218: "711", // 0.71094 182 / 256. ! 219: "715", // 0.71484 183 / 256. ! 220: "719", // 0.71875 184 / 256. ! 221: "723", // 0.72266 185 / 256. ! 222: "727", // 0.72656 186 / 256. ! 223: "730", // 0.73047 187 / 256. ! 224: "734", // 0.73438 188 / 256. ! 225: "738", // 0.73828 189 / 256. ! 226: "742", // 0.74219 190 / 256. ! 227: "746", // 0.74609 191 / 256. ! 228: "75", // 0.75000 192 / 256. ! 229: "754", // 0.75391 193 / 256. ! 230: "758", // 0.75781 194 / 256. ! 231: "762", // 0.76172 195 / 256. ! 232: "766", // 0.76563 196 / 256. ! 233: "770", // 0.76953 197 / 256. ! 234: "773", // 0.77344 198 / 256. ! 235: "777", // 0.77734 199 / 256. ! 236: "781", // 0.78125 200 / 256. ! 237: "785", // 0.78516 201 / 256. ! 238: "789", // 0.78906 202 / 256. ! 239: "793", // 0.79297 203 / 256. ! 240: "797", // 0.79688 204 / 256. ! 241: "801", // 0.80078 205 / 256. ! 242: "805", // 0.80469 206 / 256. ! 243: "809", // 0.80859 207 / 256. ! 244: "813", // 0.81250 208 / 256. ! 245: "816", // 0.81641 209 / 256. ! 246: "820", // 0.82031 210 / 256. ! 247: "824", // 0.82422 211 / 256. ! 248: "828", // 0.82813 212 / 256. ! 249: "832", // 0.83203 213 / 256. ! 250: "836", // 0.83594 214 / 256. ! 251: "840", // 0.83984 215 / 256. ! 252: "844", // 0.84375 216 / 256. ! 253: "848", // 0.84766 217 / 256. ! 254: "852", // 0.85156 218 / 256. ! 255: "856", // 0.85547 219 / 256. ! 256: "859", // 0.85938 220 / 256. ! 257: "863", // 0.86328 221 / 256. ! 258: "867", // 0.86719 222 / 256. ! 259: "871", // 0.87109 223 / 256. ! 260: "875", // 0.87500 224 / 256. ! 261: "879", // 0.87891 225 / 256. ! 262: "883", // 0.88281 226 / 256. ! 263: "887", // 0.88672 227 / 256. ! 264: "891", // 0.89063 228 / 256. ! 265: "895", // 0.89453 229 / 256. ! 266: "898", // 0.89844 230 / 256. ! 267: "902", // 0.90234 231 / 256. ! 268: "906", // 0.90625 232 / 256. ! 269: "910", // 0.91016 233 / 256. ! 270: "914", // 0.91406 234 / 256. ! 271: "918", // 0.91797 235 / 256. ! 272: "922", // 0.92188 236 / 256. ! 273: "926", // 0.92578 237 / 256. ! 274: "930", // 0.92969 238 / 256. ! 275: "934", // 0.93359 239 / 256. ! 276: "938", // 0.93750 240 / 256. ! 277: "941", // 0.94141 241 / 256. ! 278: "945", // 0.94531 242 / 256. ! 279: "949", // 0.94922 243 / 256. ! 280: "953", // 0.95313 244 / 256. ! 281: "957", // 0.95703 245 / 256. ! 282: "961", // 0.96094 246 / 256. ! 283: "965", // 0.96484 247 / 256. ! 284: "969", // 0.96875 248 / 256. ! 285: "973", // 0.97266 249 / 256. ! 286: "977", // 0.97656 250 / 256. ! 287: "980", // 0.98047 251 / 256. ! 288: "984", // 0.98438 252 / 256. ! 289: "988", // 0.98828 253 / 256. ! 290: "992", // 0.99219 254 / 256. ! 291: "996" // 0.99609 255 / 256. ! 292: }; ! 293: ! 294: #define LOCAL_BUFFER_SIZE 64 ! 295: ! 296: ! 297: //-------------------------------------------------------------------------- ! 298: // BOOL PrintString(pdev, psz) ! 299: // PDEVDATA pdev; ! 300: // PSZ psz; ! 301: // ! 302: // This routine takes cNumbers of decimal numbers and outputs them to ! 303: // the printers, with a space following each number. ! 304: // ! 305: // Parameters: ! 306: // pdev: ! 307: // pointer to DEVDATA structure. ! 308: // ! 309: // cNumbers: ! 310: // count of decimal numbers to output. ! 311: // ! 312: // iStack: ! 313: // place holder for parameters on stack. ! 314: // ! 315: // Returns: ! 316: // This function returns TRUE if the numbers were sent out, else FALSE. ! 317: // ! 318: // History: ! 319: // 08-Nov-1991 -by- Kent Settle (kentse) ! 320: // Wrote it. ! 321: //-------------------------------------------------------------------------- ! 322: ! 323: BOOL PrintString(pdev, psz) ! 324: PDEVDATA pdev; ! 325: PSZ psz; ! 326: { ! 327: // simply send the string to the printer. yes, we want strlen bytes ! 328: // passed to bPSWrite. we don't want the NULL terminator. ! 329: ! 330: return(bPSWrite(pdev, psz, strlen(psz))); ! 331: } ! 332: ! 333: ! 334: //-------------------------------------------------------------------------- ! 335: // BOOL PrintDecimal(pdev, cNumbers, ...) ! 336: // PDEVDATA pdev; ! 337: // DWORD cNumbers; ! 338: // ! 339: // This routine takes cNumbers of decimal numbers and outputs them to ! 340: // the printers, with a space following each number. ! 341: // ! 342: // Parameters: ! 343: // pdev: ! 344: // pointer to DEVDATA structure. ! 345: // ! 346: // cNumbers: ! 347: // count of decimal numbers to output. ! 348: // ! 349: // iStack: ! 350: // place holder for parameters on stack. ! 351: // ! 352: // Returns: ! 353: // This function returns TRUE if the numbers were sent out, else FALSE. ! 354: // ! 355: // History: ! 356: // 08-Nov-1991 -by- Kent Settle (kentse) ! 357: // Wrote it. ! 358: //-------------------------------------------------------------------------- ! 359: ! 360: BOOL PrintDecimal( ! 361: PDEVDATA pdev, ! 362: DWORD cNumbers, ! 363: ... ! 364: ) ! 365: { ! 366: CHAR Buffer[LOCAL_BUFFER_SIZE]; ! 367: CHAR *pBuffer; ! 368: DWORD cb = 0; ! 369: DWORD cbTotal = 0; ! 370: LONG lNum; ! 371: va_list pvarg; ! 372: ! 373: // initialize some pointers. ! 374: ! 375: pBuffer = Buffer; ! 376: va_start(pvarg, cNumbers); ! 377: ! 378: while (cNumbers--) ! 379: { ! 380: // get the next decimal number from the stack, convert it to ! 381: // ASCII and put it into the output buffer. ! 382: ! 383: lNum = va_arg(pvarg, LONG); ! 384: itoa(lNum, pBuffer, 10); ! 385: ! 386: // how many characters, excluding the NULL terminator, did we place ! 387: // into the output buffer. ! 388: ! 389: cb = strlen(pBuffer); ! 390: if ((cbTotal + cb) >= (LOCAL_BUFFER_SIZE - 1)) ! 391: { ! 392: RIP("PSCRIPT!PrintDecimal: overran the output buffer.\n"); ! 393: SetLastError(ERROR_BUFFER_OVERFLOW); ! 394: return(FALSE); ! 395: } ! 396: ! 397: // update the buffer pointer. ! 398: ! 399: pBuffer += cb; ! 400: ! 401: // output the trailing space. ! 402: ! 403: if (cNumbers >= 1) ! 404: { ! 405: *pBuffer++ = ' '; // overwrites NULL terminator from itoa. ! 406: cb++; ! 407: } ! 408: ! 409: // update the total bytes to buffer counter. ! 410: ! 411: cbTotal += cb; ! 412: } ! 413: ! 414: // we have now build the entire string in our local output buffer. ! 415: // send it out to the printer. ! 416: ! 417: return(bPSWrite(pdev, Buffer, cbTotal)); ! 418: } ! 419: ! 420: ! 421: //-------------------------------------------------------------------------- ! 422: // BOOL PrintPSFIX(pdev, cNumbers, iStack) ! 423: // PDEVDATA pdev; ! 424: // DWORD cNumbers; ! 425: // DWORD iStack; ! 426: // ! 427: // This routine takes cNumbers of PS_FIX numbers and outputs them to ! 428: // the printers, with a space following each number. ! 429: // ! 430: // Parameters: ! 431: // pdev: ! 432: // pointer to DEVDATA structure. ! 433: // ! 434: // cNumbers: ! 435: // count of PS_FIX numbers to output. ! 436: // ! 437: // iStack: ! 438: // place holder for parameters on stack. ! 439: // ! 440: // Returns: ! 441: // This function returns TRUE if the numbers were sent out, else FALSE. ! 442: // ! 443: // History: ! 444: // 08-Nov-1991 -by- Kent Settle (kentse) ! 445: // Wrote it. ! 446: //-------------------------------------------------------------------------- ! 447: ! 448: BOOL PrintPSFIX( ! 449: PDEVDATA pdev, ! 450: DWORD cNumbers, ! 451: ... ! 452: ) ! 453: { ! 454: CHAR Buffer[LOCAL_BUFFER_SIZE]; ! 455: CHAR *pBuffer; ! 456: PS_FIX psfxNum; ! 457: DWORD cb = 0; ! 458: DWORD cbTotal = 0; ! 459: va_list pvarg; ! 460: ! 461: // initialize some pointers. ! 462: ! 463: pBuffer = Buffer; ! 464: va_start(pvarg, cNumbers); ! 465: ! 466: while (cNumbers--) ! 467: { ! 468: // get the next PS_FIX number from the stack. ! 469: ! 470: psfxNum = (PS_FIX)va_arg(pvarg, LONG); ! 471: ! 472: cb = PSFIXToBuffer(pBuffer, psfxNum); ! 473: ! 474: pBuffer += cb; ! 475: ! 476: // output the trailing space if not last number in array. ! 477: ! 478: if (cNumbers >= 1) ! 479: { ! 480: *pBuffer++ = ' '; // overwrites NULL terminator from strcpy. ! 481: cb++; ! 482: } ! 483: ! 484: cbTotal += cb; ! 485: if (cbTotal >= (LOCAL_BUFFER_SIZE - 1)) ! 486: { ! 487: RIP("PSCRIPT!PrintPSFIX: overran the output buffer.\n"); ! 488: SetLastError(ERROR_BUFFER_OVERFLOW); ! 489: return(FALSE); ! 490: } ! 491: } ! 492: ! 493: // we have now built the entire string in our local output buffer. ! 494: // send it out to the printer. ! 495: ! 496: return(bPSWrite(pdev, Buffer, cbTotal)); ! 497: } ! 498: ! 499: ! 500: //-------------------------------------------------------------------------- ! 501: // BOOL bPSWrite(pdev, pbSrc, ulCount) ! 502: // PDEVDATA pdev; ! 503: // PBYTE pbSrc; // pointer to source to write to channel. ! 504: // ULONG ulCount; // length of pbSrc. ! 505: // ! 506: // This routine writes to the output buffer. When the output buffer ! 507: // becomes full, or the channel is closed, the buffer is flushed to the ! 508: // output channel. ! 509: // ! 510: // Parameters: ! 511: // pdev: ! 512: // pointer to DEVDATA structure. ! 513: // ! 514: // pbSrc: ! 515: // pointer to source, which gets written to the output buffer. ! 516: // ! 517: // ulCount: ! 518: // number of bytes in bpSrc. ! 519: // ! 520: // Returns: ! 521: // This function returns TRUE if the channel was successfully closed, ! 522: // FALSE otherwise. ! 523: // ! 524: // History: ! 525: // 20-Nov-1990 -by- Kent Settle (kentse) ! 526: // Wrote it. ! 527: //-------------------------------------------------------------------------- ! 528: ! 529: BOOL bPSWrite(pdev, pbSrc, ulCount) ! 530: PDEVDATA pdev; ! 531: PBYTE pbSrc; // pointer to source to write to channel. ! 532: ULONG ulCount; // length of pbSrc. ! 533: { ! 534: ULONG ulFree; // free space in buffer. ! 535: PBYTE pbDst, pbSource; ! 536: ! 537: // output nothing if the document has been cancelled. ! 538: ! 539: if (pdev->dwFlags & PDEV_CANCELDOC) ! 540: return(TRUE); ! 541: ! 542: // output nothing if a startdoc call has not been issued. ! 543: ! 544: if (!(pdev->dwFlags & PDEV_STARTDOC)) ! 545: return(TRUE); ! 546: ! 547: // get a local source pointer to munge with. ! 548: ! 549: pbSource = pbSrc; ! 550: ! 551: // output our header if it has not yet been done. ! 552: ! 553: bOutputHeader(pdev); ! 554: ! 555: while(ulCount > 0) ! 556: { ! 557: // get a local pointer to the current position in the buffer. ! 558: ! 559: pbDst = ((PBYTE)pdev->ioChannel.pBuffer) + pdev->ioChannel.ulBufCount; ! 560: ! 561: // get the current number of free bytes in the output buffer. ! 562: ! 563: ulFree = OUTPUT_BUFFER_SIZE - pdev->ioChannel.ulBufCount; ! 564: ! 565: // if the entire source will fit into the buffer, put it there. ! 566: ! 567: if (ulCount < ulFree) ! 568: { ! 569: // update the buffer counter. ! 570: ! 571: pdev->ioChannel.ulBufCount += ulCount; ! 572: ! 573: memcpy(pbDst, pbSource, ulCount); ! 574: ! 575: return(TRUE); ! 576: } ! 577: else ! 578: { ! 579: ! 580: // control comes here if the source will not fit into the ! 581: // buffer. copy ulFree bytes into the buffer, flush the ! 582: // buffer, and try again. ! 583: ! 584: ulCount -= ulFree; ! 585: ! 586: memcpy(pbDst, pbSource, ulFree); ! 587: ! 588: // update the source pointer. ! 589: ! 590: pbSource += ulFree; ! 591: ! 592: // set the buffer position holder to the end of the buffer. ! 593: ! 594: pdev->ioChannel.ulBufCount = OUTPUT_BUFFER_SIZE; ! 595: ! 596: // flush the buffer to the output channel. ulBufCount ! 597: // get reset to zero by bPSFlush. ! 598: ! 599: bPSFlush(pdev); ! 600: } ! 601: } ! 602: ! 603: return(TRUE); ! 604: } ! 605: ! 606: ! 607: //-------------------------------------------------------------------------- ! 608: // BOOL bPSFlush(pdev) ! 609: // PDEVDATA pdev; ! 610: // ! 611: // This routine flushes the output buffer to the output channel. ! 612: // ! 613: // Parameters: ! 614: // pdev: ! 615: // pointer to DEVDATA structure. ! 616: // ! 617: // Returns: ! 618: // This function returns TRUE if the buffer was successfully flushed, ! 619: // FALSE otherwise. ! 620: // ! 621: // History: ! 622: // 21-Nov-1990 -by- Kent Settle (kentse) ! 623: // Wrote it. ! 624: //-------------------------------------------------------------------------- ! 625: ! 626: BOOL bPSFlush(pdev) ! 627: PDEVDATA pdev; ! 628: { ! 629: DWORD cWritten; ! 630: ! 631: while (pdev->ioChannel.ulBufCount && ! 632: !(pdev->dwFlags & PDEV_CANCELDOC)) ! 633: { ! 634: if (!WritePrinter(pdev->hPrinter, pdev->ioChannel.pBuffer, ! 635: pdev->ioChannel.ulBufCount, &cWritten)) ! 636: { ! 637: DbgPrint("bPSFlush: WritePrinter failed, will not call again.\n"); ! 638: pdev->dwFlags |= PDEV_CANCELDOC; ! 639: ! 640: } ! 641: else ! 642: pdev->ioChannel.ulBufCount -= cWritten; ! 643: } ! 644: ! 645: if (pdev->dwFlags & PDEV_CANCELDOC) ! 646: { ! 647: pdev->ioChannel.ulBufCount = 0; ! 648: return TRUE; ! 649: } ! 650: ! 651: return(TRUE); ! 652: } ! 653: ! 654: ! 655: //-------------------------------------------------------------------------- ! 656: // VOID vHexOut(pdev, pbSrc, nbSrc) ! 657: // PDEVDATA pdev; // pointer to the DC instance ! 658: // PBYTE pbSrc; // pointer to the output buffer to send ! 659: // LONG nbSrc; // Size of the output buffer ! 660: // ! 661: // This routine converts a byte string to hexadecimal and sends the ! 662: // result to the output channel. ! 663: // ! 664: // Parameters: ! 665: // pdev: ! 666: // pointer to DEVDATA structure. ! 667: // ! 668: // pbSrc: ! 669: // pointer to byte string. ! 670: // ! 671: // nbSrc: ! 672: // number of bytes in string. ! 673: // ! 674: // Returns: ! 675: // This function returns no value. ! 676: // ! 677: // History: ! 678: // Wed Dec 26, 1990 -by- Kent Settle (kentse) ! 679: // Wrote it. ! 680: //-------------------------------------------------------------------------- ! 681: ! 682: VOID vHexOut(pdev, pbSrc, nbSrc) ! 683: PDEVDATA pdev; // pointer to the DC instance ! 684: PBYTE pbSrc; // pointer to the output buffer to send ! 685: LONG nbSrc; // Size of the output buffer ! 686: { ! 687: register LONG nwFree; // Number of 16 bit words available ! 688: register PBYTE pbDst, pbSource; ! 689: int b1, b2; ! 690: BOOL bFitsInBuffer; ! 691: ! 692: // output nothing if the document has been cancelled. ! 693: ! 694: if (pdev->dwFlags & PDEV_CANCELDOC) ! 695: return; ! 696: ! 697: // output nothing if a startdoc call has not been issued. ! 698: ! 699: if (!(pdev->dwFlags & PDEV_STARTDOC)) ! 700: return; ! 701: ! 702: // get a local source pointer to munge with. ! 703: ! 704: pbSource = pbSrc; ! 705: ! 706: // output our header if it has not yet been done. ! 707: ! 708: bOutputHeader(pdev); ! 709: ! 710: // Loop once for each byte and stuff each byte into the output ! 711: // buffer. When the buffer becomes full, call FlushChannel to ! 712: // empty it. ! 713: ! 714: while (nbSrc > 0) ! 715: { ! 716: // get a pointer to the current location within the output buffer. ! 717: // then calculate how many WORDS are free in the output buffer. ! 718: ! 719: pbDst = ((PBYTE)pdev->ioChannel.pBuffer) + pdev->ioChannel.ulBufCount; ! 720: nwFree = ((OUTPUT_BUFFER_SIZE - 1) - pdev->ioChannel.ulBufCount) >> 1; ! 721: ! 722: // we will be converting one source byte into two destination ! 723: // bytes, so it is proper to compare the number of source bytes ! 724: // with the number of destination words. ! 725: ! 726: bFitsInBuffer = FALSE; ! 727: ! 728: if (nbSrc < nwFree) ! 729: { ! 730: nwFree = nbSrc; ! 731: bFitsInBuffer = TRUE; ! 732: } ! 733: ! 734: nbSrc -= nwFree; ! 735: pdev->ioChannel.ulBufCount += (nwFree << 1); ! 736: ! 737: while (nwFree-- > 0) ! 738: { ! 739: // Get a byte and convert it to two hex digits ! 740: ! 741: b1 = *pbSource++; ! 742: b2 = (b1 >> 4) & 0x0f; ! 743: b1 &= 0x0f; ! 744: ! 745: //!!! during the code review it was suggested to use itoa here. ! 746: //!!! is that really worth doing??? - kentse. ! 747: ! 748: if (b2 >= 10) ! 749: b2 += ('A' - 10); ! 750: else ! 751: b2 += '0'; ! 752: ! 753: if (b1 >= 10) ! 754: b1 += ('A' - 10); ! 755: else ! 756: b1 += '0'; ! 757: ! 758: *pbDst++ = (CHAR)b2; ! 759: *pbDst++ = (CHAR)b1; ! 760: } ! 761: ! 762: // flush the buffer when it is full. ! 763: ! 764: if (!bFitsInBuffer) ! 765: bPSFlush(pdev); ! 766: } ! 767: } ! 768: ! 769: // These two routines support four cases for Bitmaps: ! 770: // ! 771: // DataType Form ! 772: // -----------|------------- ! 773: // 0 | Unpacked binary data - level1 ! 774: // 1 | Unpacked hex data - level1 ! 775: // 2 | Packed binary data( RLE only) - level2 ! 776: // 3 | Packed ascii85 data(RLE + ascii85) - level2 ! 777: SHORT PSBitMapType(PDEVDATA pdev, BOOL BinaryClearChannel) ! 778: { ! 779: ! 780: if(!BinaryClearChannel) ! 781: { ! 782: if(pdev->pntpd->LangLevel == 2) ! 783: { ! 784: if (pdev->pntpd->flFlags & BCP_PROTOCOL) ! 785: return(3); ! 786: else ! 787: return(1); ! 788: } ! 789: else ! 790: return(1); ! 791: } ! 792: else ! 793: { ! 794: if(pdev->pntpd->LangLevel == 2) ! 795: { ! 796: if (pdev->pntpd->flFlags & TBCP_PROTOCOL) ! 797: return(2); ! 798: else ! 799: return(0); ! 800: } ! 801: else ! 802: return(0); ! 803: } ! 804: } ! 805: ! 806: ! 807: //-------------------------------------------------------------------------- ! 808: // DWORD PSFIXToBuffer(pbuffer, psfx) ! 809: // CHAR *pbuffer; ! 810: // PS_FIX psfx; ! 811: // ! 812: // This routine takes a PS_FIX (24.8) number and outputs its ASCII ! 813: // equivalent to pbuffer. ! 814: // ! 815: // Parameters: ! 816: // pbuffer: ! 817: // pointer to output buffer. ! 818: // ! 819: // psfx: ! 820: // PS_FIX number. ! 821: // ! 822: // Returns: ! 823: // This function returns number of BYTES written to pbuffer. ! 824: // ! 825: // History: ! 826: // 07-May-1993 -by- Kent Settle (kentse) ! 827: // broke out of PrintPSFIX. ! 828: //-------------------------------------------------------------------------- ! 829: ! 830: DWORD PSFIXToBuffer(pbuffer, psfx) ! 831: CHAR *pbuffer; ! 832: PS_FIX psfx; ! 833: { ! 834: DWORD cb; ! 835: BOOL bNegative; ! 836: LONG lNum; ! 837: PSZ pszFrac; ! 838: ! 839: // handle negative numbers. ! 840: ! 841: bNegative = FALSE; ! 842: ! 843: if (psfx < 0) ! 844: { ! 845: psfx *= -1; ! 846: *pbuffer++ = '-'; ! 847: bNegative = TRUE; ! 848: } ! 849: ! 850: // grab the integer portion of the number, convert it to ASCII ! 851: // and put it into the output buffer. ! 852: ! 853: lNum = PSFXTOL(psfx); ! 854: itoa(lNum, pbuffer, 10); ! 855: ! 856: // how many characters, excluding the NULL terminator, did we place ! 857: // into the output buffer. ! 858: ! 859: if (bNegative) ! 860: pbuffer--; ! 861: cb = strlen(pbuffer); ! 862: ! 863: // update the buffer pointer. ! 864: ! 865: pbuffer += cb; ! 866: ! 867: // now see if we have a fractional portion of the number to ! 868: // worry about. ! 869: ! 870: lNum = (psfx & PS_FIX_MASK); ! 871: pszFrac = Fracs[lNum]; ! 872: ! 873: // output a decimal point if we have a non-zero fraction, otherwise ! 874: // output the trailing space. ! 875: ! 876: if (*pszFrac) ! 877: *pbuffer++ = '.'; // overwrites NULL terminator from itoa. ! 878: else ! 879: return(cb); // we are done. ! 880: ! 881: // account for the decimal point. ! 882: ! 883: cb++; ! 884: ! 885: // output the fractional portion number of the if there is one. ! 886: ! 887: // copy the fractional number to the output buffer. ! 888: ! 889: strcpy(pbuffer, pszFrac); ! 890: ! 891: // how many characters, excluding the NULL terminator, did we place ! 892: // into the output buffer. ! 893: ! 894: cb += strlen(pszFrac); ! 895: ! 896: return(cb); ! 897: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.