summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Morris <mikemorris@users.noreply.github.com>2016-04-12 18:33:39 -0700
committerMike Morris <mikemorris@users.noreply.github.com>2016-04-12 18:33:39 -0700
commitfea3aa573ad49003068f94374d766300fc35247f (patch)
tree4b8534f818d2809aa709020943de5bb5f22a9563
parentb401d192b38a5c00a91862b21d6a89a04b30245c (diff)
downloadqtlocation-mapboxgl-fea3aa573ad49003068f94374d766300fc35247f.tar.gz
everything is wrong but harfbuzz output is being consumed
-rw-r--r--src/mbgl/text/font.cpp42
-rw-r--r--src/mbgl/text/font.hpp6
-rw-r--r--src/mbgl/text/font_stack.cpp9
3 files changed, 39 insertions, 18 deletions
diff --git a/src/mbgl/text/font.cpp b/src/mbgl/text/font.cpp
index 3ee3b5f33a..34cfda4501 100644
--- a/src/mbgl/text/font.cpp
+++ b/src/mbgl/text/font.cpp
@@ -5,7 +5,6 @@
#include <fstream>
#include <iostream>
-#include <cstdint>
#include <codecvt>
namespace mbgl {
@@ -48,35 +47,38 @@ void Font::load() {
hb_blob_destroy(blob);
font_ = hb_font_create(face);
-#if 1
// TODO: Font size
- unsigned int upem = hb_face_get_upem(face);
- hb_font_set_scale(font_, upem, upem);
-#endif
+ upem_ = hb_face_get_upem(face);
+ hb_font_set_scale(font_, upem_, upem_);
+
hb_face_destroy(face);
hb_ft_font_set_funcs(font_);
}
-void Font::shape(const std::u32string &text)
-{
- if (!font_) return;
+Shaping Font::shape(const std::u32string &text, const float spacing, const vec2<float> &translate) {
+ Shaping shaping(translate.x * 24, translate.y * 24, text);
+
+ // TODO: the y offset *should* be part of the font metadata
+ // const int32_t yOffset = -17;
+
+ if (!font_) return shaping;
+ /*
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> cv;
std::cout << cv.to_bytes(text) << std::endl;
+ */
hb_buffer_reset(buffer_);
-
hb_buffer_add_utf32(buffer_, reinterpret_cast<const uint32_t*>(text.c_str()), text.length(), 0, text.length());
hb_buffer_set_direction(buffer_, HB_DIRECTION_RTL);
+ // hb_buffer_set_direction(buffer, hb_direction_from_string (direction, -1));
+
hb_buffer_set_script(buffer_, HB_SCRIPT_ARABIC);
- hb_buffer_set_language(buffer_, hb_language_from_string("ar", -1));
+ // hb_buffer_set_script(buffer, hb_script_from_string (script, -1));
-#if 0
- hb_buffer_set_direction(buffer, hb_direction_from_string (direction, -1));
- hb_buffer_set_script(buffer, hb_script_from_string (script, -1));
- hb_buffer_set_language(buffer, hb_language_from_string (language, -1));
-#endif
+ hb_buffer_set_language(buffer_, hb_language_from_string("ar", -1));
+ // hb_buffer_set_language(buffer, hb_language_from_string (language, -1));
hb_shape(font_, buffer_, 0 /*features*/, 0 /*num_features*/);
@@ -84,7 +86,14 @@ void Font::shape(const std::u32string &text)
hb_glyph_info_t *hb_glyph = hb_buffer_get_glyph_infos(buffer_, NULL);
hb_glyph_position_t *hb_position = hb_buffer_get_glyph_positions(buffer_, NULL);
+ // Loop through all characters of this label and shape.
for (int i = 0; i < num_glyphs; i++) {
+ uint32_t codepoint = hb_glyph[i].codepoint;
+ shaping.positionedGlyphs.emplace_back(codepoint,
+ hb_position[i].x_advance + spacing,
+ hb_position[i].y_advance);
+
+ /*
std::cout << "glyph codepoint:" << hb_glyph[i].codepoint <<
" cluster: " << hb_glyph[i].cluster <<
" mask: " << hb_glyph[i].mask <<
@@ -93,8 +102,11 @@ void Font::shape(const std::u32string &text)
// " x_offset: "<< hb_position[i].x_offset <<
// " y_offset: "<< hb_position[i].y_offset << "\n";
// std::cout << "glyph:" << hb_glyph->codepoint << "\n";
+ */
}
+ return shaping;
+
/*
auto hb_buffer_deleter = [](hb_buffer_t * buffer) { hb_buffer_destroy(buffer);};
const std::unique_ptr<hb_buffer_t, decltype(hb_buffer_deleter)> buffer(hb_buffer_create(),hb_buffer_deleter);
diff --git a/src/mbgl/text/font.hpp b/src/mbgl/text/font.hpp
index afb3248888..9d34b18df1 100644
--- a/src/mbgl/text/font.hpp
+++ b/src/mbgl/text/font.hpp
@@ -1,6 +1,9 @@
#ifndef MBGL_TEXT_FONT
#define MBGL_TEXT_FONT
+#include <mbgl/text/glyph.hpp>
+#include <mbgl/util/math.hpp>
+
#include <string>
#include <harfbuzz/hb.h>
@@ -12,7 +15,7 @@ public:
Font(const std::string &filename);
~Font();
- void shape(const std::u32string &text);
+ Shaping shape(const std::u32string &text, const float spacing, const vec2<float> &translate);
private:
void load();
@@ -20,6 +23,7 @@ private:
std::string filename_;
hb_font_t *font_;
hb_buffer_t *buffer_;
+ unsigned int upem_;
};
} // end namespace mbgl
diff --git a/src/mbgl/text/font_stack.cpp b/src/mbgl/text/font_stack.cpp
index d49e128f51..4c27a3dc5f 100644
--- a/src/mbgl/text/font_stack.cpp
+++ b/src/mbgl/text/font_stack.cpp
@@ -35,26 +35,31 @@ const Shaping FontStack::getShaping(const std::u32string &string, const float ma
const float lineHeight, const float horizontalAlign,
const float verticalAlign, const float justify,
const float spacing, const vec2<float> &translate) const {
+ /*
Shaping shaping(translate.x * 24, translate.y * 24, string);
- // the y offset *should* be part of the font metadata
+ // TODO: the y offset *should* be part of the font metadata
const int32_t yOffset = -17;
float x = 0;
const float y = yOffset;
+ */
// Create new Harfbuzz font object
Font font("/Library/Fonts/Arial Unicode.ttf");
- font.shape(string);
+ Shaping shaping = font.shape(string, spacing, translate);
+ /*
// Loop through all characters of this label and shape.
for (uint32_t chr : string) {
auto it = sdfs.find(chr);
if (it != sdfs.end()) {
+ // TODO: change this instead of assuming they stay in order
shaping.positionedGlyphs.emplace_back(chr, x, y);
x += it->second.metrics.advance + spacing;
}
}
+ */
if (shaping.positionedGlyphs.empty())
return shaping;