summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-10-30 17:36:28 -0400
committerKonstantin Käfer <mail@kkaefer.com>2014-10-30 17:36:28 -0400
commit203acaad9e654680e62c3bab1c3fe27b64009007 (patch)
tree6f49bd92acc9f0df3645845c14fdaa92e5828db0 /src
parent8712beff80fdee10c3eb9634b65cfeb659944936 (diff)
downloadqtlocation-mapboxgl-203acaad9e654680e62c3bab1c3fe27b64009007.tar.gz
simplify debug font lookup
Diffstat (limited to 'src')
-rw-r--r--src/geometry/debug_font.cpp198
-rw-r--r--src/geometry/debug_font_buffer.cpp12
2 files changed, 99 insertions, 111 deletions
diff --git a/src/geometry/debug_font.cpp b/src/geometry/debug_font.cpp
index 8ee9f6811f..7e69246fdb 100644
--- a/src/geometry/debug_font.cpp
+++ b/src/geometry/debug_font.cpp
@@ -97,11 +97,6 @@ const int8_t simplex_93[] = { 5, 25, 7, 24, 8, 23, 9, 21, 9, 19, 8, 17, 7, 16, 6
const int8_t simplex_94[] = { 3, 6, 3, 8, 4, 11, 6, 12, 8, 12, 10, 11, 14, 8, 16, 7, 18, 7, 20, 8, 21, 10, -1, -1, 3, 8, 4, 10, 6, 11, 8, 11, 10, 10, 14, 7, 16, 6, 18, 6, 20, 7, 21, 10, 21, 12 };
struct glyph {
- glyph() : width(0), length(0), data(nullptr) { }
- glyph(uint8_t width_, uint8_t length_, const int8_t *data_)
- : width(width_),
- length(length_),
- data(data_) {}
uint8_t width;
uint8_t length;
const int8_t *data;
@@ -109,100 +104,101 @@ struct glyph {
// Font data From Hershey Simplex Font
// http://paulbourke.net/dataformats/hershey/
-const std::map<char, glyph> simplex = {
- { ' ', { 16, 0, nullptr } },
- { '!', { 10, sizeof(simplex_1), simplex_1 } },
- { '"', { 16, sizeof(simplex_2), simplex_2 } },
- { '#', { 21, sizeof(simplex_3), simplex_3 } },
- { '$', { 20, sizeof(simplex_4), simplex_4 } },
- { '%', { 24, sizeof(simplex_5), simplex_5 } },
- { '&', { 26, sizeof(simplex_6), simplex_6 } },
- { '\'', { 10, sizeof(simplex_7), simplex_7 } },
- { '(', { 14, sizeof(simplex_8), simplex_8 } },
- { ')', { 14, sizeof(simplex_9), simplex_9 } },
- { '*', { 16, sizeof(simplex_10), simplex_10 } },
- { '+', { 26, sizeof(simplex_11), simplex_11 } },
- { ',', { 10, sizeof(simplex_12), simplex_12 } },
- { '-', { 26, sizeof(simplex_13), simplex_13 } },
- { '.', { 10, sizeof(simplex_14), simplex_14 } },
- { '/', { 22, sizeof(simplex_15), simplex_15 } },
- { '0', { 20, sizeof(simplex_16), simplex_16 } },
- { '1', { 20, sizeof(simplex_17), simplex_17 } },
- { '2', { 20, sizeof(simplex_18), simplex_18 } },
- { '3', { 20, sizeof(simplex_19), simplex_19 } },
- { '4', { 20, sizeof(simplex_20), simplex_20 } },
- { '5', { 20, sizeof(simplex_21), simplex_21 } },
- { '6', { 20, sizeof(simplex_22), simplex_22 } },
- { '7', { 20, sizeof(simplex_23), simplex_23 } },
- { '8', { 20, sizeof(simplex_24), simplex_24 } },
- { '9', { 20, sizeof(simplex_25), simplex_25 } },
- { ':', { 10, sizeof(simplex_26), simplex_26 } },
- { ';', { 10, sizeof(simplex_27), simplex_27 } },
- { '<', { 24, sizeof(simplex_28), simplex_28 } },
- { '=', { 26, sizeof(simplex_29), simplex_29 } },
- { '>', { 24, sizeof(simplex_30), simplex_30 } },
- { '?', { 18, sizeof(simplex_31), simplex_31 } },
- { '@', { 27, sizeof(simplex_32), simplex_32 } },
- { 'A', { 18, sizeof(simplex_33), simplex_33 } },
- { 'B', { 21, sizeof(simplex_34), simplex_34 } },
- { 'C', { 21, sizeof(simplex_35), simplex_35 } },
- { 'D', { 21, sizeof(simplex_36), simplex_36 } },
- { 'E', { 19, sizeof(simplex_37), simplex_37 } },
- { 'F', { 18, sizeof(simplex_38), simplex_38 } },
- { 'G', { 21, sizeof(simplex_39), simplex_39 } },
- { 'H', { 22, sizeof(simplex_40), simplex_40 } },
- { 'I', { 8, sizeof(simplex_41), simplex_41 } },
- { 'J', { 16, sizeof(simplex_42), simplex_42 } },
- { 'K', { 21, sizeof(simplex_43), simplex_43 } },
- { 'L', { 17, sizeof(simplex_44), simplex_44 } },
- { 'M', { 24, sizeof(simplex_45), simplex_45 } },
- { 'N', { 22, sizeof(simplex_46), simplex_46 } },
- { 'O', { 22, sizeof(simplex_47), simplex_47 } },
- { 'P', { 21, sizeof(simplex_48), simplex_48 } },
- { 'Q', { 22, sizeof(simplex_49), simplex_49 } },
- { 'R', { 21, sizeof(simplex_50), simplex_50 } },
- { 'S', { 20, sizeof(simplex_51), simplex_51 } },
- { 'T', { 16, sizeof(simplex_52), simplex_52 } },
- { 'U', { 22, sizeof(simplex_53), simplex_53 } },
- { 'V', { 18, sizeof(simplex_54), simplex_54 } },
- { 'W', { 24, sizeof(simplex_55), simplex_55 } },
- { 'X', { 20, sizeof(simplex_56), simplex_56 } },
- { 'Y', { 18, sizeof(simplex_57), simplex_57 } },
- { 'Z', { 20, sizeof(simplex_58), simplex_58 } },
- { '[', { 14, sizeof(simplex_59), simplex_59 } },
- { '\\', { 14, sizeof(simplex_60), simplex_60 } },
- { ']', { 14, sizeof(simplex_61), simplex_61 } },
- { '^', { 16, sizeof(simplex_62), simplex_62 } },
- { '_', { 16, sizeof(simplex_63), simplex_63 } },
- { '`', { 10, sizeof(simplex_64), simplex_64 } },
- { 'a', { 19, sizeof(simplex_65), simplex_65 } },
- { 'b', { 19, sizeof(simplex_66), simplex_66 } },
- { 'c', { 18, sizeof(simplex_67), simplex_67 } },
- { 'd', { 19, sizeof(simplex_68), simplex_68 } },
- { 'e', { 18, sizeof(simplex_69), simplex_69 } },
- { 'f', { 12, sizeof(simplex_70), simplex_70 } },
- { 'g', { 19, sizeof(simplex_71), simplex_71 } },
- { 'h', { 19, sizeof(simplex_72), simplex_72 } },
- { 'i', { 8, sizeof(simplex_73), simplex_73 } },
- { 'j', { 10, sizeof(simplex_74), simplex_74 } },
- { 'k', { 17, sizeof(simplex_75), simplex_75 } },
- { 'l', { 8, sizeof(simplex_76), simplex_76 } },
- { 'm', { 30, sizeof(simplex_77), simplex_77 } },
- { 'n', { 19, sizeof(simplex_78), simplex_78 } },
- { 'o', { 19, sizeof(simplex_79), simplex_79 } },
- { 'p', { 19, sizeof(simplex_80), simplex_80 } },
- { 'q', { 19, sizeof(simplex_81), simplex_81 } },
- { 'r', { 13, sizeof(simplex_82), simplex_82 } },
- { 's', { 17, sizeof(simplex_83), simplex_83 } },
- { 't', { 12, sizeof(simplex_84), simplex_84 } },
- { 'u', { 19, sizeof(simplex_85), simplex_85 } },
- { 'v', { 16, sizeof(simplex_86), simplex_86 } },
- { 'w', { 22, sizeof(simplex_87), simplex_87 } },
- { 'x', { 17, sizeof(simplex_88), simplex_88 } },
- { 'y', { 16, sizeof(simplex_89), simplex_89 } },
- { 'z', { 17, sizeof(simplex_90), simplex_90 } },
- { '{', { 14, sizeof(simplex_91), simplex_91 } },
- { '|', { 8, sizeof(simplex_92), simplex_92 } },
- { '}', { 14, sizeof(simplex_93), simplex_93 } },
- { '~', { 24, sizeof(simplex_94), simplex_94 } }
+
+const glyph simplex[] = {
+ /* 32 */ { 16, 0, nullptr },
+ /* 33 ! */ { 10, sizeof(simplex_1), simplex_1 },
+ /* 34 " */ { 16, sizeof(simplex_2), simplex_2 },
+ /* 35 # */ { 21, sizeof(simplex_3), simplex_3 },
+ /* 36 $ */ { 20, sizeof(simplex_4), simplex_4 },
+ /* 37 % */ { 24, sizeof(simplex_5), simplex_5 },
+ /* 38 & */ { 26, sizeof(simplex_6), simplex_6 },
+ /* 39 ' */ { 10, sizeof(simplex_7), simplex_7 },
+ /* 40 ( */ { 14, sizeof(simplex_8), simplex_8 },
+ /* 41 ) */ { 14, sizeof(simplex_9), simplex_9 },
+ /* 42 * */ { 16, sizeof(simplex_10), simplex_10 },
+ /* 43 + */ { 26, sizeof(simplex_11), simplex_11 },
+ /* 44 , */ { 10, sizeof(simplex_12), simplex_12 },
+ /* 45 - */ { 26, sizeof(simplex_13), simplex_13 },
+ /* 46 . */ { 10, sizeof(simplex_14), simplex_14 },
+ /* 47 / */ { 22, sizeof(simplex_15), simplex_15 },
+ /* 48 0 */ { 20, sizeof(simplex_16), simplex_16 },
+ /* 49 1 */ { 20, sizeof(simplex_17), simplex_17 },
+ /* 50 2 */ { 20, sizeof(simplex_18), simplex_18 },
+ /* 51 3 */ { 20, sizeof(simplex_19), simplex_19 },
+ /* 52 4 */ { 20, sizeof(simplex_20), simplex_20 },
+ /* 53 5 */ { 20, sizeof(simplex_21), simplex_21 },
+ /* 54 6 */ { 20, sizeof(simplex_22), simplex_22 },
+ /* 55 7 */ { 20, sizeof(simplex_23), simplex_23 },
+ /* 56 8 */ { 20, sizeof(simplex_24), simplex_24 },
+ /* 57 9 */ { 20, sizeof(simplex_25), simplex_25 },
+ /* 58 : */ { 10, sizeof(simplex_26), simplex_26 },
+ /* 59 ; */ { 10, sizeof(simplex_27), simplex_27 },
+ /* 60 < */ { 24, sizeof(simplex_28), simplex_28 },
+ /* 61 = */ { 26, sizeof(simplex_29), simplex_29 },
+ /* 62 > */ { 24, sizeof(simplex_30), simplex_30 },
+ /* 63 ? */ { 18, sizeof(simplex_31), simplex_31 },
+ /* 64 @ */ { 27, sizeof(simplex_32), simplex_32 },
+ /* 65 A */ { 18, sizeof(simplex_33), simplex_33 },
+ /* 66 B */ { 21, sizeof(simplex_34), simplex_34 },
+ /* 67 C */ { 21, sizeof(simplex_35), simplex_35 },
+ /* 68 D */ { 21, sizeof(simplex_36), simplex_36 },
+ /* 69 E */ { 19, sizeof(simplex_37), simplex_37 },
+ /* 70 F */ { 18, sizeof(simplex_38), simplex_38 },
+ /* 71 G */ { 21, sizeof(simplex_39), simplex_39 },
+ /* 72 H */ { 22, sizeof(simplex_40), simplex_40 },
+ /* 73 I */ { 8, sizeof(simplex_41), simplex_41 },
+ /* 74 J */ { 16, sizeof(simplex_42), simplex_42 },
+ /* 75 K */ { 21, sizeof(simplex_43), simplex_43 },
+ /* 76 L */ { 17, sizeof(simplex_44), simplex_44 },
+ /* 77 M */ { 24, sizeof(simplex_45), simplex_45 },
+ /* 78 N */ { 22, sizeof(simplex_46), simplex_46 },
+ /* 79 O */ { 22, sizeof(simplex_47), simplex_47 },
+ /* 80 P */ { 21, sizeof(simplex_48), simplex_48 },
+ /* 81 Q */ { 22, sizeof(simplex_49), simplex_49 },
+ /* 82 R */ { 21, sizeof(simplex_50), simplex_50 },
+ /* 83 S */ { 20, sizeof(simplex_51), simplex_51 },
+ /* 84 T */ { 16, sizeof(simplex_52), simplex_52 },
+ /* 85 U */ { 22, sizeof(simplex_53), simplex_53 },
+ /* 86 V */ { 18, sizeof(simplex_54), simplex_54 },
+ /* 87 W */ { 24, sizeof(simplex_55), simplex_55 },
+ /* 88 X */ { 20, sizeof(simplex_56), simplex_56 },
+ /* 89 Y */ { 18, sizeof(simplex_57), simplex_57 },
+ /* 90 Z */ { 20, sizeof(simplex_58), simplex_58 },
+ /* 91 [ */ { 14, sizeof(simplex_59), simplex_59 },
+ /* 92 \ */ { 14, sizeof(simplex_60), simplex_60 },
+ /* 93 ] */ { 14, sizeof(simplex_61), simplex_61 },
+ /* 94 ^ */ { 16, sizeof(simplex_62), simplex_62 },
+ /* 95 _ */ { 16, sizeof(simplex_63), simplex_63 },
+ /* 96 ` */ { 10, sizeof(simplex_64), simplex_64 },
+ /* 97 a */ { 19, sizeof(simplex_65), simplex_65 },
+ /* 98 b */ { 19, sizeof(simplex_66), simplex_66 },
+ /* 99 c */ { 18, sizeof(simplex_67), simplex_67 },
+ /* 100 d */ { 19, sizeof(simplex_68), simplex_68 },
+ /* 101 e */ { 18, sizeof(simplex_69), simplex_69 },
+ /* 102 f */ { 12, sizeof(simplex_70), simplex_70 },
+ /* 103 g */ { 19, sizeof(simplex_71), simplex_71 },
+ /* 104 h */ { 19, sizeof(simplex_72), simplex_72 },
+ /* 105 i */ { 8, sizeof(simplex_73), simplex_73 },
+ /* 106 j */ { 10, sizeof(simplex_74), simplex_74 },
+ /* 107 k */ { 17, sizeof(simplex_75), simplex_75 },
+ /* 108 l */ { 8, sizeof(simplex_76), simplex_76 },
+ /* 109 m */ { 30, sizeof(simplex_77), simplex_77 },
+ /* 110 n */ { 19, sizeof(simplex_78), simplex_78 },
+ /* 111 o */ { 19, sizeof(simplex_79), simplex_79 },
+ /* 112 p */ { 19, sizeof(simplex_80), simplex_80 },
+ /* 113 q */ { 19, sizeof(simplex_81), simplex_81 },
+ /* 114 r */ { 13, sizeof(simplex_82), simplex_82 },
+ /* 115 s */ { 17, sizeof(simplex_83), simplex_83 },
+ /* 116 t */ { 12, sizeof(simplex_84), simplex_84 },
+ /* 117 u */ { 19, sizeof(simplex_85), simplex_85 },
+ /* 118 v */ { 16, sizeof(simplex_86), simplex_86 },
+ /* 119 w */ { 22, sizeof(simplex_87), simplex_87 },
+ /* 120 x */ { 17, sizeof(simplex_88), simplex_88 },
+ /* 121 y */ { 16, sizeof(simplex_89), simplex_89 },
+ /* 122 z */ { 17, sizeof(simplex_90), simplex_90 },
+ /* 123 { */ { 14, sizeof(simplex_91), simplex_91 },
+ /* 124 | */ { 8, sizeof(simplex_92), simplex_92 },
+ /* 125 } */ { 14, sizeof(simplex_93), simplex_93 },
+ /* 126 ~ */ { 24, sizeof(simplex_94), simplex_94 },
};
diff --git a/src/geometry/debug_font_buffer.cpp b/src/geometry/debug_font_buffer.cpp
index 2a0924a1c4..3c858cf60d 100644
--- a/src/geometry/debug_font_buffer.cpp
+++ b/src/geometry/debug_font_buffer.cpp
@@ -12,19 +12,11 @@ void DebugFontBuffer::addText(const char *text, double left, double baseline, do
const size_t len = strlen(text);
for (size_t i = 0; i < len; ++i) {
- if (text[i] < 32 || (unsigned char)(text[i]) > 127) {
+ if (text[i] < 32 || (unsigned char)(text[i]) >= 127) {
continue;
}
- auto it = simplex.find((int)text[i]);
- if (it == simplex.end()) {
- continue;
- }
-
- const glyph& glyph = it->second;
- if (!glyph.width) {
- continue;
- }
+ const glyph& glyph = simplex[text[i] - 32];
int16_t prev_x = -1, prev_y = -1, prev = false;
for (int32_t j = 0; j < glyph.length; j += 2) {