Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect handling of blank lines with NT-5890K #44

Open
Selorax opened this issue Dec 8, 2022 · 1 comment
Open

Incorrect handling of blank lines with NT-5890K #44

Selorax opened this issue Dec 8, 2022 · 1 comment

Comments

@Selorax
Copy link

Selorax commented Dec 8, 2022

I have a thermal printer, which looks exactly as Zjang ZJ-5890K and is probably same same inside.

The line in source https://github.com/klirichek/zj-58/blob/master/rastertozj.c#L119 seems to assume that ESC J n skips 0.176n mm, however, on my printer it skips 0.125n mm, according to documentation and my own measurements.

Also, 0.176 equals 1/144 inches, not 1/44 inches, so the line had a mistype too.

However, for some reason, the printed files had too wide blank intervals, while they were supposed to be too narrow ...

@robog-two
Copy link

Hey, sorry to revive this issue after so long. Hopefully if this is unhelpful to you it could at least solve this for others in the future.

I was able to add a hacky work-around to print blank lines as an image as normal, that still allows the printer to stop printing if there is nothing left to print (rather than stop printing at the end of the selected page size - which is what it does if you simply override line_is_empty)

I'm not great at writing C, and this is actually a guaranteed possible buffer overflow issue if you print a long, completely-blank image, and may break lots of things. So don't do that.

Anyways, I'm too lazy to throw together a PR, especially since it looks like no one is reviewing them anyways, so here's the snippet of code I modified, you can find where it is using the comments at the top

      // lazy output of current raster. First check current line if it is zero.
      // if there were many zeroes and met non-zero - flush zeros by 'feed' cmd
      // if opposite - send non-zero chunk as raster.
      unsigned char *pBuf = pRasterBuf;
      unsigned char *pChunk = pBuf;
      const unsigned char *pEnd = pBuf + iBytesChunk;
      unsigned char zeroArr[65534];
      memset(zeroArr, 0, 65534);
      const unsigned char *pZeroArr;
      pZeroArr = &zeroArr[0];
      int nonzerolines = 0;
      while ( pBuf<pEnd ) {
        if (line_is_empty(pBuf, width_bytes)) {
          if (nonzerolines) { // met zero, need to flush collected raster
            send_raster(pChunk, width_bytes, nonzerolines);
            nonzerolines = 0;
          }
          ++zeroy;
        } else {
          if (zeroy) { // met non-zero, need to feed calculated num of zero lines
            send_raster(pZeroArr, width_bytes, zeroy);
            zeroy=0;
          }
          if (!nonzerolines)
            pChunk = pBuf;
          ++nonzerolines;
        }
        pBuf += width_bytes;
      }
      send_raster(pChunk, width_bytes, nonzerolines);
      //flushBuffer();
    } // loop over page

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants