Hide ICU C++ API from Skia users.
Parts of third_party need the C++ API so hide it from Skia users as needed to prevent re-introduction. This also avoids the ICU version renaming / name mangling when building our own test version of ICU. This makes life in an editor and debugger much easier. Change-Id: I8fb1903e2b31e9dd04efa22173a03115d629c232 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/292854 Reviewed-by: Julia Lavrova <jlavrova@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
parent
a50830b6f4
commit
5ef0d2f6c0
@ -22,6 +22,7 @@ if (skia_enable_skparagraph) {
|
||||
public = skparagraph_public
|
||||
if (skia_use_icu && skia_use_harfbuzz) {
|
||||
sources = skparagraph_sources
|
||||
configs += [ "//third_party/icu:no_cxx" ]
|
||||
} else {
|
||||
sources = []
|
||||
}
|
||||
@ -43,6 +44,7 @@ if (skia_enable_skparagraph) {
|
||||
configs += [ "../../:skia_private" ]
|
||||
if (skia_use_icu && skia_use_harfbuzz) {
|
||||
sources = skparagraph_utils
|
||||
configs += [ "//third_party/icu:no_cxx" ]
|
||||
} else {
|
||||
sources = []
|
||||
}
|
||||
@ -57,6 +59,7 @@ if (skia_enable_skparagraph) {
|
||||
if (skia_use_icu && skia_use_harfbuzz && paragraph_tests_enabled) {
|
||||
testonly = true
|
||||
sources = [ "tests/SkParagraphTest.cpp" ]
|
||||
configs += [ "//third_party/icu:no_cxx" ]
|
||||
deps = [
|
||||
":skparagraph",
|
||||
"../..:gpu_tool_utils",
|
||||
@ -71,6 +74,7 @@ if (skia_enable_skparagraph) {
|
||||
if (skia_use_icu && skia_use_harfbuzz && paragraph_bench_enabled) {
|
||||
testonly = true
|
||||
sources = [ "bench/ParagraphBench.cpp" ]
|
||||
configs += [ "//third_party/icu:no_cxx" ]
|
||||
deps = [
|
||||
":skparagraph",
|
||||
"../..:skia",
|
||||
@ -84,6 +88,7 @@ if (skia_enable_skparagraph) {
|
||||
if (skia_use_icu && skia_use_harfbuzz) {
|
||||
testonly = true
|
||||
sources = [ "samples/SampleParagraph.cpp" ]
|
||||
configs += [ "//third_party/icu:no_cxx" ]
|
||||
deps = [
|
||||
":skparagraph",
|
||||
":utils",
|
||||
|
@ -35,6 +35,7 @@ if (skia_use_icu && skia_use_harfbuzz) {
|
||||
include_dirs = [ "../.." ]
|
||||
public = [ "src/word_boundaries.h" ]
|
||||
sources = [ "src/word_boundaries.cpp" ]
|
||||
configs += [ "//third_party/icu:no_cxx" ]
|
||||
deps = [ "../../third_party/icu" ]
|
||||
}
|
||||
|
||||
|
@ -1,50 +1,55 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
#include "include/core/SkTypes.h"
|
||||
#include "include/private/SkTemplates.h"
|
||||
#include "modules/skplaintexteditor/src/word_boundaries.h"
|
||||
|
||||
#include <unicode/brkiter.h>
|
||||
#include <unicode/unistr.h>
|
||||
|
||||
#include <unicode/ubrk.h>
|
||||
#include <unicode/utext.h>
|
||||
#include <unicode/utypes.h>
|
||||
#include <memory>
|
||||
|
||||
std::vector<bool> GetUtf8WordBoundaries(const char* begin, size_t byteCount, const char* locale) {
|
||||
static constexpr UBreakIteratorType kIteratorType = UBRK_WORD;
|
||||
struct UTextCloser {
|
||||
void operator()(UText* p) { (void)utext_close(p); }
|
||||
};
|
||||
struct UBreakCloser {
|
||||
void operator()(UBreakIterator* p) { (void)ubrk_close(p); }
|
||||
};
|
||||
|
||||
namespace {
|
||||
template <typename T,typename P,P* p> using resource = std::unique_ptr<T, SkFunctionWrapper<P, p>>;
|
||||
using ICUBrk = resource<UBreakIterator, decltype(ubrk_close) , ubrk_close >;
|
||||
using ICUUText = resource<UText , decltype(utext_close) , utext_close >;
|
||||
}
|
||||
|
||||
std::vector<bool> GetUtf8WordBoundaries(const char* begin, size_t byteCount, const char* locale) {
|
||||
std::vector<bool> result;
|
||||
if (0 == byteCount) {
|
||||
return result;
|
||||
}
|
||||
result.resize(byteCount);
|
||||
|
||||
UText utf8UText = UTEXT_INITIALIZER;
|
||||
UErrorCode errorCode = U_ZERO_ERROR;
|
||||
(void)utext_openUTF8(&utf8UText, begin, byteCount, &errorCode);
|
||||
std::unique_ptr<UText, UTextCloser> autoclose1(&utf8UText);
|
||||
if (U_FAILURE(errorCode)) {
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
UText sUtf8UText = UTEXT_INITIALIZER;
|
||||
ICUUText utf8UText(utext_openUTF8(&sUtf8UText, begin, byteCount, &status));
|
||||
if (U_FAILURE(status)) {
|
||||
SkDebugf("Could not create utf8UText: %s", u_errorName(status));
|
||||
return result;
|
||||
}
|
||||
UBreakIterator* iter = ubrk_open(kIteratorType, locale, nullptr, 0, &errorCode);
|
||||
std::unique_ptr<UBreakIterator, UBreakCloser> autoclose2(iter);
|
||||
if (U_FAILURE(errorCode)) {
|
||||
|
||||
ICUBrk wordBreakIterator(ubrk_open(UBRK_WORD, locale, nullptr, 0, &status));
|
||||
if (!wordBreakIterator || U_FAILURE(status)) {
|
||||
SkDEBUGF("Could not create line break iterator: %s", u_errorName(status));
|
||||
return result;
|
||||
}
|
||||
ubrk_setUText(iter, &utf8UText, &errorCode);
|
||||
if (U_FAILURE(errorCode)) {
|
||||
|
||||
ubrk_setUText(&*wordBreakIterator, utf8UText.get(), &status);
|
||||
if (U_FAILURE(status)) {
|
||||
SkDebugf("Could not setText on break iterator: %s", u_errorName(status));
|
||||
return result;
|
||||
}
|
||||
int pos = ubrk_first(iter);
|
||||
while (pos != icu::BreakIterator::DONE) {
|
||||
if ((unsigned)pos < (unsigned)byteCount) {
|
||||
|
||||
int32_t pos = ubrk_first(&*wordBreakIterator);
|
||||
while (pos != UBRK_DONE) {
|
||||
if ((size_t)pos < byteCount) {
|
||||
result[pos] = true;
|
||||
}
|
||||
pos = ubrk_next(iter);
|
||||
pos = ubrk_next(&*wordBreakIterator);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -36,7 +36,10 @@ if (skia_enable_skshaper) {
|
||||
"//third_party/icu",
|
||||
]
|
||||
}
|
||||
configs += [ "../../:skia_private" ]
|
||||
configs += [
|
||||
"../../:skia_private",
|
||||
"//third_party/icu:no_cxx",
|
||||
]
|
||||
}
|
||||
} else {
|
||||
group("skshaper") {
|
||||
|
7
third_party/icu/BUILD.gn
vendored
7
third_party/icu/BUILD.gn
vendored
@ -11,6 +11,12 @@ declare_args() {
|
||||
skia_use_system_icu = is_official_build
|
||||
}
|
||||
|
||||
# Skia avoids the ICU C++ API, but third_party may use it.
|
||||
# Using this config hides the C++ API.
|
||||
config("no_cxx") {
|
||||
defines = [ "U_SHOW_CPLUSPLUS_API=0" ]
|
||||
}
|
||||
|
||||
if (skia_use_system_icu) {
|
||||
system("icu") {
|
||||
libs = [ "icuuc" ]
|
||||
@ -68,6 +74,7 @@ if (skia_use_system_icu) {
|
||||
]
|
||||
public_defines = [
|
||||
"U_USING_ICU_NAMESPACE=0",
|
||||
"U_DISABLE_RENAMING",
|
||||
"SK_USING_THIRD_PARTY_ICU",
|
||||
]
|
||||
configs -= [ "//gn:no_rtti" ]
|
||||
|
Loading…
Reference in New Issue
Block a user