summaryrefslogtreecommitdiff
path: root/libs/minikin
diff options
context:
space:
mode:
authorSeigo Nonaka <nona@google.com>2023-07-18 15:51:35 +0900
committerSeigo Nonaka <nona@google.com>2023-07-19 22:16:06 +0900
commit6b35a3749ae57f129cd90d207aebba95045e6c8c (patch)
tree3c9f0bc5f2ac979a5bf2ce548ff4d02662a0bcfa /libs/minikin
parentffa85d423d839d11f43d615f070bef4363bf10bf (diff)
downloadminikin-6b35a3749ae57f129cd90d207aebba95045e6c8c.tar.gz
Reorganize structs and add debug methods
Bug: N/A Test: minikin_tests Change-Id: I06260a4a90e2c969bfd5667868638067b6c3dc06
Diffstat (limited to 'libs/minikin')
-rw-r--r--libs/minikin/Android.bp5
-rw-r--r--libs/minikin/Debug.cpp109
2 files changed, 113 insertions, 1 deletions
diff --git a/libs/minikin/Android.bp b/libs/minikin/Android.bp
index 5c7abf2..f5af693 100644
--- a/libs/minikin/Android.bp
+++ b/libs/minikin/Android.bp
@@ -68,7 +68,10 @@ cc_library {
product_variables: {
debuggable: {
// Enable assertion on eng and userdebug build.
- cppflags: ["-DENABLE_ASSERTION"],
+ srcs: [
+ "Debug.cpp",
+ ],
+ cppflags: [ "-DENABLE_ASSERTION" ],
},
},
shared_libs: [
diff --git a/libs/minikin/Debug.cpp b/libs/minikin/Debug.cpp
new file mode 100644
index 0000000..6c48a39
--- /dev/null
+++ b/libs/minikin/Debug.cpp
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2023 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.
+ */
+
+#include "minikin/Debug.h"
+
+#include <unicode/utf16.h>
+#include <unicode/utf8.h>
+
+#include <sstream>
+
+#include "minikin/FontFileParser.h"
+#include "minikin/LayoutCore.h"
+#include "minikin/LocaleList.h"
+#include "minikin/MinikinExtent.h"
+#include "minikin/MinikinPaint.h"
+#include "minikin/MinikinRect.h"
+#include "minikin/Point.h"
+#include "minikin/Range.h"
+#include "minikin/U16StringPiece.h"
+
+namespace minikin {
+
+namespace debug {
+
+std::string toUtf8(const U16StringPiece& text) {
+ std::string output;
+ output.resize(text.size() * 4);
+ uint32_t in_i = 0;
+ uint32_t out_i = 0;
+ bool isError = false;
+
+ while (in_i < text.size()) {
+ uint32_t ch;
+ U16_NEXT(text, in_i, text.size(), ch);
+ U8_APPEND(output, out_i, output.size(), ch, isError);
+ if (isError) {
+ return "";
+ }
+ }
+
+ output.resize(out_i);
+ return output;
+}
+
+std::string toString(const Point& point) {
+ std::stringstream ss;
+ ss << point;
+ return ss.str();
+}
+
+std::string toString(const MinikinRect& rect) {
+ std::stringstream ss;
+ ss << rect;
+ return ss.str();
+}
+
+std::string toString(const Range& range) {
+ std::stringstream ss;
+ ss << range;
+ return ss.str();
+}
+
+std::string toString(const MinikinExtent& extent) {
+ std::stringstream ss;
+ ss << extent;
+ return ss.str();
+}
+
+std::string toString(const LayoutPiece& layout) {
+ std::stringstream ss;
+ ss << "advance=" << layout.advance() << ", extent=" << toString(layout.extent()) << ", glyphs=";
+
+ for (uint32_t i = 0; i < layout.glyphCount(); ++i) {
+ ss << "{id:" << layout.glyphIdAt(i) << ", pos = " << toString(layout.pointAt(i))
+ << ", font = \""
+ << FontFileParser(layout.fontAt(i).hbFont()).getPostScriptName().value_or("[UNKNOWN]")
+ << "\"}, ";
+ }
+ return ss.str();
+}
+
+std::string toString(const MinikinPaint& paint) {
+ std::stringstream ss;
+ ss << "{size=" << paint.size << ", scaleX=" << paint.scaleX << ", skewX=" << paint.skewX
+ << ", letterSpacing=" << paint.letterSpacing << ", wordSpacing=" << paint.wordSpacing
+ << ", fontFlags=" << paint.fontFlags
+ << ", localeList=" << getLocaleString(paint.localeListId)
+ << ", fontStyle=" << paint.fontStyle << ", familyVariant=" << paint.familyVariant
+ << ", fontFeatureSettings=" << paint.fontFeatureSettings
+ << ", fontCollectionId=" << paint.font->getId();
+ return ss.str();
+}
+
+} // namespace debug
+
+} // namespace minikin