summaryrefslogtreecommitdiff
path: root/libs/minikin
diff options
context:
space:
mode:
Diffstat (limited to 'libs/minikin')
-rw-r--r--libs/minikin/Debug.cpp13
-rw-r--r--libs/minikin/FeatureFlags.h8
-rw-r--r--libs/minikin/FontFeatureUtils.cpp51
-rw-r--r--libs/minikin/FontFeatureUtils.h40
-rw-r--r--libs/minikin/LayoutCore.cpp2
-rw-r--r--libs/minikin/MinikinInternal.cpp13
-rw-r--r--libs/minikin/StringPiece.h1
7 files changed, 64 insertions, 64 deletions
diff --git a/libs/minikin/Debug.cpp b/libs/minikin/Debug.cpp
index 8168a77..42d6d8e 100644
--- a/libs/minikin/Debug.cpp
+++ b/libs/minikin/Debug.cpp
@@ -21,7 +21,6 @@
#include <sstream>
-#include "minikin/FontFeature.h"
#include "minikin/FontFileParser.h"
#include "minikin/LayoutCore.h"
#include "minikin/LocaleList.h"
@@ -80,18 +79,6 @@ std::string toString(const MinikinExtent& extent) {
return ss.str();
}
-std::string toString(const FontFeature& feature) {
- std::stringstream ss;
- ss << feature;
- return ss.str();
-}
-
-std::string toString(const std::vector<FontFeature>& features) {
- std::stringstream ss;
- ss << features;
- return ss.str();
-}
-
std::string toString(const LayoutPiece& layout) {
std::stringstream ss;
ss << "{advance=" << layout.advance() << ", extent=" << toString(layout.extent())
diff --git a/libs/minikin/FeatureFlags.h b/libs/minikin/FeatureFlags.h
index f1da23d..3c2e455 100644
--- a/libs/minikin/FeatureFlags.h
+++ b/libs/minikin/FeatureFlags.h
@@ -39,14 +39,6 @@ inline bool word_style_auto() {
#endif // __ANDROID__
}
-inline bool inter_character_justification() {
-#ifdef __ANDROID__
- return com_android_text_flags_inter_character_justification();
-#else
- return true;
-#endif // __ANDROID__
-}
-
} // namespace features
#endif // FEATURE_FLAGS
diff --git a/libs/minikin/FontFeatureUtils.cpp b/libs/minikin/FontFeatureUtils.cpp
index cc0749a..e1ec065 100644
--- a/libs/minikin/FontFeatureUtils.cpp
+++ b/libs/minikin/FontFeatureUtils.cpp
@@ -14,29 +14,12 @@
* limitations under the License.
*/
+#include "FontFeatureUtils.h"
+
#include "StringPiece.h"
-#include "minikin/FontFeature.h"
-#include "minikin/MinikinPaint.h"
namespace minikin {
-std::vector<FontFeature> FontFeature::parse(std::string_view fontFeatureSettings) {
- std::vector<FontFeature> features;
-
- SplitIterator it(StringPiece(fontFeatureSettings), ',');
- while (it.hasNext()) {
- StringPiece featureStr = it.next();
- static hb_feature_t feature;
- // We do not allow setting features on ranges. As such, reject any setting that has
- // non-universal range.
- if (hb_feature_from_string(featureStr.data(), featureStr.size(), &feature) &&
- feature.start == 0 && feature.end == (unsigned int)-1) {
- features.push_back({feature.tag, feature.value});
- }
- }
- return features;
-}
-
std::vector<hb_feature_t> cleanAndAddDefaultFontFeatures(const MinikinPaint& paint) {
std::vector<hb_feature_t> features;
// Disable default-on non-required ligature features if letter-spacing
@@ -57,17 +40,27 @@ std::vector<hb_feature_t> cleanAndAddDefaultFontFeatures(const MinikinPaint& pai
static constexpr hb_tag_t halt_tag = HB_TAG('h', 'a', 'l', 't');
static constexpr hb_tag_t palt_tag = HB_TAG('p', 'a', 'l', 't');
- for (const FontFeature& feature : paint.fontFeatureSettings) {
- // OpenType requires disabling default `chws` feature if glyph-width features.
- // https://docs.microsoft.com/en-us/typography/opentype/spec/features_ae#tag-chws
- // Here, we follow Chrome's impl: not enabling default `chws` feature if `palt` or
- // `halt` is enabled.
- // https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/platform/fonts/shaping/font_features.cc;drc=77a9a09de0688ca449f5333a305ceaf3f36b6daf;l=215
- if (feature.tag == chws_tag ||
- (feature.value && (feature.tag == halt_tag || feature.tag == palt_tag))) {
- default_enable_chws = false;
+ SplitIterator it(paint.fontFeatureSettings, ',');
+ while (it.hasNext()) {
+ StringPiece featureStr = it.next();
+ static hb_feature_t feature;
+ // We do not allow setting features on ranges. As such, reject any setting that has
+ // non-universal range.
+ if (hb_feature_from_string(featureStr.data(), featureStr.size(), &feature) &&
+ feature.start == 0 && feature.end == (unsigned int)-1) {
+ // OpenType requires disabling default `chws` feature if glyph-width features.
+ // https://docs.microsoft.com/en-us/typography/opentype/spec/features_ae#tag-chws
+ // Here, we follow Chrome's impl: not enabling default `chws` feature if `palt` or
+ // `halt` is enabled.
+ // https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/platform/fonts/shaping/font_features.cc;drc=77a9a09de0688ca449f5333a305ceaf3f36b6daf;l=215
+ if (default_enable_chws &&
+ (feature.tag == chws_tag ||
+ (feature.value && (feature.tag == halt_tag || feature.tag == palt_tag)))) {
+ default_enable_chws = false;
+ }
+
+ features.push_back(feature);
}
- features.push_back({feature.tag, feature.value, 0, ~0u});
}
if (default_enable_chws) {
diff --git a/libs/minikin/FontFeatureUtils.h b/libs/minikin/FontFeatureUtils.h
new file mode 100644
index 0000000..1a02173
--- /dev/null
+++ b/libs/minikin/FontFeatureUtils.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MINIKIN_FONT_FEATURE_UTILS_H
+#define MINIKIN_FONT_FEATURE_UTILS_H
+
+#include <hb.h>
+
+#include "minikin/MinikinPaint.h"
+
+namespace minikin {
+
+/**
+ * Returns the final set of font features based on the features requested by this paint object and
+ * extra defaults or implied font features.
+ *
+ * Features are included from the paint object if they are:
+ * 1) in a supported range
+ *
+ * Default features are added based if they are:
+ * 1) implied due to Paint settings such as letterSpacing
+ * 2) default features that do not conflict with requested features
+ */
+std::vector<hb_feature_t> cleanAndAddDefaultFontFeatures(const MinikinPaint& paint);
+
+} // namespace minikin
+#endif // MINIKIN_LAYOUT_UTILS_H
diff --git a/libs/minikin/LayoutCore.cpp b/libs/minikin/LayoutCore.cpp
index 10c932a..b89958e 100644
--- a/libs/minikin/LayoutCore.cpp
+++ b/libs/minikin/LayoutCore.cpp
@@ -34,11 +34,11 @@
#include <vector>
#include "BidiUtils.h"
+#include "FontFeatureUtils.h"
#include "LayoutUtils.h"
#include "LocaleListCache.h"
#include "MinikinInternal.h"
#include "minikin/Emoji.h"
-#include "minikin/FontFeature.h"
#include "minikin/HbUtils.h"
#include "minikin/LayoutCache.h"
#include "minikin/LayoutPieces.h"
diff --git a/libs/minikin/MinikinInternal.cpp b/libs/minikin/MinikinInternal.cpp
index 5b81406..d02f71f 100644
--- a/libs/minikin/MinikinInternal.cpp
+++ b/libs/minikin/MinikinInternal.cpp
@@ -17,12 +17,9 @@
#define LOG_TAG "Minikin"
-#include "MinikinInternal.h"
-
#include <log/log.h>
-#include "FeatureFlags.h"
-#include "minikin/MinikinPaint.h"
+#include "MinikinInternal.h"
namespace minikin {
@@ -48,12 +45,4 @@ bool isVariationSelector(uint32_t codePoint) {
return isBMPVariationSelector(codePoint) || isVariationSelectorSupplement(codePoint);
}
-bool MinikinPaint::skipCache() const {
- if (features::inter_character_justification()) {
- return false; // if the flag is on, do not skip the cache.
- } else {
- return !fontFeatureSettings.empty();
- }
-}
-
} // namespace minikin
diff --git a/libs/minikin/StringPiece.h b/libs/minikin/StringPiece.h
index 84c7d17..befb312 100644
--- a/libs/minikin/StringPiece.h
+++ b/libs/minikin/StringPiece.h
@@ -29,7 +29,6 @@ public:
StringPiece(const char* data) : mData(data), mLength(data == nullptr ? 0 : strlen(data)) {}
StringPiece(const char* data, size_t length) : mData(data), mLength(length) {}
StringPiece(const std::string& str) : mData(str.data()), mLength(str.size()) {}
- StringPiece(std::string_view str) : mData(str.data()), mLength(str.size()) {}
inline const char* data() const { return mData; }
inline size_t length() const { return mLength; }