diff options
author | Chris Loer <chris.loer@gmail.com> | 2018-09-19 15:20:03 -0700 |
---|---|---|
committer | Chris Loer <chris.loer@mapbox.com> | 2018-10-15 13:15:46 -0700 |
commit | bc718257748f1ad87658e85f8c31b574afca57a9 (patch) | |
tree | 10ca9f0b762362102482d0614e2d04feab419730 /platform/qt | |
parent | fed55418f21719149e510a6c49836ba58a5da2c2 (diff) | |
download | qtlocation-mapboxgl-bc718257748f1ad87658e85f8c31b574afca57a9.tar.gz |
[core] Bidi support for styled text.
Remove use of QString from non-ICU Qt stub bidi implementation since we weren't making use of it.
Diffstat (limited to 'platform/qt')
-rw-r--r-- | platform/qt/src/bidi.cpp | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/platform/qt/src/bidi.cpp b/platform/qt/src/bidi.cpp index b75d038d6b..6b680a9769 100644 --- a/platform/qt/src/bidi.cpp +++ b/platform/qt/src/bidi.cpp @@ -2,51 +2,50 @@ #include <mbgl/text/bidi.hpp> -#include <QString> - namespace mbgl { +// This stub implementation is stateless and doesn't implement the private +// methods used by the ICU BiDi class BiDiImpl { -public: - QString string; + // Used by the ICU implementation to hold onto internal BiDi state }; std::u16string applyArabicShaping(const std::u16string& input) { return input; } -void BiDi::mergeParagraphLineBreaks(std::set<std::size_t>& lineBreakPoints) { - lineBreakPoints.insert(static_cast<std::size_t>(impl->string.length())); +BiDi::BiDi() : impl(std::make_unique<BiDiImpl>()) +{ } -std::vector<std::u16string> -BiDi::applyLineBreaking(std::set<std::size_t> lineBreakPoints) { - mergeParagraphLineBreaks(lineBreakPoints); +BiDi::~BiDi() = default; + +std::vector<std::u16string> BiDi::processText(const std::u16string& input, std::set<std::size_t> lineBreakPoints) { + lineBreakPoints.insert(input.length()); std::vector<std::u16string> transformedLines; std::size_t start = 0; for (std::size_t lineBreakPoint : lineBreakPoints) { - transformedLines.push_back(getLine(start, lineBreakPoint)); + transformedLines.push_back(input.substr(start, lineBreakPoint - start)); start = lineBreakPoint; } return transformedLines; } -BiDi::BiDi() : impl(std::make_unique<BiDiImpl>()) -{ -} - -BiDi::~BiDi() = default; +std::vector<StyledText> BiDi::processStyledText(const StyledText& input, std::set<std::size_t> lineBreakPoints) { + lineBreakPoints.insert(input.first.length()); -std::vector<std::u16string> BiDi::processText(const std::u16string& input, std::set<std::size_t> lineBreakPoints) { - impl->string = QString::fromUtf16(reinterpret_cast<const ushort*>(input.data()), int(input.size())); - return applyLineBreaking(lineBreakPoints); -} + std::vector<StyledText> transformedLines; + std::size_t start = 0; + for (std::size_t lineBreakPoint : lineBreakPoints) { + transformedLines.emplace_back( + input.first.substr(start, lineBreakPoint - start), + std::vector<uint8_t>(input.second.begin() + start, input.second.begin() + lineBreakPoint)); + start = lineBreakPoint; + } -std::u16string BiDi::getLine(std::size_t start, std::size_t end) { - auto utf16 = impl->string.mid(static_cast<int32_t>(start), static_cast<int32_t>(end - start)); - return std::u16string(reinterpret_cast<const char16_t*>(utf16.utf16()), utf16.length()); + return transformedLines; } } // end namespace mbgl |