//将源数据按指定的宽高分割成小方格图片,以每个图片为单位,返回光栅数据 private static byte[] TAC_CutToGridAndTurnToByte(byte[][] orgData, int nPerHeight, int nPerWidth, int nLines, int nClos) { //测试时为bFontWidth = 24,bFontHeight = 24,bLines = 12, bClos = 16; //12行,每行16个汉字 int nHeight = nPerHeight * nLines; int nWidht = nPerWidth * nClos; byte[][] tempGridData = new byte[nPerHeight][]; for (int i = 0; i < nPerHeight; i++) { tempGridData[i] = new byte[nPerWidth]; } int nPerGridByte = ((nPerWidth + 7) / 8) * nPerHeight; byte[] bWordsByte = new byte[nPerGridByte * nLines * nClos]; int k = 0; for (int i = 0; i < nHeight; i += nPerHeight) { for (int j = 0; j < nWidht; j += nPerWidth) { CACULATE.CACU_CutToData(orgData, i, j, tempGridData);//已经获得光栅的点阵数据了 TAC_TurnBitToByte(tempGridData).CopyTo(bWordsByte, k); k += nPerGridByte; } } return(bWordsByte); }
//完成最后一系列工作,并把缓冲区的内容转成字节数据返回 public static byte[] POS_Print() { if (PrintDirection != 0) { SYS_SetPrintDirection(0); } int nHeight = PageBuffer.Length; int nWidth = PageBuffer[0].Length; int blukHeight = 96; int blukSum = (nHeight + blukHeight - 1) / blukHeight; int byteLength = 8 * blukSum + (nWidth + 7) / 8 * ((nHeight + 7) / 8 * 8); byte[] latestData = new byte[byteLength]; int offset = 0; byte[][] desData; desData = CACULATE.getSampleDesData(blukHeight, nWidth); for (int i = 0; i < nHeight; i = i + blukHeight) { if ((nHeight - i > 0) & (nHeight - i < blukHeight)) { desData = CACULATE.getSampleDesData(nHeight - i, nWidth); } CACULATE.CACU_CutToData(PageBuffer, i, 0, desData); byte[] temp = CACULATE.CACU_PixDataToPrintedCommand(desData, 0); temp.CopyTo(latestData, offset); offset += temp.Length; } return(latestData); }
//向缓冲区输入字符串 //nOrgx和nOrgy表示绝对打印位置 public static bool POS_PL_TextOut(String text, int nOrgx, int nOrgy, int nWidthTimes, int nHeightTimes, int nFontStyle) { byte[][] temp = TEXTANDPIC.TAC_WriteStringToPixel(text, LineSpacing, RightSpacing, LeftPad + PrintAreaWidth - nOrgx); byte[][] temptimes = CACULATE.CACU_TimesData(temp, nHeightTimes + 1, nWidthTimes + 1); CACULATE.CACU_CopyData(temptimes, nOrgy - LineHeight * (nHeightTimes + 1), nOrgx, PageBuffer); return(true); }
private static void TAC_PrintLibrary(String sZikuPath, int nFontHeight, int nFontWidth, int nPerWordByte) { FileStream readFileStream = new FileStream(sZikuPath, FileMode.Open); byte[] wordData = new byte[nPerWordByte]; int nWidth = nFontWidth * 16; int nHeight = (nFontHeight + 4) * 12; byte[][] pageData = new byte[nHeight][]; for (int i = 0; i < nHeight; i++) { pageData[i] = new byte[nWidth]; } for (int i = 0; i < nHeight; i = i + nFontHeight + 4) { for (int j = 0; j < nWidth; j = j + nFontWidth) { readFileStream.Read(wordData, 0, nPerWordByte); CACULATE.CACU_CopyData(TAC_TurnFontDataToBit(wordData, nFontHeight, nFontWidth), i, j, pageData); } } COMMUNICATION.CMNCT_Send(CACULATE.CACU_PixDataToPrintedCommand(pageData, 0)); }
public static bool POS_PL_PrintBmpInRAM(int nID, int nOrgx, int nOrgy, int nMode) { nOrgy -= bmpBuffer.Length; CACULATE.CACU_CopyData(bmpBuffer, nOrgy, nOrgx, PageBuffer); return(true); }
public static bool POS_PL_DownloadAndPrintBmp(string pszPath, int nOrgx, int nOrgy, int nMode) { byte[][] temp = TEXTANDPIC.TAC_TurnPicToPixData(pszPath); CACULATE.CACU_CopyData(temp, nOrgy - temp.Length, nOrgx, PageBuffer); return(true); }
//将字符串转成点阵数据。可以设置行间留白,字符右间距,以及页宽。 public static byte[][] TAC_WriteStringToPixel(String sText, int nLineSpacing, int nRightSpacing, int nPageWidth) { //使用24*24的默认字体 int fontHeight = 24; int fontWidth = 24; int fontWidthASCII = 12; int nPerFontBytes = 72; int nPerASCIIBytes = 36; int desWidth = nPageWidth; int desHeight = ((sText.Length * (fontWidth + nRightSpacing) + nPageWidth - 1) / nPageWidth) * (fontHeight + nLineSpacing); byte[][] desData = new byte[desHeight][]; for (int i = 0; i < desHeight; i++) { desData[i] = new byte[desWidth]; } //将sText转成点阵数据返回,nHeight和nWidth为行下间距和字符右间距 FileStream fileStream = new FileStream("GB10830(24x24)_All", FileMode.Open); FileStream fileStreamASCII = new FileStream("(1b0000)base12X24", FileMode.Open); byte[] readBuffer = new byte[nPerFontBytes]; byte[] readBufferASCII = new byte[nPerASCIIBytes]; byte[] GBKBytes = Encoding.Default.GetBytes(sText); int gbkBytesLength = GBKBytes.Length; int ch = 0; int cl = 0; int desY = 0; int desX = 0; for (int i = 0; i < gbkBytesLength; i++) { ch = GBKBytes[i]; if (ch < 128) { if (ch < 20) { continue; } fileStreamASCII.Seek(TAC_GetASCIIFontDataIndex((byte)ch) * nPerASCIIBytes, SeekOrigin.Begin); fileStreamASCII.Read(readBufferASCII, 0, readBufferASCII.Length); if (desX + fontWidthASCII + nRightSpacing > desWidth - 1) { desX = 0; desY = desY + fontHeight + nLineSpacing; } CACULATE.CACU_CopyData(TAC_TurnFontDataToBit(readBufferASCII, 24, 12), desY, desX, desData); desX = desX + fontWidthASCII + nRightSpacing; } else { i++; cl = GBKBytes[i]; fileStream.Seek(TAC_GetIndex((byte)ch, (byte)cl) * nPerFontBytes, SeekOrigin.Begin); fileStream.Read(readBuffer, 0, readBuffer.Length); if (desX + fontWidth + nRightSpacing > desWidth - 1) { desX = 0; desY = desY + fontHeight + nLineSpacing; } CACULATE.CACU_CopyData(TAC_TurnFontDataToBit(readBuffer, 24, 24), desY, desX, desData); desX = desX + fontWidth + nRightSpacing; } } fileStream.Close(); fileStreamASCII.Close(); return(desData); }