Forráskód Böngészése

标签打印机差不多完成了

zhangyang 6 éve
szülő
commit
ccd0aec585

+ 1 - 1
bin/Win32/Debug/lewaimai_pos_windows/skin/setting.xml

@@ -129,7 +129,7 @@
 						<CheckBox name="setting_is_new_waimai_biaoqian_printer" width="72" height="45" normalimage="file='switchbutton.png' source='0,0,143,91'" selectedimage="file='switchbutton.png' source='0,182,143,273'"/>
 					</HorizontalLayout>
 
-					<HorizontalLayout height="44" name="setting_printer_usb_layout">
+					<HorizontalLayout height="44" name="setting_biaoqian_printer_usb_layout">
 						<Label text="标签打印机usb端口选择" width="260"/>
 						<Combo name="setting_biaoqian_printer_usb" padding="0,9,0,0" width="800" height="26" tooltip="请点击这里选择您的标签打印机usb端口" normalimage="file='Setting_Combox_Normal.png' corner='2,2,24,2'" hotimage="file='Setting_Combox_Hover.png' corner='2,2,24,2'" pushedimage="Setting_Combox_Click.png' corner='2,2,24,2'" textpadding="10,1,1,1" >
 						</Combo>

+ 2 - 2
lewaimai_pos_windows/network/CMessagePush.cpp

@@ -488,11 +488,11 @@ void CMessagePush::HandlePrinter()
 				continue;
 			}
 
-			//AddShouyinPrinter(order);
+			AddShouyinPrinter(order);
 
 			AddBiaoqianPrinter(order);
 
-			//AddChufangPrinter(order);
+			AddChufangPrinter(order);
 		}
     }
 

+ 99 - 1
lewaimai_pos_windows/tool/CPosPrinter.cpp

@@ -833,7 +833,16 @@ void CPosPrinter::PrintWaimaiOrderBiaoqian(CWaimaiOrder& order)
 			BIAOQIAN_TEXTOUT(order_num_info, 16, 16, 1, 1);
 
 			//每行最多显示12个汉字,这里要计算一下换行
-			BIAOQIAN_TEXTOUT(CLewaimaiString::UTF8ToANSI(food_name), 16, 80, 1, 2);
+			food_name += CLewaimaiString::UnicodeToUTF8(L" ¥") + food_price;
+			std::vector<std::string> foodNameVector = HandleBiaoqianFoodname(food_name);
+
+			int nRow = 0;
+			for (std::vector<std::string>::iterator it = foodNameVector.begin(); it != foodNameVector.end(); it++)
+			{
+				BIAOQIAN_TEXTOUT(CLewaimaiString::UTF8ToANSI(*it), 16, 60 + 40 * nRow, 1, 2);
+
+				nRow++;
+			}			
 
 			BIAOQIAN_TEXTOUT(order_num, 16, 200, 1, 1);
 
@@ -1752,4 +1761,93 @@ std::string CPosPrinter::HandleFoodTotalPrice(std::string oldprice, int guige)
             return " " + oldprice;
         }
     }
+}
+
+std::vector<std::string> CPosPrinter::HandleBiaoqianFoodname(std::string oldname)
+{
+	std::vector<std::string> newnameArray;
+	int nHanzi, nZimu;
+	CalWord(oldname, nHanzi, nZimu);
+
+	int nWidth = nHanzi * 2 + nZimu;
+
+	//40 *30mmm的标签,宽度最大24
+	int maxWidth = 24;
+
+	if (nWidth <= maxWidth)
+	{
+		//对于nWidth补空格
+		for (int i = 0; i < maxWidth - nWidth; i++)
+		{
+			oldname += " ";
+		}
+
+		newnameArray.push_back(oldname);
+		return newnameArray;
+	}
+
+	//宽度大于15的情况,如果超过了,就要进行换行截取
+	const char* s = oldname.c_str();
+	int nTmp = 0;
+	int nTotal = 0;
+
+	while (*s != '\0')
+	{
+		if (!(*s >= 0 && *s <= 127))
+		{
+			//汉字的情况
+			s++;
+			nTmp++;
+			nTotal++;
+
+			s++;
+			nTmp++;
+			nTotal++;
+		}
+		else
+		{
+			//字母的情况
+			s++;
+			nTmp++;
+			nTotal++;
+		}
+
+		if (nTmp == maxWidth)
+		{
+			//这里开始要换行了
+			string newnameItem;
+			newnameItem.assign(oldname, nTotal - nTmp, nTmp);
+			newnameArray.push_back(newnameItem);
+			nTmp = 0;
+		}
+		else if (nTmp == maxWidth - 1)
+		{
+			//如果是第14个了,判断下一个是不是中文,如果是的话也要换行
+			if (!(*(s + 1) >= 0 && *(s + 1) <= 127))
+			{
+				//下一个是中文,也要换行了,补齐一个空格
+				string newnameItem;
+				newnameItem.assign(oldname, nTotal - nTmp, nTmp);
+				newnameItem += " ";
+				newnameArray.push_back(newnameItem);
+				nTmp = 0;
+			}
+		}
+	}
+
+	if (nTmp > 0)
+	{
+		//处理分隔后的最后一行
+		string newnameItem;
+		newnameItem.assign(oldname, nTotal - nTmp, nTmp);
+
+		for (int i = 0; i < maxWidth - nTmp; i++)
+		{
+			newnameItem += " ";
+		}
+
+		newnameArray.push_back(newnameItem);
+	}
+
+	return newnameArray;
 }

+ 2 - 0
lewaimai_pos_windows/tool/CPosPrinter.h

@@ -80,6 +80,8 @@ private:
 	std::string HandleFoodQuantity(std::string oldquantity, int guige = 1);
 	std::string HandleFoodTotalPrice(std::string oldprice, int guige = 1);
 
+	std::vector<std::string> HandleBiaoqianFoodname(std::string oldname);
+
 private:
 	std::vector<PrinterHandle> m_hPorts;