Summary of the invention
In order to solve the problems of the technologies described above, the object of the invention is: a kind of simple to operate, display effect good, highly versatile and compatibility are used on POS platform Arabic display packing is provided.
The technical solution adopted for the present invention to solve the technical problems is: a kind of Arabic display packing for POS platform, comprising:
The object in A, structure vector fonts storehouse, employing freetype storehouse, and read font file, thus obtain the Arabic local coder of character string to be shown;
B, the local coder of acquisition is converted to unicode coding;
The total length of character string to be shown after the conversion of C, calculation code, then according to the starting point of the total length determination display position of the total length calculated and screen;
D, according to Arabic write the two or more syllables of a word together and transformation rule, conversion process is carried out to the character string to be shown after code conversion, thus obtain new character strings;
The message bit pattern of all characters in E, extraction new character strings, and be presented on screen according to the message bit pattern of the starting point determined by extraction.
Further, described step D, it comprises:
D1, write the two or more syllables of a word together conversion process is carried out to the character string to be shown after code conversion, thus obtain the character string after write the two or more syllables of a word together conversion;
D2, deformation process is carried out to the character string after write the two or more syllables of a word together conversion, thus obtain new character strings.
Further, described step D1, it comprises:
D11, judge code conversion after character string to be shown in i-th character whether to meet before it character simultaneously and to exist and a character belongs to write the two or more syllables of a word together character set below, if, then perform step D12, otherwise, then go to step D13, described i is the natural number started from 2, and 2≤i≤length, described length are the total length calculated;
D12, to judge before i-th character whether a character belongs to distortion leading character collection, if so, then i-th character is become the corresponding character in write the two or more syllables of a word together character set 1, otherwise, then i-th character is become 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 so, then performs i++, then returns step D11, otherwise, then go to step D2.
Further, described step D2, it comprises:
D21, judge write the two or more syllables of a word together conversion after character string in before m character a character or below a character whether belong to deformed characters collection, if so, then execution step D22, otherwise, then go to step D23, described m is the natural number started from 1, and 1≤m≤length;
D22, m character be modified to deformed characters according to the result judged and concentrate corresponding new unicode to encode;
D23, judge whether m meets m≤length, if so, then performs m++, then returns step D21, otherwise, then go to step E.
Further, described step e, it comprises:
The api function in E1, employing freetype storehouse extracts the message bit pattern of the n-th character in new character strings, and described n is the natural number started from 1, and 1≤n≤length;
E2, according to the starting point determined, the message bit pattern of the n-th character is presented on the position (xn, yn) of screen;
E3, the starting point of display position is moved horizontally widthn left, described widthn is the bitmap width of the n-th character;
E4, judge whether n meets n≤length, if so, then performs n++, then return step e 1, otherwise then end operation, described character string to be shown shows in screen complete.
Further, described step e 1, it comprises:
E11, judge that the resolution of screen is whether higher than the resolution threshold preset, and if so, then performs step e 12, otherwise, then perform step e 13;
The message bit pattern of mode to the n-th character that E12, the mode adopting 256 GTGs to play up or monochrome are played up extracts;
E13, adopt 256 GTGs improved to play up the message bit pattern of mode to the n-th character and extract, thus pixel gray level information in the n-th character is taken out 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 the n-th character extracted, obtain required metric, then according to the metric obtained, longitudinal adjustment is carried out to the starting point determined, thus the n-th character is arranged by datum line;
E22, according to the starting point after longitudinal adjustment, the message bit pattern of the n-th character to be presented on the position (xn, yn) of screen.
Further, described required metric is that the top point of the n-th character is to the Distance geometry datum line of bitmap region top layer to the distance of region top layer.
The invention has the beneficial effects as follows: the vector fonts introducing energy free transform size, thickness or degree of tilt, and freetype increase income storehouse support under, solve raster font normally to show Arabic and freely can not change the problem of font size, thickness and degree of tilt, simple to operate, good and the highly versatile of display effect, improves the user interface experience of POS; Also can expand to the non-monospaced font display of other similar Arabic simultaneously, better compatible.
Embodiment
With reference to Fig. 1, a kind of Arabic display packing for POS platform, comprising:
The object in A, structure vector fonts storehouse, employing freetype storehouse, and read font file, thus obtain the Arabic local coder of character string to be shown;
B, the local coder of acquisition is converted to unicode coding;
The total length of character string to be shown after the conversion of C, calculation code, then according to the starting point of the total length determination display position of the total length calculated and screen;
D, according to Arabic write the two or more syllables of a word together and transformation rule, conversion process is carried out to the character string to be shown after code conversion, thus obtain new character strings;
The message bit pattern of all characters in E, extraction new character strings, and be presented on screen according to the message bit pattern of the starting point determined by extraction.
Wherein, the object adopting freetype storehouse to build vector fonts storehouse refers to, adopts in freetype storehouse and supports that the character library tahoma.ttf that increases income of Arabic is to construct fontlib object.After building fontlib object, when reading font file, just can find the Arabic local coder of character string to be shown according to the index information in font file from fontlib.
Change process due to freetype storehouse extraction character bitmap information and distortion below all to need to adopt unicode coding, and generally need use local coder when display Arabic character string, so the present invention also will utilize iconv order to carry out code conversion, and using UTF8 form as intermediate form (namely local coder is first converted to utf8 code, and then is converted to unicode coding by 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 being used as calculating that the width of all characters obtained has been added up.Display mode due to Arabic font is from right to left, and the total length of screen is fixing, so just can know the initial point from right to left (i.e. the starting point of display position) of character layout after needing to obtain the total length of character string to be shown.
Carry out conversion process, mainly refer to and carry out write the two or more syllables of a word together conversion according to Arabic write the two or more syllables of a word together and transformation rule 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 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, write the two or more syllables of a word together conversion process is carried out to the character string to be shown after code conversion, thus obtain the character string after write the two or more syllables of a word together conversion;
D2, deformation process is carried out to the character string after write the two or more syllables of a word together conversion, thus obtain new character strings.
With reference to Fig. 3, be further used as preferred embodiment, described step D1, it comprises:
D11, judge code conversion after character string to be shown in i-th character whether to meet before it character simultaneously and to exist and a character belongs to write the two or more syllables of a word together character set below, if, then perform step D12, otherwise, then go to step D13, described i is the natural number started from 2, and 2≤i≤length, described length are the total length calculated;
D12, to judge before i-th character whether a character belongs to distortion leading character collection, if so, then i-th character is become the corresponding character in write the two or more syllables of a word together character set 1, otherwise, then i-th character is become 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 so, then performs i++, then returns step D11, otherwise, then go to step D2.
According to Arabic write the two or more syllables of a word together transformation rule, when carrying out write the two or more syllables of a word together conversion, the present invention first judges whether to need to carry out write the two or more syllables of a word together conversion according to the concrete condition of i-th adjacent two character of character (the i-th-1 character and the i-th+1 character), if desired, then whether belong to distortion leading character according to character above again to integrate i-th 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 (i.e. unicode coding) in write the two or more syllables of a word together character set 0 or 1, 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 write the two or more syllables of a word together conversion after character string in before m character a character or below a character whether belong to deformed characters collection, if so, then execution step D22, otherwise, then go to step D23, described m is the natural number started from 1, and 1≤m≤length;
D22, m character be modified to deformed characters according to the result judged and concentrate corresponding new unicode to encode;
D23, judge whether m meets m≤length, if so, then performs m++, then returns step D21, otherwise, then go to step E.
According to Arabic deformation transformation rule, deformation transformation connects a character before conversion front(and belongs to distortion leading character collection 1 before can being divided into), after rear even conversion last(, a character belongs to distortion suffix character collection 2), before intermediate conversion middle(, a character belongs to distortion leading character collection 1, a character next belongs to distortion suffix character collection 2) and separately before conversion alone(a character do not belong to distortion leading character collection 1, after a character do not belong to be out of shape suffix character collection 2) these four kinds of situations.When carrying out deformation transformation, m character is modified to deformed characters according to the concrete condition of m adjacent two character of character (m-1 character and m+1 character) and concentrates corresponding new unicode coding by the present invention.Wherein, the preposition collection of deformed characters 1 and deformed characters collection 2 are set 1 and the set 2 of existing Arabic deformation transformation specified by rules.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 extracts the message bit pattern of the n-th character in new character strings, and described n is the natural number started from 1, and 1≤n≤length;
E2, according to the starting point determined, the message bit pattern of the n-th character is presented on the position (xn, yn) of screen;
E3, the starting point of display position is moved horizontally widthn left, described widthn is the bitmap width of the n-th character;
E4, judge whether n meets n≤length, if so, then performs n++, then return step e 1, otherwise then end operation, described character string to be shown shows in screen complete.
The api function that the present invention calls freetype storehouse arranges the size of character bitmap and plays up the attributes such as mode (comprising size, thickness and italic etc.).
With reference to Fig. 6, be further used as preferred embodiment, described step e 1, it comprises:
E11, judge that the resolution of screen is whether higher than the resolution threshold preset, and if so, then performs step e 12, otherwise, then perform step e 13;
The message bit pattern of mode to the n-th character that E12, the mode adopting 256 GTGs to play up or monochrome are played up extracts;
E13, adopt 256 GTGs improved to play up the message bit pattern of mode to the n-th character and extract, thus pixel gray level information in the n-th character is taken out structure character contour higher than the point of predetermined threshold value.
The character bitmap that the present invention extracts freetype storehouse adds to choose the location of pixel gray level namely adopt 256 GTGs of improvement to play up mode to carry out message bit pattern extraction by playing up mode, reach the effect that font is attenuated, can 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 the n-th character extracted, obtain required metric, then according to the metric obtained, longitudinal adjustment is carried out to the starting point determined, thus the n-th character is arranged by datum line;
E22, according to the starting point after longitudinal adjustment, the message bit pattern of the n-th character to be presented on the position (xn, yn) of screen.
Carrying out longitudinal adjustment to the starting point determined, is situation about horizontally misplacing to prevent Arabic character string.
Be further used as preferred embodiment, described required metric is that the top point of the n-th character is to the Distance geometry datum line of bitmap region top layer to the distance of region top layer.
Below in conjunction with Figure of description, specific embodiments of the invention are described in further detail.
Embodiment 1
This embodiment mainly introduces the algorithm flow chart of Arabic write the two or more syllables of a word together of the present invention and transformation rule.
The present invention processes character string string [length] to be shown, mainly the conversion of the distortion of fingering row and combination handwriting rule, and wherein the priority of combination handwriting rule is higher, and length is the length of 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) convert according to combination handwriting rule, to needing write the two or more syllables of a word together character string [i] to convert, 2≤i≤length.
For string [i], if string [i-1] exists and string [i+1] belongs to write the two or more syllables of a word together character set, then string [i] needs write the two or more syllables of a word together to convert, otherwise does not then need write the two or more syllables of a word together to convert, and the conversion of the write the two or more syllables of a word together of string [i] is divided into again following two kinds of situations:
If string [i-1] belongs to distortion leading character collection, then string [i]=Arabic_TogetherChar_Set [char_id] [1];
Otherwise, string [i]=Arabic_TogetherChar_Set [char_id] [0].The implication of above-mentioned assignment statement to be changed to by string [i] according to actual conditions in the corresponding character in write the two or more syllables of a word together character set 0 or 1.
(2) according to Arabic transformation rule, to needing deformed characters string [m] to convert, 1≤m≤length.Carry out deformation transformation and can be divided into again following four kinds of situations:
If string [m] above character belong to distortion leading character collection 1, after character do not belong to distortion suffix character collection 2, then string [m]=Arabic_Transformation_Set [char_id] [front];
If string [m] above character do not belong to distortion leading character collection 1, after character belong to distortion suffix character collection 2, then string [m]=Arabic_Transformation_Set [char_id] [last];
If string [m] above all belongs to deformed characters collection with character below, then
string[m]=Arabic_Transformation_Set[char_id][middle];
If string [m] does not above all belong to deformed characters collection with character below, then
string[m]=Arabic_Transformation_Set[char_id][alone]。
The implication of above-mentioned assignment statement is changed in the corresponding unicode coding of these four kinds of situations of front, last, middle and alone by string [m] according to actual conditions.
Embodiment 2
How the thickness adjustment that this embodiment mainly introduces font realizes.
The effect of display is undoubtedly in pos platform interface of paramount importance, on pos platform raster font why can always adopt by each company, wherein very large feature is exactly that raster font can oneself carry out finely tuning thus the display effect reaching almost Perfect.What vector fonts adopted is the matrixing algorithm of mathematics, and for high-resolution screen, its display effect is good, but for the lower pos platform of resolution, then it also needs to carry out adjusting to reach good display effect.
The thickness of font regulates point following two kinds of situations to realize:
One be screen resolution high when, the configuration of thickness font can be carried out by playing up mode, namely utilize 256 GTGs or monochrome play up mode carry out character message bit pattern extract, such font just can realize thickness difference realization.Rendering configurations needs to call FT_LOAD_MONOCHROME and FT_LOAD_NO_AUTOHINT function.
Two is screen resolution lower especially POS when adopting screen, and the monochrome carried plays up mode actual effect may be poor.Therefore, the present invention takes method to be that the message bit pattern 256 GTGs being played up mode is modified, with certain boundary value bounds for cut-off rule, the point higher than bounds just shows, and by all pixel gray level information is such as 255 to extract structure character contour.
I.e. ifbitmap [i] [j] >bounds, displaythebitmap, elsedon ' tdisplayit.Wherein, bitmap [i] [j] represents bitmap.
Embodiment 3
This embodiment mainly introduces the imposition layout of font.
After taking out character bitmap information by freetype storehouse, metric wherein also will be utilized character string to be arranged according to datum line, otherwise the words of directly display there will be the situation of horizontally dislocation.
Suppose that we need character string string at (x_topleft, y_topleft) display is started, this point is the reference point on horizontal displaing coordinate, the message bit pattern bitmap extracted for each character char, freetype storehouse needs top point that the metric used is character to the distance bitmap_top of bitmap region top layer and datum line to the distance ascender of region top layer.In order to realize character horizontal alignment on datum line, the longitudinal pixel reference position for character string [i] processes 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 make all equivalent variations or replacement under the prerequisite without prejudice to spirit of the present invention, and these equivalent distortion or replacement are all included in the application's claim limited range.