{"action":"closed","issue":{"url":"https://api.github.com/repos/vszakats/harbour-core/issues/148","labels_url":"https://api.github.com/repos/vszakats/harbour-core/issues/148/labels{/name}","comments_url":"https://api.github.com/repos/vszakats/harbour-core/issues/148/comments","events_url":"https://api.github.com/repos/vszakats/harbour-core/issues/148/events","html_url":"https://github.com/vszakats/harbour-core/issues/148","id":97328289,"number":148,"title":"hbwin: problem with win_tprn.prg","user":{"login":"ujayadev","id":13509143,"avatar_url":"https://avatars.githubusercontent.com/u/13509143?v=3","gravatar_id":"","url":"https://api.github.com/users/ujayadev","html_url":"https://github.com/ujayadev","followers_url":"https://api.github.com/users/ujayadev/followers","following_url":"https://api.github.com/users/ujayadev/following{/other_user}","gists_url":"https://api.github.com/users/ujayadev/gists{/gist_id}","starred_url":"https://api.github.com/users/ujayadev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ujayadev/subscriptions","organizations_url":"https://api.github.com/users/ujayadev/orgs","repos_url":"https://api.github.com/users/ujayadev/repos","events_url":"https://api.github.com/users/ujayadev/events{/privacy}","received_events_url":"https://api.github.com/users/ujayadev/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/vszakats/harbour-core/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/vszakats/harbour-core/labels/confirmed","name":"confirmed","color":"1EAA19"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-07-26T15:40:57Z","updated_at":"2015-07-26T20:28:15Z","closed_at":"2015-07-26T20:28:15Z","body":"Hi Viktor,\r\nPlease go thru the attached program.  When compiled with Harbour 3.2 nightly build it prints correctly, but when compiled with Viktor's fork, the output is all jumbled.\r\n```Harbour\r\n/** definitions for print function **/\r\n\r\n#define CONDENSED CHR(15)\r\n#define NORMAL    CHR(18)\r\n#define DBL_WIDTH CHR(27)+CHR(33)+CHR(32)\r\n#define NORMAL_WIDTH CHR(27)+CHR(33)+CHR(0)\r\n#define NLQ CHR(27)+CHR(69)\r\n#define NLQCANCEL CHR(27)+CHR(70)\r\n#define FORMFEED  CHR(12)\r\n#define ESC       chr(27)\r\n#define DBLWIDTH  CHR(27)+CHR(14)\r\n#define NORMALWIDTH CHR(27)+CHR(20)\r\n#define ESCCONDENSED chr(27)+CHR(15)\r\n#define ESCNORMAL    chr(27)+CHR(18)\r\n#define PRINTINITIALISE  chr(27)+chr(64)  // for tech excel reports\r\n#define LINESPERPAGE   chr(27)+chr(67)+chr(72)    // for tech excel reports\r\n#define DBLSTRIKE  chr(27)+chr(71)\r\n#define DBLSTRIKECANCEL  chr(27)+chr(72)\r\n#define CPI12         chr(27)+chr(77)\r\n#define CONDENSED12 CHR(15)+chr(15)  // condensed mode in 12cpi therefore 20cpi\r\n\r\n\r\n#define NMAX_LINE_LEN 255\r\n\r\n#define FORM_A4 9\r\n#define FORM_LEGAL   5\r\n\r\n#define FORMLENGTH 11.69    // inches\r\n#define FORMWIDTH  8.27     // inches\r\n#define FORMLEFTMARGIN 5.0  // Inches\r\n#define FORMTOPMARGIN 2    // inches\r\n\r\n#define PS_SOLID            0\r\n\r\n#define TA_LEFT     0\r\n#define TA_RIGHT    1\r\n#define TA_CENTER   2\r\n\r\n\r\n#define RGB( nR,nG,nB )   ( nR + ( nG * 256 ) + ( nB * 256 * 256 ) )\r\n\r\n#define BLACK          RGB( 0x0 ,0x0 ,0x0  )\r\n#define BLUE           RGB( 0x0 ,0x0 ,0x85 )\r\n#define GREEN          RGB( 0x0 ,0x85,0x0  )\r\n#define CYAN           RGB( 0x0 ,0x85,0x85 )\r\n#define RED            RGB( 0x85,0x0 ,0x0  )\r\n#define MAGENTA        RGB( 0x85,0x0 ,0x85 )\r\n#define BROWN          RGB( 0x85,0x85,0x0  )\r\n#define WHITE          RGB( 0xC6,0xC6,0xC6 )\r\n\r\nfunction testTxt2Gdi(cFile)\r\n   local fHandle := 0,xPath := space(40), lAllowView := .t.\r\n   local nFontSize := 12\r\n   defaults()\r\n   txt2gdi(cFile)\r\nreturn NIL\r\n\r\nfunction Txt2Gdi(cFile,cPrinter)\r\n   local fHandle := 0\r\n   local nFontSize := 12 , cLine := \"\",nPos := 0\r\n   set date british\r\n   cFile := iif(cFile # NIL, cFile, cFile := space(8))\r\n   if empty(cFile)\r\n      cFile := dGetFile({{\"Text Files\",\"*.txt\"}},\"Enter Text File to Convert:\")\r\n      cFile := alltrim(cFile)\r\n   endif\r\n   popread(.f.,\"Enter FontSize:\",@nFontSize,\"99.99\")\r\n *  cFile := GETSHORTPATHNAME(cFile)\r\n   fHandle := F_Open(cFile)\r\n   if fHandle # 0\r\n      // if formfeed at end for eject, then remove so that a blank page is\r\n      // not made in gdi\r\n      FSeek(fHandle,-1,FS_END)\r\n      FReadLn(fHandle, @cLine, NMAX_LINE_LEN)\r\n      nPos := at(FORMFEED,cLine)\r\n      if nPos != 0\r\n         FSeek(fHandle,-1,FS_END)\r\n         FWrite(fHandle,space(1))\r\n      endif\r\n      fSeek(fHandle,0,FS_SET)\r\n      printFile(fHandle,nFontSize,cPrinter)\r\n      // restore the formfeed character\r\n      if nPos != 0\r\n         FSeek(fHandle,-1,FS_END)\r\n         FWrite(fHandle, FORMFEED)\r\n      endif\r\n      fileClose(fHandle)\r\n   else\r\n      msgbox(cFile+\" \"+\"Not Found\")\r\n   endif\r\nreturn NIL\r\n\r\nstatic function printFile(fHandle,nFontSize,cPrinter)\r\n   local nPrn := 0, aPrn :=  {}, oPrinter\r\n   aPrn := WIN_PRINTERLIST()\r\n\r\n  IF EMPTY(aPrn)\r\n    msgbox(\"No printers installed - Cannot continue\")\r\n    RETURN NIL\r\n ENDIF\r\n if empty(cPrinter)\r\n     nPrn:= mChoice(aPrn) // superlib function, u can use aChoice\r\n     oPrinter := Win_Prn():New(aPrn[nPrn])\r\n  else\r\n     oPrinter := Win_Prn():New(cPrinter)\r\n  endif\r\n  oPrinter:Landscape := .f.\r\n  oPrinter:FormType := FORM_A4\r\n  oPrinter:Copies   := 1\r\n  oPrinter:LeftMargin := FORMLEFTMARGIN\r\n//  oPrinter:TopMargin := 50.8\r\n  IF !oPrinter:Create()\r\n    msgbox(\"Cannot Create Printer\")\r\n  ELSE\r\n    IF !oPrinter:startDoc()\r\n      msgbox(\"StartDoc() failed for Printer \"+cPrinter)\r\n    ELSE\r\n       oPrinter:SetPen(PS_SOLID, 1, BLACK)\r\n       changeFont(NORMAL,oPrinter,nFontSize)\r\n       printGDI(fHandle,oPrinter,nFontSize)\r\n      oPrinter:EndDoc()\r\n    ENDIF\r\n    oPrinter:Destroy()\r\n  ENDIF\r\n  RETURN(NIL)\r\n\r\nstatic function printGDI(fHandle,oPrinter,nFontSize)\r\n   local cLine := \"\", nPos := 0, lStartNewPage := .t., lContinue := .t.\r\n   local i := 0\r\n   *printRuler(oPrinter)\r\n    while lContinue\r\n      lContinue := FReadLn(fHandle, @cLine, NMAX_LINE_LEN)\r\n      if FORMFEED $ cLine // print the line, then start a new page\r\n         nPos := rat(FORMFEED,cLine)\r\n         printLine(substr(cLine,1,nPos-1),oPrinter,nFontSize)\r\n         /* chk if there are more lines in file, if yes, create new page\r\n           else end page\r\n           if fmove2next(fHandle)\r\n             fmove2prior(fHandle) // move back to retain orginal position\r\n             oPrinter:EndPage(lStartNewPage)\r\n           else\r\n             lStartNewPage := .f.\r\n             oPrinter:EndPage(lStartNewPage)\r\n           endif\r\n          */\r\n           oPrinter:EndPage(lStartNewPage)\r\n           oPrinter:NewLine()\r\n           oPrinter:NewLine()\r\n      else\r\n         printLine(cLine,oPrinter,nFontSize)\r\n      endif\r\n  enddo\r\nreturn nIL\r\n\r\nstatic function PrintLine(cLine,oPrinter,nFontSize)\r\n   local xRes := oPrinter:PixelsPerInchX, lNewLine := .t.\r\n   local i := 0, lStartNewPage := .t., nPos := 0\r\n   local nProportion := 98/80\r\n   DO CASE\r\n   CASE alltrim(cLine) == CONDENSED // whole file to be printed in condensed\r\n      changeFont(CONDENSED,oPrinter,nFontSize)\r\n   CASE ESCCONDENSED $ cLine .and. !(NORMAL $ cLine) // only condensed not normal\r\n      if substr(cLine,i,2) = ESCCONDENSED\r\n            changeFont(CONDENSED12,oPrinter,nFontSize)\r\n            i := i +2\r\n      endif\r\n      for i = 3 to len(cLine)\r\n         if !(substr(cLine,i,2) = ESCCONDENSED)\r\n            oPrinter:textoutat(,,substr(cLine,i,1),lNewLine := .f.)\r\n         endif\r\n      next\r\n      oPrinter:NewLine()\r\n      lNewLine := .t.\r\n   CASE !(CONDENSED $ cLine) .and. (NORMAL $ cLine) // only normal not condensed\r\n      changeFont(NORMAL,oPrinter,nFontSize)\r\n   CASE alltrim(cLine) == NORMAL // whole file to be printed in normal\r\n      changeFont(NORMAL,oPrinter,nFontSize)\r\n   CASE chr(13) $ cLine .and. \"_\" $ cLine  // underline\r\n      for i = 1 to len(cLine)\r\n         if !(substr(cLine,i,1) = chr(13) .or. ;\r\n              substr(cLine,i,1) = \"_\")\r\n             // switch on underline if not space\r\n            if substr(cLine,i,1) != space(1)\r\n               oPrinter:UnderLine(.t.)\r\n            endif\r\n            oPrinter:textoutat(,,substr(cLine,i,1),lNewLine := .f.)\r\n            if substr(cLine,i,1) != space(1)\r\n               oPrinter:UnderLine(.f.)\r\n            endif\r\n         endif\r\n      next\r\n      lNewLine := .t.\r\n      oPrinter:NewLine()\r\n   CASE NLQ $ cLine .and. NLQCANCEL $ cLine // change boldnes\r\n      for i = 1 to len(cLine)\r\n         if substr(cLine,i,2) = NLQ\r\n            oPrinter:Bold(600)\r\n            i+= 2\r\n         elseif substr(cLine,i,2) = NLQCANCEL\r\n            oPrinter:Bold(0)\r\n            i+= 2\r\n         endif\r\n         if !(substr(cLine,i,2) = NLQ .Or.;\r\n               substr(cLine,i,2) = NLQCANCEL;\r\n             )\r\n            oPrinter:textoutat(,,substr(cLine,i,1),lNewLine := .f.)\r\n         endif\r\n      next\r\n      oPrinter:NewLine()\r\n      lNewLine := .t.\r\n   CASE DBLSTRIKE $ cLine .and. DBLSTRIKECANCEL $ cLine // change boldnes\r\n      for i = 1 to len(cLine)\r\n         if substr(cLine,i,2) = DBLSTRIKE\r\n            oPrinter:Bold(600)\r\n            i+= 2\r\n         elseif substr(cLine,i,2) = DBLSTRIKECANCEL\r\n            oPrinter:Bold(0)\r\n            i+= 2\r\n         endif\r\n         if !(substr(cLine,i,2) = DBLSTRIKE .Or.;\r\n               substr(cLine,i,2) = DBLSTRIKECANCEL;\r\n             )\r\n            oPrinter:textoutat(,,substr(cLine,i,1),lNewLine := .f.)\r\n         endif\r\n      next\r\n      oPrinter:NewLine()\r\n      lNewLine := .t.\r\n   CASE ESCCONDENSED $ cLine .and. NORMAL $ cLine\r\n      for i = 1 to len(cLine)\r\n         if substr(cLine,i,2) = CPI12 // for tech excel\r\n            changeFont(CPI12,oPrinter,nFontSize)\r\n            i := i +2\r\n         elseif substr(cLine,i,2) = ESCCONDENSED\r\n            changeFont(CONDENSED12,oPrinter,nFontSize)\r\n            i := i +2\r\n         elseif substr(cLine,i,1) = NORMAL\r\n            changeFont(NORMAL,oPrinter,nFontSize)\r\n            ++i\r\n            // carriage retrn in line remove trailing spaces\r\n         elseif substr(cLine,i,1) = CHR(13)\r\n            ++i\r\n            while(substr(cLine,i,1)) = space(1)\r\n               ++i  // increment value of i till space\r\n            end\r\n         endif\r\n         if !(substr(cLine,i,2) = ESCCONDENSED .Or.;\r\n             substr(cLine,i,1) = NORMAL .or.;\r\n             substr(cLine,i,1) = CONDENSED .or.;\r\n             substr(cLine,i,2) = CPI12 .or. ;\r\n             substr(cLine,i,1) = CHR(13))\r\n            oPrinter:textoutat(,,substr(cLine,i,1),lNewLine := .f.)\r\n         endif\r\n         *i--\r\n      next\r\n      oPrinter:NewLine()\r\n      lNewLine := .t.\r\n   CASE CONDENSED $ cLine .and. NORMAL $ cLine\r\n      for i = 1 to len(cLine)\r\n         if substr(cLine,i,1) = CONDENSED\r\n            changeFont(CONDENSED,oPrinter,nFontSize)\r\n         elseif substr(cLine,i,1) = NORMAL\r\n            changeFont(NORMAL,oPrinter,nFontSize)\r\n            // carriage retrn in line remove trailing spaces\r\n         elseif substr(cLine,i,1) = CHR(13)\r\n            ++i\r\n            while(substr(cLine,i,1)) = space(1)\r\n               ++i  // increment value of i till space\r\n            end\r\n         endif\r\n         if !(substr(cLine,i,1) = CONDENSED .Or.;\r\n             substr(cLine,i,1) = NORMAL .or.;\r\n             substr(cLine,i,1) = CHR(13))\r\n            oPrinter:textoutat(,,substr(cLine,i,1),lNewLine := .f.)\r\n         endif\r\n      next\r\n      oPrinter:NewLine()\r\n      lNewLine := .t.\r\n   CASE DBLWIDTH $ cLine .and. NORMALWIDTH $ cLine\r\n      oPrinter:NewLine()\r\n      oPrinter:NewLine()\r\n      for i = 1 to len(cLine)\r\n         if substr(cLine,i,2) = PRINTINITIALISE\r\n            i := i +1        // increment only by 1 as for next loop increases it by another 1\r\n         elseif substr(cLine,i,3) = LINESPERPAGE\r\n            i := i +2\r\n         elseif substr(cLine,i,2) = DBLWIDTH\r\n            changeFont(DBL_WIDTH,oPrinter,20)\r\n            i := i +1\r\n         elseif substr(cLine,i,2) = NORMALWIDTH\r\n            changeFont(NORMAL,oPrinter,nFontSize)\r\n            i := i +1\r\n            // carriage retrn in line remove trailing spaces\r\n         elseif substr(cLine,i,1) = CHR(13)\r\n            ++i\r\n            while(substr(cLine,i,1)) = space(1)\r\n               ++i  // increment value of i till space\r\n            end\r\n         endif\r\n         if !(substr(cLine,i-1,2) = DBLWIDTH .Or.;      // deduct 1 as i is already incremented above\r\n              substr(cLine,i-1,2) = NORMALWIDTH  .or.;\r\n              substr(cLine,i-1,2) = PRINTINITIALISE .or.;\r\n              substr(cLine,i-2,3) = LINESPERPAGE .or.;\r\n             substr(cLine,i-1,1) = CHR(13))\r\n            oPrinter:textoutat(,,substr(cLine,i,1),lNewLine := .f.)\r\n         endif\r\n      next\r\n      oPrinter:NewLine()\r\n      lNewLine := .t.\r\n   CASE DBL_WIDTH $ cLine .and. NORMAL_WIDTH $ cLine\r\n      oPrinter:NewLine()\r\n      oPrinter:NewLine()\r\n      for i = 1 to len(cLine)\r\n         if substr(cLine,i,3) = DBL_WIDTH\r\n            changeFont(DBL_WIDTH,oPrinter,20)\r\n            i := i +3\r\n         elseif substr(cLine,i,3) = NORMAL_WIDTH\r\n            changeFont(NORMAL,oPrinter,nFontSize)\r\n            i := i +3\r\n            // carriage retrn in line remove trailing spaces\r\n         elseif substr(cLine,i,1) = CHR(13)\r\n            ++i\r\n            while(substr(cLine,i,1)) = space(1)\r\n               ++i  // increment value of i till space\r\n            end\r\n         endif\r\n         if !(substr(cLine,i,3) = DBL_WIDTH .Or.;\r\n             substr(cLine,i,3) = NORMAL_WIDTH  .or.;\r\n             substr(cLine,i,1) = CHR(13))\r\n            oPrinter:textoutat(,,substr(cLine,i,1),lNewLine := .f.)\r\n         endif\r\n      next\r\n      oPrinter:NewLine()\r\n      lNewLine := .t.\r\n   CASE ESC $ cLine\r\n      for i = 1 to len(cLine)\r\n         if substr(cLine,i,1) = ESC\r\n            i++\r\n         else\r\n            oPrinter:textoutat(,,substr(cLine,i,1),lNewLine := .f.)\r\n         endif\r\n      next\r\n   OTHERWISE\r\n      *TextOutAt(nPosX,nPosY, cString, lNewLine, lUpdatePosX, nAlignHori, nAlignVert) CLASS WIN32PRN\r\n      oPrinter:textoutat(,,cLine,lNewLine)\r\n   ENDCASE\r\nreturn NIL\r\n\r\nstatic function ChangeFont(cFont,oPrinter,nFontSize)\r\n   local aCondensed := {3, -43}\r\n   nFontSize := iif(nFontSize # NIL, nFontSize,12)\r\n   if nFontSize <= 10.50\r\n      aCondensed := {3,-50}\r\n   endif\r\n   if cFont == CONDENSED\r\n      oPrinter:SetFont('Lucida Console',nFontSize,aCondensed) \r\n   elseif cFont == NORMAL\r\n    oPrinter:SetFont('Lucida Console',nFontSize,0)\r\n   elseif cFont == DBL_WIDTH\r\n      oPrinter:SetFont('Lucida Console',nFontSize,0)\r\n   elseif cFont == CPI12\r\n      oPrinter:SetFont('Lucida Console',nFontSize,{1,12})\r\n   elseif cFont == CONDENSED12\r\n      oPrinter:SetFont('Lucida Console',nFontSize,{3,-60})\r\n   endif\r\nreturn NIL\r\n\r\nstatic FUNCTION FReadLn(fHandle, cBuffer, nMaxLine)\r\n\r\nLOCAL cLine, nEol, nNumRead, nSavePos\r\n\r\n  cLine   := Space(nMaxLine)\r\n  cBuffer := \"\"\r\n\r\n  // Save current file position for later seek\r\n  nSavePos := FTell(fHandle)\r\n\r\n  nNumRead := FRead(fHandle, @cLine, nMaxLine)\r\n\r\n  IF (nEol := At(CRLF, SubStr(cLine, 1, nNumRead))) == 0\r\n    cBuffer := cLine                     // Line overflow or eof\r\n  ELSE\r\n    cBuffer := SubStr(cLine, 1, nEol - 1)  // Copy up to eol\r\n\r\n    // Now position file to next line (skip lf) ...\r\n    FSeek(fHandle, nSavePos + nEol + 1, FS_SET)\r\n\r\n  ENDIF\r\n\r\nRETURN nNumRead != 0        // If last read didn't suceed, eof\r\n\r\nstatic PROCEDURE Fileclose(fHandle)\r\n\r\n  FClose(fhandle)\r\n\r\nRETURN\r\n\r\nfunction PrintRuler(oPrinter)\r\n   local i := 0, j := 0\r\n   oPrinter:NewLine()\r\n   // show tenth division\r\n   for i = 0 to oPrinter:MaxCol()\r\n      if i <= 9\r\n         j := 0\r\n      else\r\n         j := val(substr(str(i,2),1,1))\r\n       endif\r\n      oPrinter:Textoutat(,,ltrim(str(j,4)),.f.)\r\n   next\r\n   oPrinter:NewLine()\r\n   // show subdivision of ruler\r\n   for i = 0 to oPrinter:MaxCol()\r\n      if i <= 9\r\n         j := i\r\n      else\r\n         j := i - val((substr(str(i,2),1,1))+\"0\")\r\n       endif\r\n      oPrinter:Textoutat(,,ltrim(str(j,4)),.f.)\r\n   next\r\n   oPrinter:NewLine()\r\n   return NIL\r\n\r\n/* See function in FileMan.prg\r\n#pragma begindump\r\n\r\n#include <windows.h>\r\n#include \"hbapi.h\"\r\n\r\nHB_FUNC( GETSHORTPATHNAME )\r\n{\r\n  char buffer[ MAX_PATH + 1 ] = {0};\r\n  GetShortPathName( hb_parcx(1), buffer, MAX_PATH );\r\n  hb_retc( buffer );\r\n}\r\n\r\n#pragma enddump\r\n*/\r\n\r\n\r\n/*\r\n    BEGIN SEQUENCE\r\n        IF Empty(cPrinter)\r\n           cPrinter := redirect()\r\n        endif\r\n        DO CASE\r\n        case \"HP\" $ upper(cPrinter) .and. \"JET\" $ upper(cPrinter)\r\n            txt2gdi(cFile,cPrinter)\r\n        case \"HP\" $ upper(cPrinter) .and. \"LASER\" $ upper(cPrinter)\r\n            txt2gdi(cFile,cPrinter)\r\n        case \"PDF\" $ upper(cPrinter)\r\n           txt2gdi(cFile,cPrinter)\r\n        otherwise\r\n           WinPrintRaw( cPrinter,cFile )  // currentprinter in Redirect(), winPrintRaw function in redirect\r\n        endcase\r\n     RECOVER USING oErrorinfo\r\n        //\r\n     END\r\n     */\u001A\r\n```\r\n```\r\n-oTxt2GdiV\r\n\r\nhbwin.hbc\r\nxhb.hbc\r\nSuperlib.hbc\r\n\r\n-a -m -n -w -b\r\n\r\nTxt2gdiV.prg\r\n```"}}