PrinterDef.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /************************************************************************/
  2. /* Copyright (C), 2016-2020, [Jeff], 保留所有权利;
  3. /* 模 块 名:;
  4. /* 描 述:;
  5. /*
  6. /* 版 本:[V];
  7. /* 作 者:[Jeff];
  8. /* 日 期:[3/17/2017];
  9. /*
  10. /*
  11. /* 注 意:;
  12. /*
  13. /* 修改记录:[Jeff];
  14. /* 修改日期:;
  15. /* 修改版本:;
  16. /* 修改内容:;
  17. /************************************************************************/
  18. #ifndef __PRINTER_DEF__
  19. #define __PRINTER_DEF__
  20. #pragma once
  21. #include "..\..\..\common\Base64\Base64.h"
  22. #include "..\..\..\common\cJson\cJSON.h"
  23. #include <string>
  24. #include <vector>
  25. using namespace std;
  26. #ifdef _UNICODE
  27. typedef wstring TString;
  28. #else
  29. typedef string TString;
  30. #endif
  31. #include <gdiplus.h>
  32. using namespace Gdiplus;
  33. #pragma comment(lib, "gdiplus.lib")
  34. #define AlignNormal 0 // 正常对齐方式;
  35. #define AlignHCenter 1 // 水平居中;
  36. #define AlignVCenter 2 // 垂直居中;
  37. #define AlignTopRight 4 // 向右上角对齐;
  38. #define AlignTopLeft 8 // 向左上角对齐;
  39. #define AlignBottomRight 16 // 向右下角对齐;
  40. #define AlignBottomLeft 32 // 向左下角对齐;
  41. #define AlignHVCenter 64 // 向左下角对齐;
  42. // 打印图元结构;
  43. typedef struct __PRINTCELL__
  44. {
  45. // 图元名称;
  46. TString strCellName;
  47. // 图元key名;
  48. TString strCellKey;
  49. // 图元边距值;
  50. INT nCellMargins;
  51. // 图元打印位置;
  52. INT top;
  53. INT left;
  54. INT right;
  55. INT bottom;
  56. // 图元原始位置;
  57. CRect rcOrg;
  58. // 图元变化位置;
  59. CRect rcChg;
  60. // 是否自动换行;
  61. BOOL bAutoWraps;
  62. // 是否已经自动换行;
  63. BOOL bHasWrapped;
  64. // 图元top\left\right\bottom边样式:0=透明、1=虚线、2=实线;
  65. INT nTopLineType;
  66. INT nLeftLineType;
  67. INT nRightLineType;
  68. INT nBottomLineType;
  69. // 图元边线宽;
  70. INT nLineWide;
  71. // 图元填充内容:0=文本,1=图片;
  72. INT nFillerType;
  73. // 文本内容;
  74. TString strTextContent;
  75. // 文本的字体名;
  76. TString strTextFontName;
  77. // 文本的字体大小(号);
  78. INT nTextFontSize;
  79. // 文本颜色;
  80. COLORREF clrText;
  81. // 文本对齐方式:0 = 默认左对齐, 1 = 居中对齐,2 =右对齐;
  82. INT nTextAlignType;
  83. // 文本行间距;
  84. INT nLineSpacing;
  85. // 文本是否粗体;
  86. BOOL bTextBold;
  87. // 文本是否斜体;
  88. BOOL bTextItalic;
  89. // 如果文本在图元区域内不能一行显示完全,则需要换行;
  90. vector<TString> vtSubText;
  91. // 图片描述;
  92. TString strImgName;
  93. // 图片内容,由文件流转成Base64的字符串;
  94. TString strImgContent;
  95. // 图元是否在换页时,只画了一部分区域边框;
  96. BOOL bDrawHalf;
  97. // 是否被上下衔接过;
  98. BOOL bTypesetting;
  99. __PRINTCELL__()
  100. {
  101. strCellName = _T("");
  102. strCellKey = _T("");
  103. nCellMargins = 0;
  104. top = 0;
  105. left = 0;
  106. right = 0;
  107. bottom = 0;
  108. rcOrg.SetRect(0, 0, 0, 0);
  109. rcChg.SetRect(0, 0, 0, 0);
  110. bAutoWraps = FALSE;
  111. bHasWrapped = FALSE;
  112. nTopLineType = 0;
  113. nBottomLineType = 0;
  114. nLeftLineType = 0;
  115. nRightLineType = 0;
  116. nLineWide = 0;
  117. nFillerType = 0;
  118. strTextContent = _T("");
  119. strTextFontName = _T("");
  120. nTextFontSize = 0;
  121. clrText = 0;
  122. nTextAlignType = 0;
  123. nLineSpacing = 0;
  124. bTextBold = FALSE;
  125. bTextItalic = FALSE;
  126. strImgName = _T("");
  127. strImgContent = _T("");
  128. bDrawHalf = FALSE;
  129. bTypesetting = FALSE;
  130. }
  131. }STPrintCell, *pSTPrintCell;
  132. typedef struct __KEY_VALUE__
  133. {
  134. TString strName;
  135. TString strKey;
  136. TString strTextValue;
  137. TString strImgValue;
  138. }KeyValue, *pKeyValue;
  139. // 打印列表;
  140. typedef struct __PRINTLIST__
  141. {
  142. CRect rcPage; // rcPage.bottom是换行或换页的坐标y值;
  143. BOOL bShowFrame;
  144. INT nLineWide;
  145. TString strPrinterName;
  146. vector<STPrintCell> vtPrintCell;
  147. }PrintList, *pPrintList;
  148. extern BOOL GIsHalfHZ(const CStringA &str);
  149. extern BOOL IsHalfChineseWord(IN LPCCH lpText);
  150. // 加载模板;
  151. extern BOOL LoadTemplateFromJson(IN PrintList &printlist, IN TString strTemplateJson);
  152. extern BOOL LoadTemplateFromFile(IN PrintList &printlist, IN TString strTemplateFile);
  153. // 加载键值;
  154. extern BOOL LoadValuesFromJson(IN PrintList& printlist, IN TString strValuesJson);
  155. extern BOOL LoadValuesFromFile(IN PrintList& printlist, IN TString strValuesFile);
  156. // 保存Json;
  157. extern void SaveJson(IN PrintList &printlist, IN TString strSavePath, IN BOOL bChange = FALSE);
  158. extern void SaveJson(IN PrintList &printlist, IN TString strSavePath, IN const double lfValues);
  159. extern void GetImgBufferFromBase64(IN TString strBase64, IN BYTE **pBuffer, IN DWORD& dwBufferLen);
  160. extern BOOL LoadImgFromBuffer(IN Image** pImg, IN BYTE* pBuffer, IN CONST INT& nBufLen);
  161. extern int GetEncoderClsid(IN CONST WCHAR* format, OUT CLSID* pClsid);
  162. extern BOOL SaveImg2newfile(IN Image* pImg, IN CString strNewfile, IN ULONG uQuality);
  163. extern BOOL SaveImg2newfile(IN Image* pImg, IN TString strNewfile, IN ULONG uQuality);
  164. #endif//__PRINTER_DEF__