summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-12-12 13:19:35 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-12-12 22:34:52 +0200
commitc0e18ad80c56d6197cb0e5f1e29384ad54491dbb (patch)
tree0d667c35f861ebc427be8e245ce42dea85e42a83
parentce5ed9e6498a832f070400fb281e46cd04e39ea1 (diff)
downloadqtlocation-mapboxgl-c0e18ad80c56d6197cb0e5f1e29384ad54491dbb.tar.gz
[core] Added BidiImpl to avoid ICU types exposure
-rw-r--r--platform/default/bidi.cpp31
-rw-r--r--src/mbgl/text/bidi.hpp7
2 files changed, 20 insertions, 18 deletions
diff --git a/platform/default/bidi.cpp b/platform/default/bidi.cpp
index 7d5f6313bc..5b0c2f8da7 100644
--- a/platform/default/bidi.cpp
+++ b/platform/default/bidi.cpp
@@ -6,6 +6,15 @@
namespace mbgl {
+class BiDiImpl {
+public:
+ BiDiImpl() : bidiText(ubidi_open()), bidiLine(ubidi_open()) {}
+ ~BiDiImpl() { ubidi_close(bidiText); ubidi_close(bidiLine); }
+
+ UBiDi* bidiText = nullptr;
+ UBiDi* bidiLine = nullptr;
+};
+
// Takes UTF16 input in logical order and applies Arabic shaping to the input while maintaining
// logical order
// Output won't be intelligible until the bidirectional algorithm is applied
@@ -38,11 +47,11 @@ ProcessedBiDiText::ProcessedBiDiText(BiDi& p_bidi) : bidi(p_bidi) {
}
void ProcessedBiDiText::mergeParagraphLineBreaks(std::set<int32_t>& lineBreakPoints) {
- int32_t paragraphCount = ubidi_countParagraphs(bidi.bidiText);
+ int32_t paragraphCount = ubidi_countParagraphs(bidi.impl->bidiText);
for (int32_t i = 0; i < paragraphCount; i++) {
UErrorCode errorCode = U_ZERO_ERROR;
int32_t paragraphEndIndex;
- ubidi_getParagraphByIndex(bidi.bidiText, i, NULL, &paragraphEndIndex, NULL, &errorCode);
+ ubidi_getParagraphByIndex(bidi.impl->bidiText, i, NULL, &paragraphEndIndex, NULL, &errorCode);
if (U_FAILURE(errorCode))
throw std::runtime_error(std::string("ProcessedBiDiText::mergeParagraphLineBreaks: ") +
@@ -72,23 +81,17 @@ ProcessedBiDiText::applyLineBreaking(std::set<int32_t> lineBreakPoints) {
return transformedLines;
}
-BiDi::BiDi() {
- bidiText = ubidi_open();
- bidiLine = ubidi_open();
+BiDi::BiDi() : impl(std::make_unique<BiDiImpl>())
+{
}
BiDi::~BiDi() {
- if (bidiText)
- ubidi_close(bidiText);
-
- if (bidiLine)
- ubidi_close(bidiLine);
}
ProcessedBiDiText BiDi::processText(const std::u16string& input) {
UErrorCode errorCode = U_ZERO_ERROR;
- ubidi_setPara(bidiText, input.c_str(), static_cast<int32_t>(input.size()), UBIDI_DEFAULT_LTR,
+ ubidi_setPara(impl->bidiText, input.c_str(), static_cast<int32_t>(input.size()), UBIDI_DEFAULT_LTR,
NULL, &errorCode);
if (U_FAILURE(errorCode))
@@ -99,7 +102,7 @@ ProcessedBiDiText BiDi::processText(const std::u16string& input) {
std::u16string BiDi::getLine(int32_t start, int32_t end) {
UErrorCode errorCode = U_ZERO_ERROR;
- ubidi_setLine(bidiText, start, end, bidiLine, &errorCode);
+ ubidi_setLine(impl->bidiText, start, end, impl->bidiLine, &errorCode);
if (U_FAILURE(errorCode))
throw std::runtime_error(std::string("BiDi::getLine (setLine): ") + u_errorName(errorCode));
@@ -107,13 +110,13 @@ std::u16string BiDi::getLine(int32_t start, int32_t end) {
// Because we set UBIDI_REMOVE_BIDI_CONTROLS, the output may be smaller than what we reserve
// Setting UBIDI_INSERT_LRM_FOR_NUMERIC would require
// ubidi_getLength(pBiDi)+2*ubidi_countRuns(pBiDi)
- int32_t outputLength = ubidi_getProcessedLength(bidiLine);
+ int32_t outputLength = ubidi_getProcessedLength(impl->bidiLine);
std::unique_ptr<UChar[]> outputText = std::make_unique<UChar[]>(outputLength);
// UBIDI_DO_MIRRORING: Apply unicode mirroring of characters like parentheses
// UBIDI_REMOVE_BIDI_CONTROLS: Now that all the lines are set, remove control characters so that
// they don't show up on screen (some fonts have glyphs representing them)
- ubidi_writeReordered(bidiLine, outputText.get(), outputLength,
+ ubidi_writeReordered(impl->bidiLine, outputText.get(), outputLength,
UBIDI_DO_MIRRORING | UBIDI_REMOVE_BIDI_CONTROLS, &errorCode);
if (U_FAILURE(errorCode))
diff --git a/src/mbgl/text/bidi.hpp b/src/mbgl/text/bidi.hpp
index 8cbe079e57..6c209c427c 100644
--- a/src/mbgl/text/bidi.hpp
+++ b/src/mbgl/text/bidi.hpp
@@ -3,14 +3,14 @@
#include <set>
#include <string>
#include <vector>
+#include <memory>
#include <mbgl/util/noncopyable.hpp>
-struct UBiDi;
-
namespace mbgl {
class BiDi;
+class BiDiImpl;
std::u16string applyArabicShaping(const std::u16string&);
@@ -40,8 +40,7 @@ public:
private:
std::u16string getLine(int32_t start, int32_t end);
- UBiDi* bidiText;
- UBiDi* bidiLine;
+ std::unique_ptr<BiDiImpl> impl;
};
} // end namespace mbgl