Disclosure of Invention
The present invention is directed to solving, at least to some extent, one of the technical problems in the related art. Therefore, the invention aims to provide a method and a device for printing by sections of a thermal printer and the thermal printer, which can reduce the printing times and improve the printing efficiency.
The technical scheme adopted by the invention is as follows:
in a first aspect, the present invention provides a method for segmented printing of a thermal printer, the method comprising the steps of:
dividing a heating area of the thermal printer into N sections of sub-areas on average in the transverse direction, wherein the heating area comprises M heating points, and each section of sub-area comprises M/N heating points;
counting the number of points to be heated of each section of the subarea respectively, wherein the number of the points to be heated of each section of the subarea is less than or equal to M/N;
grouping the N sections of sub-regions according to the number of to-be-heated points of each section of sub-region, so that the number of the sub-regions of each group is the largest and the total number of the to-be-heated points of each group is less than or equal to M/N;
and performing heating printing according to the grouping.
Further, the step of regrouping the N segments of sub-regions according to the number of points to be heated of each segment of sub-region, so that the number of sub-regions of each group is the largest and the total number P of points to be heated of each group is not more than M/N, specifically includes:
(1) determining a subregion with the maximum number of points to be heated as a first subregion;
(2) judging whether the number of points to be heated of the first sub-area is smaller than M/N, if not, executing the step (3), otherwise, executing the step (4);
(3) taking each first subregion as a group, and returning to the step (1);
(4) determining the maximum number of points to be heated in the remaining subareas as a second subarea;
(5) judging whether the sum of the number of points to be heated of the first sub-area and the number of points to be heated of the second sub-area is smaller than M/N, if so, executing the step (6), otherwise, executing the step (7), and if the sum is equal to M/N, taking the first sub-area and the second sub-area as a group;
(6) determining the maximum number of points to be heated in the remaining sub-regions as a third sub-region, judging whether the sum of the number of points to be heated of the first sub-region, the number of points to be heated of the second sub-region and the number of points to be heated of the third sub-region is less than M/N, if so, executing a step (8), otherwise, executing a step (9), and if the sum is equal to M/N, enabling the first sub-region, the second sub-region and the third sub-region to be a group;
(7) determining the maximum number of points to be heated in the remaining sub-regions as a third sub-region, judging whether the sum of the number of points to be heated of the first sub-region and the number of points to be heated of the third sub-region is less than M/N, if so, executing the step (10), otherwise, executing the step (11), and if the sum is equal to M/N, taking the first sub-region and the third sub-region as a group;
(8) determining the maximum number of points to be heated in the remaining sub-regions as a fourth sub-region, and judging whether the sum of the number of points to be heated in the first sub-region, the number of points to be heated in the second sub-region, the number of points to be heated in the third sub-region and the number of points to be heated in the fourth sub-region is less than M/N;
(9) determining the maximum number of points to be heated in the remaining sub-regions as a fourth sub-region, and judging whether the sum of the number of points to be heated in the first sub-region, the number of points to be heated in the second sub-region and the number of points to be heated in the fourth sub-region is less than M/N;
(10) determining the maximum number of points to be heated in the remaining sub-regions as a fourth sub-region, and judging whether the sum of the number of points to be heated in the first sub-region, the number of points to be heated in the third sub-region and the number of points to be heated in the fourth sub-region is less than M/N;
(11) determining the maximum number of points to be heated in the remaining sub-regions as a fourth sub-region, and judging whether the sum of the number of points to be heated in the first sub-region and the number of points to be heated in the fourth sub-region is less than M/N;
and iterating until the sum of the number of points to be heated of the X sub-regions is less than or equal to M/N, and the sum of the number of points to be heated of the X +1 sub-regions is greater than M/N, taking the X sub-regions as a group, and finally enabling the number of the sub-regions in each group to be the largest and the total number of the points to be heated of each group to be less than or equal to M/N.
Further, the method further comprises:
and performing descending arrangement on the N sections of sub-regions according to the number of points to be heated to determine the first sub-region, the second sub-region, the third sub-region and the fourth sub-region.
Further, the method further comprises: if all sub-regions have been determined, execution is stopped.
Further, the heating region includes 384 heating points, the N segments of sub-regions are 6 segments of sub-regions, and each segment of sub-region includes 64 heating points.
In a second aspect, the present invention provides a segmented printing apparatus for a thermal printer, the apparatus comprising:
the region dividing module is used for averagely dividing a heating region of the thermal printer into N sections of sub-regions in the transverse direction, wherein the heating region comprises M heating points, and each section of sub-region comprises M/N heating points;
the counting module is used for respectively counting the number of points to be heated of each section of sub-region, wherein the number of the points to be heated of each section of sub-region is less than or equal to M/N;
the grouping module is used for grouping the N sections of sub-regions according to the number of the points to be heated of each section of sub-region, so that the number of the sub-regions of each group is the largest and the total number of the points to be heated of each group is less than or equal to M/N;
and the heating module is used for heating and printing according to the groups.
In a third aspect, the present invention provides a thermal printer, including a thermal print head, a processor, a memory, and a printing program stored in the memory, where the printing program is executable by the processor to control the thermal print head to execute the above-mentioned thermal printer segment printing method.
The invention has the beneficial effects that:
the heating area of the thermal printer is divided into N sections of sub-areas, the number of points to be heated of each section of sub-area is counted respectively, the N sections of sub-areas are grouped according to the number of points to be heated of each section of sub-area, and finally heating printing is carried out according to the grouped groups. The technical problem that the printing efficiency is low due to the fact that few points to be heated are printed in N sections in the prior art is solved, the number of times of printing is reduced through the mode of firstly segmenting, then grouping and finally printing, and the printing efficiency is improved.
Example one
The embodiment provides a segmented printing method of a thermal printer, which comprises the following steps as shown in FIG. 1:
s100, dividing a heating area of the thermal printer into N sections of sub-areas on average in the transverse direction, wherein the heating area comprises M heating points, and each section of sub-area comprises M/N heating points;
s200, counting the number of points to be heated of each segment of sub-region respectively, wherein the number of the points to be heated of each segment of sub-region is less than or equal to M/N;
s300, grouping N sections of sub-regions according to the number of points to be heated of each section of sub-region, so that the number of the sub-regions of each group is the largest, and the total number P of the points to be heated of each group is less than or equal to M/N;
and step S400, heating printing is carried out according to the grouping.
As shown in fig. 2, step S300 specifically includes:
s301, determining a subregion with the maximum number of points to be heated as a first subregion;
step S302, judging whether the number of points to be heated of the first subregion is less than M/N, if not, executing step S303, otherwise, executing step S304;
step S303, taking each first sub-area as a group, and returning to the step S301;
step S304, determining the maximum number of points to be heated in the remaining subareas as a second subarea;
step S305, judging whether the sum of the number of points to be heated of the first sub-area and the number of points to be heated of the second sub-area is smaller than M/N, if so, executing step S306, otherwise, executing step S307, and if the sum is equal to M/N, taking the first sub-area and the second sub-area as a group;
step S306, determining the maximum number of points to be heated in the remaining sub-regions as a third sub-region, judging whether the sum of the number of points to be heated of the first sub-region, the number of points to be heated of the second sub-region and the number of points to be heated of the third sub-region is smaller than M/N, if so, executing step S308, otherwise, executing step S309, and if the sum is equal to M/N, enabling the first sub-region, the second sub-region and the third sub-region to be a group;
step S307, determining the maximum number of points to be heated in the remaining sub-regions as a third sub-region, judging whether the sum of the number of points to be heated in the first sub-region and the number of points to be heated in the third sub-region is less than M/N, if so, executing step S310, otherwise, executing step S311, and if the sum is equal to M/N, taking the first sub-region and the third sub-region as a group;
step S308, determining the maximum number of points to be heated in the remaining sub-regions as a fourth sub-region, and judging whether the sum of the number of points to be heated in the first sub-region, the number of points to be heated in the second sub-region, the number of points to be heated in the third sub-region and the number of points to be heated in the fourth sub-region is less than M/N;
step S309, determining the maximum number of points to be heated in the remaining sub-regions as a fourth sub-region, and judging whether the sum of the number of points to be heated in the first sub-region, the number of points to be heated in the second sub-region and the number of points to be heated in the fourth sub-region is less than M/N;
step S310, determining the maximum number of points to be heated in the remaining sub-areas as a fourth sub-area, and judging whether the sum of the number of points to be heated in the first sub-area, the number of points to be heated in the third sub-area and the number of points to be heated in the fourth sub-area is less than M/N;
step S311, determining the maximum number of points to be heated in the remaining sub-regions as a fourth sub-region, and judging whether the sum of the number of points to be heated in the first sub-region and the number of points to be heated in the fourth sub-region is less than M/N;
and iterating until the sum of the number of points to be heated of the X sub-regions is less than or equal to M/N, and the sum of the number of points to be heated of the X +1 sub-regions is greater than M/N, taking the X sub-regions as a group, and finally enabling the number of the sub-regions in each group to be the largest and the total number of the points to be heated P in each group to be less than or equal to M/N.
As shown in fig. 3, assuming that the heating area of the thermal printer has 384 heating resistors, that is, 384 heating points, after the printer receives data to be printed, the printer controls the heating resistors at the heating points corresponding to the print data to heat, thereby implementing printing. Specifically, referring to fig. 3, the heating area of the thermal printer is divided into 6 segments of sub-areas on average in the transverse direction, and each segment of sub-area includes 384/6 — 64 heating points as an example:
example 1
After the printer receives a line of data to be printed, counting the number of points to be heated of each sub-area to be heated according to the line of data. It can be understood that the number of the points to be heated required to be heated in each sub-region does not exceed 64 points. As shown in fig. 4, the 6-segment sub-regions are respectively marked as a 1-a 6, and the statistical results are: 64 points, 48 points, 10 points, 15 points, 20 points and 30 points.
Then
Step S301, determining the sub-region with the maximum number of points to be heated as a first sub-region, namely A1 as the first sub-region;
step S302, judging whether the number 64 of the points to be heated of the first subregion A1 is less than 64, if not, executing step S303;
step S303, regarding each first sub-region as a group, that is, regarding the first sub-region a1 as a group, returning to step S301, determining that the sub-region with the largest number of points to be heated is the first sub-region, at this time, a2 is the first sub-region, then executing step S302 to determine whether the number 48 of points to be heated of the first sub-region a2 is less than 64, and if so, executing step S304;
step S304, determining the maximum number of points to be heated in the remaining sub-areas as a second sub-area, namely A6 as the second sub-area;
step S305, judging whether the sum of the number 48 of the points to be heated in the first subregion A2 and the number 30 of the points to be heated in the second subregion A6 is less than 64, if not, executing step S307;
step S307, determining the maximum number of the points to be heated in the remaining sub-regions as a third sub-region, namely A5 is the third sub-region, judging whether the sum of the number 48 of the points to be heated in the first sub-region A2 and the number 20 of the points to be heated in the third sub-region A5 is less than 64, if not, executing step S311;
step S311, determining the maximum number of the points to be heated in the remaining sub-regions as a fourth sub-region, that is, a4 is the fourth sub-region, determining whether the sum of the number of the points to be heated 48 in the first sub-region a2 and the number of the points to be heated 15 in the fourth sub-region a4 is less than 64, and if yes, executing the next step;
the next step is as follows: determining the maximum number of points to be heated in the remaining sub-regions as a fifth sub-region, that is, A3 is the fifth sub-region, determining whether the sum of the number 48 of points to be heated of the first sub-region a2, the number 15 of points to be heated of the fourth sub-region A4 and the number 15 of points to be heated of the fifth sub-region A3 is less than 64, if the result is negative, taking the X sub-regions as a group according to the principle that the sum of the number of points to be heated of the X sub-regions is less than or equal to M/N, and the sum of the number of points to be heated of the X +1 sub-regions is greater than M/N, returning to step S301, determining the sub-region with the maximum number of points to be heated as the first sub-region, and then a6 is the first sub-.
With this iteration, referring to fig. 4, the final grouping result is obtained, where the sub-region a1 is the 1 st group (the total number of points to be heated is 64), the sub-regions a2 and a4 are the 2 nd group (the total number of points to be heated is 63), the sub-regions A3, a5 and a6 are the 3 rd group (the total number of points to be heated is 60), and 3 groups are all satisfied, where each group has the largest number of sub-regions and the total number of points to be heated is less than or equal to 64. The printer only needs to heat and print the data according to the grouping result for 3 times, while the traditional method needs 6 times, thus greatly improving the printing efficiency.
Example 2
After the printer receives a line of data to be printed, counting the number of points to be heated of each sub-area to be heated according to the line of data. It can be understood that the number of the points to be heated required to be heated in each sub-region does not exceed 64 points. As shown in fig. 5, the 6-segment sub-regions are respectively marked as B1-B6, and the statistical results are: 64 points, 3 points, 64 points, 5 points, 64 points, 29 points. Then
Step S301, determining that the subregion with the maximum number of points to be heated is a first subregion, namely B1, B3 and B5 are all first subregions;
step S302, judging whether the number 64 of the points to be heated of the first sub-areas B1, B3 and B5 is less than 64, if not, executing the step S303;
step S303, regarding each first sub-region as a group, that is, regarding each first sub-region B1, B3, B5 as a group, returning to step S301, determining that the sub-region with the largest number of points to be heated is the first sub-region, at this time, B6 is the first sub-region, then executing step S302 to determine whether the number 29 of points to be heated of the first sub-region B6 is less than 64, and if yes, executing step S304;
step S304, determining the maximum number of points to be heated in the remaining sub-areas as a second sub-area, namely B4 as the second sub-area;
step S305, judging whether the sum of the number of the to-be-heated dots 29 of the first subregion B6 and the number of the to-be-heated dots 5 of the second subregion B4 is less than 64, and if so, executing step S306;
step S306, determining the largest number of points to be heated in the remaining sub-regions as a third sub-region, that is, B2 is the third sub-region, determining whether the sum of the number of points to be heated 29 of the first sub-region B6, the number of points to be heated 5 of the second sub-region B4, and the number of points to be heated 3 of the third sub-region B2 is less than 64, if so, and at this time, all sub-regions are determined, stopping execution, and using the first sub-region B6, the second sub-region B4, and the third sub-region B2 as a set.
With this iteration, referring to fig. 5, the final grouping result is obtained as: the sub-region B1 is the 1 st group (the total number of points to be heated is 64), the sub-regions B6, B4 and B2 are the 2 nd group (the total number of points to be heated is 37), the sub-region B3 is the 3 rd group (the total number of points to be heated is 64), the sub-region B5 is the 4 th group (the total number of points to be heated is 64), and 4 groups in total all satisfy that the number of sub-regions in each group is the most and the total number of points to be heated in each group is not more than 64. The printer only needs to heat and print the data according to the grouping result for 4 times, while the traditional method needs 6 times, thus greatly improving the printing efficiency.
It is conceivable that, in examples 1 and 2 in the present embodiment, the first sub-region, the second sub-region, the third sub-region, the fourth sub-region, and the fifth sub-region … … may also be determined in a manner of sorting 6 segments of sub-regions in a descending order. The number of the points to be heated in the sub-region is sequenced at the beginning, so that the grouping process is clearer and simpler.