summaryrefslogtreecommitdiff
path: root/src/mbgl/geometry/debug_font_buffer.cpp
diff options
context:
space:
mode:
authorLeith Bade <leith@mapbox.com>2014-12-05 23:16:49 +1100
committerLeith Bade <leith@mapbox.com>2014-12-05 23:16:49 +1100
commitde9eb00276684a10f49a1c490f55266b80238155 (patch)
treefc713b06541bb1af04e95c70f2e383bcb86a164a /src/mbgl/geometry/debug_font_buffer.cpp
parentc348c141c5c5754c962d9b7e94af83f097e30487 (diff)
parentff640132de0fe855314a8fd86adae3a2fb33237b (diff)
downloadqtlocation-mapboxgl-de9eb00276684a10f49a1c490f55266b80238155.tar.gz
Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason
Conflicts: .gitignore gyp/mbgl-ios.gypi gyp/mbgl-linux.gypi gyp/mbgl-osx.gypi include/mbgl/map/map.hpp src/mbgl/map/map.cpp src/mbgl/storage/caching_http_file_source.cpp
Diffstat (limited to 'src/mbgl/geometry/debug_font_buffer.cpp')
-rw-r--r--src/mbgl/geometry/debug_font_buffer.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/mbgl/geometry/debug_font_buffer.cpp b/src/mbgl/geometry/debug_font_buffer.cpp
new file mode 100644
index 0000000000..1ec71463e5
--- /dev/null
+++ b/src/mbgl/geometry/debug_font_buffer.cpp
@@ -0,0 +1,42 @@
+#include <mbgl/geometry/debug_font_buffer.hpp>
+#include <mbgl/geometry/debug_font_data.hpp>
+
+#include <mbgl/platform/gl.hpp>
+#include <cmath>
+#include <cstring>
+
+using namespace mbgl;
+
+void DebugFontBuffer::addText(const char *text, double left, double baseline, double scale) {
+ uint16_t *coords = nullptr;
+
+ const size_t len = strlen(text);
+ for (size_t i = 0; i < len; ++i) {
+ if (text[i] < 32 || (unsigned char)(text[i]) >= 127) {
+ 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) {
+ if (glyph.data[j] == -1 && glyph.data[j + 1] == -1) {
+ prev = false;
+ } else {
+ int16_t x = std::round(left + glyph.data[j] * scale);
+ int16_t y = std::round(baseline - glyph.data[j + 1] * scale);
+ if (prev) {
+ coords = static_cast<uint16_t *>(addElement());
+ coords[0] = prev_x;
+ coords[1] = prev_y;
+
+ coords = static_cast<uint16_t *>(addElement());
+ coords[0] = x;
+ coords[1] = y;
+ }
+ prev_x = x; prev_y = y; prev = true;
+ }
+ }
+ left += glyph.width * scale;
+ }
+}