Summary of the invention
In order to solve the problems of the technologies described above, the objective of the invention is: provide a kind of simple to operate, display effect good, highly versatile and the compatible Arabic display packing that is used on the POS platform.
The technical solution adopted for the present invention to solve the technical problems is: a kind of display packing of the Arabic for the POS platform comprises:
A, employing freetype storehouse build the object in vector fonts storehouse, and read font file, thereby obtain the Arabic local coder of character string to be shown;
B, the local coder obtained is converted to unicode coding;
The total length of the character string to be shown after C, calculation code conversion, the total length that then basis calculates and the total length of screen are determined the starting point of display position;
D, the character string to be shown according to Arabic write the two or more syllables of a word together and transformation rule after to code conversion are carried out conversion process, thereby are obtained new character strings;
The message bit pattern of all characters in E, extraction new character strings, and according to definite starting point, the message bit pattern of extraction is presented on screen.
Further, described step D, it comprises:
D1, the character string to be shown after code conversion is carried out to the write the two or more syllables of a word together conversion process, thereby obtain the character string after the write the two or more syllables of a word together conversion;
D2, the character string after write the two or more syllables of a word together conversion is carried out to deformation process, thereby obtain new character strings.
Further, described step D1, it comprises:
D11, judge in the character string to be shown after code conversion whether i character meets that one of its front character exists and one of back character belongs to the write the two or more syllables of a word together character set simultaneously, if, perform step D12, otherwise, go to step D13, described i is the natural number from 2 beginnings, and 2≤i≤length, and described length is the total length calculated;
Whether D12, one of the front character that judges i character belong to distortion leading character collection, if, i character become to the corresponding character in write the two or more syllables of a word together character set 1, otherwise, i character become to the corresponding character in write the two or more syllables of a word together character set 0;
D13, judge whether i meets i≤length, if, carry out i++, then return to step D11, otherwise, go to step D2.
Further, described step D2, it comprises:
D21, judge whether one of front character or one of the back character of m character in the character string after write the two or more syllables of a word together conversion belong to the deformed characters collection, if perform step D22, otherwise, go to step D23, described m is the natural number from 1 beginning, and 1≤m≤length;
D22, the new unicode that m character is modified to the concentrated correspondence of deformed characters according to the result judged encode;
D23, judge whether m meets m≤length, if, carry out m++, then return to step D21, otherwise, go to step E.
Further, described step e, it comprises:
The api function in E1, employing freetype storehouse is extracted the message bit pattern of n character in new character strings, and described n is the natural number from 1 beginning, and 1≤n≤length;
E2, according to definite starting point, the message bit pattern of n character is presented on the position (xn, yn) of screen;
E3, the starting point of display position is moved horizontally to widthn left, the bitmap width that described widthn is n character;
E4, judge whether n meets n≤length, if, carry out n++, then return to step e 1, otherwise, end operation, described character string to be shown shows complete in screen.
Further, described step e 1, it comprises:
E11, judge screen resolution whether higher than default resolution threshold, if, perform step E12, otherwise, perform step E13;
E12, adopt mode that 256 GTGs play up or the monochromatic mode of playing up to be extracted the message bit pattern of n character;
E13, adopt improved 256 GTGs to play up mode the message bit pattern of n character is extracted, thereby pixel gray level information in n character is taken out to the structure character contour higher than the point of predetermined threshold value.
Further, described step e 2, it comprises:
E21, from the message bit pattern of n character extracting, obtain required metric, then according to the metric obtained, definite starting point is vertically adjusted, thereby n character arranged by datum line;
Starting point after E22, basis are vertically adjusted is presented at the message bit pattern of n character on the position (xn, yn) of screen.
Further, described required metric is n character goes up some the distance to the distance of bitmap region top layer and datum line to regional top layer most.
The invention has the beneficial effects as follows: the vector fonts of having introduced the free transform size of energy, thickness or degree of tilt, and under freetype increases income the support in storehouse, solve raster font and can't normally show Arabic and the problem that can not freely change font size, thickness and degree of tilt, simple to operate, good and the highly versatile of display effect, improved the user interface experience of POS machine; The non-monospaced font that also can expand to other similar Arabic simultaneously shows, better compatible.
Embodiment
With reference to Fig. 1, a kind of display packing of the Arabic for the POS platform comprises:
A, employing freetype storehouse build the object in vector fonts storehouse, and read font file, thereby obtain the Arabic local coder of character string to be shown;
B, the local coder obtained is converted to unicode coding;
The total length of the character string to be shown after C, calculation code conversion, the total length that then basis calculates and the total length of screen are determined the starting point of display position;
D, the character string to be shown according to Arabic write the two or more syllables of a word together and transformation rule after to code conversion are carried out conversion process, thereby are obtained new character strings;
The message bit pattern of all characters in E, extraction new character strings, and according to definite starting point, the message bit pattern of extraction is presented on screen.
Wherein, the object that adopts the freetype storehouse to build the vector fonts storehouse refers to, adopts in the freetype storehouse and supports the character library tahoma.ttf that increases income of Arabic to construct the fontlib object.After building the fontlib object, while reading font file, just can find according to the index information in font file the Arabic local coder of character string to be shown from fontlib.
Processing is changed in the distortion of extracting character bitmap information and back due to the freetype storehouse all needs to adopt the unicode coding, and generally need use local coder when showing the Arabic character string, so the present invention also will utilize the iconv order to carry out code conversion, and using the UTF8 form as intermediate form (be that local coder first is converted to the utf8 code, and then be converted to the unicode coding by the utf8 code).
During the total length of the character string to be shown after calculation code of the present invention conversion, first obtain the width of all characters in character string to be shown, and then the total length that the width of all characters of obtaining has been added up and has been used as calculating.Because the display mode of Arabic font is from right to left, and the total length of screen is fixed, so need to obtain after the total length of character string to be shown the initial point from right to left (being the starting point of display position) that just can know the character layout.
Carry out conversion process, mainly refer to according to Arabic write the two or more syllables of a word together and transformation rule and carry out the write the two or more syllables of a word together conversion and carry out deformation transformation.Wherein the priority of write the two or more syllables of a word together conversion is higher, therefore carries out conversion process and first completes the write the two or more syllables of a word together conversion, and then carry out deformation transformation.
With reference to Fig. 2, be further used as preferred embodiment, described step D, it comprises:
D1, the character string to be shown after code conversion is carried out to the write the two or more syllables of a word together conversion process, thereby obtain the character string after the write the two or more syllables of a word together conversion;
D2, the character string after write the two or more syllables of a word together conversion is carried out to deformation process, thereby obtain new character strings.
With reference to Fig. 3, be further used as preferred embodiment, described step D1, it comprises:
D11, judge in the character string to be shown after code conversion whether i character meets that one of its front character exists and one of back character belongs to the write the two or more syllables of a word together character set simultaneously, if, perform step D12, otherwise, go to step D13, described i is the natural number from 2 beginnings, and 2≤i≤length, and described length is the total length calculated;
Whether D12, one of the front character that judges i character belong to distortion leading character collection, if, i character become to the corresponding character in write the two or more syllables of a word together character set 1, otherwise, i character become to the corresponding character in write the two or more syllables of a word together character set 0;
D13, judge whether i meets i≤length, if, carry out i++, then return to step D11, otherwise, go to step D2.
According to Arabic write the two or more syllables of a word together transformation rule, when carrying out the write the two or more syllables of a word together conversion, the present invention first judges whether to carry out the write the two or more syllables of a word together conversion according to the concrete condition of i adjacent two characters of character (i-1 character and i+1 character), if need, whether belong to the distortion leading character according to one of front character again and integrate i character transformation as the corresponding character in write the two or more syllables of a word together character set 0 or 1.Wherein, write the two or more syllables of a word together character set 0 is the array 0 of existing Arabic write the two or more syllables of a word together transformation rule defined, and write the two or more syllables of a word together character set 1 is the array 1 of existing Arabic write the two or more syllables of a word together transformation rule defined.Corresponding character in write the two or more syllables of a word together character set 0 or 1 (being the unicode coding) can inquire from the write the two or more syllables of a word together conversion table of comparisons provided in advance.
With reference to Fig. 4, be further used as preferred embodiment, described step D2, it comprises:
D21, judge whether one of front character or one of the back character of m character in the character string after write the two or more syllables of a word together conversion belong to the deformed characters collection, if perform step D22, otherwise, go to step D23, described m is the natural number from 1 beginning, and 1≤m≤length;
D22, the new unicode that m character is modified to the concentrated correspondence of deformed characters according to the result judged encode;
D23, judge whether m meets m≤length, if, carry out m++, then return to step D21, otherwise, go to step E.
According to Arabic deformation transformation rule, deformation transformation can be divided into front company and convert one of front(front character and belong to distortion leading character collection 1), rear company converts one of last(back character and belongs to distortion suffix character collection 2), one of intermediate conversion middle(front character belongs to distortion leading character collection 1, a next character belongs to distortion suffix character collection 2) and separately one of alone(front of conversion character do not belong to distortion leading character collection 1, one of back character do not belong to be out of shape suffix character collection 2) these four kinds of situations.When carrying out deformation transformation, the present invention is modified to by m character the new unicode coding that deformed characters is concentrated correspondence according to the concrete condition of m adjacent two characters of character (m-1 character and m+1 character).Wherein, the preposition collection 1 of deformed characters and deformed characters collection 2 are set 1 and the set 2 of existing Arabic deformation transformation rule defined.New unicode coding can inquire from the deformation transformation table of comparisons provided in advance.
With reference to Fig. 5, be further used as preferred embodiment, described step e, it comprises:
The api function in E1, employing freetype storehouse is extracted the message bit pattern of n character in new character strings, and described n is the natural number from 1 beginning, and 1≤n≤length;
E2, according to definite starting point, the message bit pattern of n character is presented on the position (xn, yn) of screen;
E3, the starting point of display position is moved horizontally to widthn left, the bitmap width that described widthn is n character;
E4, judge whether n meets n≤length, if, carry out n++, then return to step e 1, otherwise, end operation, described character string to be shown shows complete in screen.
The api function that the present invention calls the freetype storehouse arranges the size of character bitmap and plays up the attribute (comprising size, thickness and italic etc.) such as mode.
With reference to Fig. 6, be further used as preferred embodiment, described step e 1, it comprises:
E11, judge screen resolution whether higher than default resolution threshold, if, perform step E12, otherwise, perform step E13;
E12, adopt mode that 256 GTGs play up or the monochromatic mode of playing up to be extracted the message bit pattern of n character;
E13, adopt improved 256 GTGs to play up mode the message bit pattern of n character is extracted, thereby pixel gray level information in n character is taken out to the structure character contour higher than the point of predetermined threshold value.
The character bitmap that the present invention extracts the freetype storehouse adds the location of pixel gray level is chosen and adopted improved 256 GTGs to play up mode to carry out the message bit pattern extraction by playing up mode, reach the effect that font is attenuated, can be better in the upper use of POS platform (screen resolution is generally less, as screen).
With reference to Fig. 7, be further used as preferred embodiment, described step e 2, it comprises:
E21, from the message bit pattern of n character extracting, obtain required metric, then according to the metric obtained, definite starting point is vertically adjusted, thereby n character arranged by datum line;
Starting point after E22, basis are vertically adjusted is presented at the message bit pattern of n character on the position (xn, yn) of screen.
Definite starting point is vertically adjusted, and is in order to prevent the horizontally situation of dislocation of Arabic character string.
Be further used as preferred embodiment, described required metric is n character goes up some the distance to the distance of bitmap region top layer and datum line to regional top layer most.
Below in conjunction with Figure of description, specific embodiments of the invention are described in further detail.
Embodiment 1
The algorithm flow chart of this embodiment article Arabic write the two or more syllables of a word together of the present invention and transformation rule.
The present invention is to character string string[length to be shown] processed, mainly refer to and be out of shape and the conversion of combination handwriting rule, wherein the priority of combination handwriting rule is higher, the length that length is character string to be shown.
With reference to Fig. 8, the algorithm flow of Arabic write the two or more syllables of a word together of the present invention and transformation rule is as follows:
(1) according to combination handwriting rule, converted, to needing write the two or more syllables of a word together character string[i] converted 2≤i≤length.
For string[i], if string[i-1] exist and string[i+1] belong to write the two or more syllables of a word together character set, string[i] need the write the two or more syllables of a word together conversion, otherwise do not need the write the two or more syllables of a word together conversion, and string[i] the write the two or more syllables of a word together conversion be divided into again following two kinds of situations:
If string[i-1] belong to and be out of shape leading character collection, string[i]=Arabic_TogetherChar_Set[char_id] [1];
Otherwise, string[i]=Arabic_TogetherChar_Set[char_id] [0].The implication of above-mentioned assignment statement is by string[i according to actual conditions] change in the corresponding character in write the two or more syllables of a word together character set 0 or 1.
(2) according to the Arabic transformation rule, to needing deformed characters string[m] converted 1≤m≤length.Carry out deformation transformation and can be divided into again following four kinds of situations:
If string[m] the front character belongs to distortion leading character collection 1, the back character does not belong to distortion suffix character collection 2, string[m]=Arabic_Transformation_Set[char_id] [front];
If string[m] the front character do not belong to distortion leading character collection 1, the back character belongs to distortion suffix character collection 2, string[m]=Arabic_Transformation_Set[char_id] [last];
If string[m] front and back character all belong to the deformed characters collection,
string[m]=Arabic_Transformation_Set[char_id][middle];
If string[m] front and back character all do not belong to the deformed characters collection,
string[m]=Arabic_Transformation_Set[char_id][alone]。
The implication of above-mentioned assignment statement is by string[m according to actual conditions] change in the corresponding unicode coding of these four kinds of situations of front, last, middle and alone.
Embodiment 2
The thickness of this embodiment article font is regulated and how to be realized.
The effect shown is undoubtedly in pos platform interface of paramount importance, and on the pos platform, why raster font can be adopted by each company always, thereby wherein very large characteristics are exactly that raster font can oneself be finely tuned the display effect that reaches almost Perfect.What vector fonts adopted is the matrixing algorithm of mathematics, and for high-resolution screen, its display effect is good, but for resolution for lower pos platform, it also needs to be adjusted the display effect that reaches good.
The thickness of font is regulated minute following two kinds of situations and is realized:
The one, in the high situation of screen resolution, can carry out by playing up mode the configuration of thickness font, utilize 256 GTGs or the monochromatic mode of playing up to carry out the message bit pattern of character and extract, font just can realize the difference realization of thickness like this.Rendering configurations need to be called FT_LOAD_MONOCHROME and FT_LOAD_NO_AUTOHINT function.
The 2nd, when the low especially POS machine of screen resolution adopts screen, the monochrome carried is played up the mode actual effect may be poor.Therefore, it is that the message bit pattern that 256 GTGs are played up to mode is modified that the present invention takes method, take certain boundary value bounds is cut-off rule, higher than the point of bounds, is just shown, such as the pixel gray level information by all is 255 to extract the structure character contour.
Be if bitmap[i] [j] > bounds, display the bitmap, else don ' t display it.Wherein, bitmap[i] [j] represent bitmap.
Embodiment 3
The imposition layout of this embodiment article font.
After taking out character bitmap information by the freetype storehouse, also will utilize metric wherein that character string is arranged according to datum line, otherwise the words that directly show there will be the situation of horizontal dislocation.
Suppose that we need to be by character string string at (x_topleft, y_topleft) start to show, this point is the reference point on horizontal displaing coordinate, for each character char, the metric that the message bit pattern bitmap that the freetype storehouse extracts need to be used is character go up most a little to the distance b itmap_top of bitmap region top layer and datum line to regional top layer apart from ascender.In order to realize character horizontal alignment on datum line, for character string[i] vertical pixel reference position process as follows:
string[i]->start_y?=y_topleft+(ascender-bitmap_top)。
More than that better enforcement of the present invention is illustrated, but the invention is not limited to described embodiment, those of ordinary skill in the art also can do and make all equivalent variations or replacement under the prerequisite without prejudice to spirit of the present invention, and the distortion that these are equal to or replacement all are included in the application's claim limited range.