components/u8g2/csrc/u8g2_kerning.c

changeset 0
88d965579617
equal deleted inserted replaced
-1:000000000000 0:88d965579617
1 /*
2
3 u8g2_kerning.c
4
5 Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6
7 Copyright (c) 2016, olikraus@gmail.com
8 All rights reserved.
9
10 Redistribution and use in source and binary forms, with or without modification,
11 are permitted provided that the following conditions are met:
12
13 * Redistributions of source code must retain the above copyright notice, this list
14 of conditions and the following disclaimer.
15
16 * Redistributions in binary form must reproduce the above copyright notice, this
17 list of conditions and the following disclaimer in the documentation and/or other
18 materials provided with the distribution.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34 */
35
36 #include "u8g2.h"
37
38 /* this function is used as "u8g2_get_kerning_cb" */
39 /*
40 uint8_t u8g2_GetNullKerning(u8g2_t *u8g2, uint16_t e1, uint16_t e2)
41 {
42 return 0;
43 }
44 */
45
46 /* this function is used as "u8g2_get_kerning_cb" */
47 uint8_t u8g2_GetKerning(U8X8_UNUSED u8g2_t *u8g2, u8g2_kerning_t *kerning, uint16_t e1, uint16_t e2)
48 {
49 uint16_t i1, i2, cnt, end;
50 if ( kerning == NULL )
51 return 0;
52
53 /* search for the encoding in the first table */
54 cnt = kerning->first_table_cnt;
55 cnt--; /* ignore the last element of the table, which is 0x0ffff */
56 for( i1 = 0; i1 < cnt; i1++ )
57 {
58 if ( kerning->first_encoding_table[i1] == e1 )
59 break;
60 }
61 if ( i1 >= cnt )
62 return 0; /* e1 not part of the kerning table, return 0 */
63
64 /* get the upper index for i2 */
65 end = kerning->index_to_second_table[i1+1];
66 for( i2 = kerning->index_to_second_table[i1]; i2 < end; i2++ )
67 {
68 if ( kerning->second_encoding_table[i2] == e2 )
69 break;
70 }
71
72 if ( i2 >= end )
73 return 0; /* e2 not part of any pair with e1, return 0 */
74
75 return kerning->kerning_values[i2];
76 }
77
78 uint8_t u8g2_GetKerningByTable(U8X8_UNUSED u8g2_t *u8g2, const uint16_t *kt, uint16_t e1, uint16_t e2)
79 {
80 uint16_t i;
81 i = 0;
82 if ( kt == NULL )
83 return 0;
84 for(;;)
85 {
86 if ( kt[i] == 0x0ffff )
87 break;
88 if ( kt[i] == e1 && kt[i+1] == e2 )
89 return kt[i+2];
90 i+=3;
91 }
92 return 0;
93 }
94

mercurial