From cd404cb5e1aed30b46a7af7ddb91ba6e126fe4c2 Mon Sep 17 00:00:00 2001 From: Chad Jones Date: Fri, 19 Apr 2013 10:28:48 -0700 Subject: [PATCH 001/364] Initial empty repository From c1a6032ce6990fe982cddf67e1902fdad4fb398b Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 23 Apr 2013 15:45:41 -0700 Subject: [PATCH 002/364] Initial commit of Minikin library This is the initial draft of Minikin, a library intended to perform text layout functions. This version does basic weight selection and font runs for scripts, and also has a simple renderer for drawing into bitmaps, but is lacking measurement, line breaking, and a number of other important features. It also lacks caching and other performance refinements. Change-Id: I789a2e47d11d71202dc84b4751b51a5e2cd9c451 --- .../flutter/include/minikin/AnalyzeStyle.h | 26 ++ .../flutter/include/minikin/CmapCoverage.h | 31 ++ engine/src/flutter/include/minikin/CssParse.h | 86 ++++++ .../flutter/include/minikin/FontCollection.h | 90 ++++++ .../src/flutter/include/minikin/FontFamily.h | 67 +++++ engine/src/flutter/include/minikin/Layout.h | 89 ++++++ .../flutter/include/minikin/SparseBitSet.h | 92 ++++++ .../src/flutter/libs/minikin/AnalyzeStyle.cpp | 43 +++ engine/src/flutter/libs/minikin/Android.mk | 43 +++ .../src/flutter/libs/minikin/CmapCoverage.cpp | 179 ++++++++++++ engine/src/flutter/libs/minikin/CssParse.cpp | 162 +++++++++++ .../flutter/libs/minikin/FontCollection.cpp | 150 ++++++++++ .../src/flutter/libs/minikin/FontFamily.cpp | 95 +++++++ engine/src/flutter/libs/minikin/Layout.cpp | 264 ++++++++++++++++++ .../src/flutter/libs/minikin/SparseBitSet.cpp | 147 ++++++++++ engine/src/flutter/sample/Android.mk | 42 +++ engine/src/flutter/sample/example.cpp | 100 +++++++ 17 files changed, 1706 insertions(+) create mode 100644 engine/src/flutter/include/minikin/AnalyzeStyle.h create mode 100644 engine/src/flutter/include/minikin/CmapCoverage.h create mode 100644 engine/src/flutter/include/minikin/CssParse.h create mode 100644 engine/src/flutter/include/minikin/FontCollection.h create mode 100644 engine/src/flutter/include/minikin/FontFamily.h create mode 100644 engine/src/flutter/include/minikin/Layout.h create mode 100644 engine/src/flutter/include/minikin/SparseBitSet.h create mode 100644 engine/src/flutter/libs/minikin/AnalyzeStyle.cpp create mode 100644 engine/src/flutter/libs/minikin/Android.mk create mode 100644 engine/src/flutter/libs/minikin/CmapCoverage.cpp create mode 100644 engine/src/flutter/libs/minikin/CssParse.cpp create mode 100644 engine/src/flutter/libs/minikin/FontCollection.cpp create mode 100644 engine/src/flutter/libs/minikin/FontFamily.cpp create mode 100644 engine/src/flutter/libs/minikin/Layout.cpp create mode 100644 engine/src/flutter/libs/minikin/SparseBitSet.cpp create mode 100644 engine/src/flutter/sample/Android.mk create mode 100644 engine/src/flutter/sample/example.cpp diff --git a/engine/src/flutter/include/minikin/AnalyzeStyle.h b/engine/src/flutter/include/minikin/AnalyzeStyle.h new file mode 100644 index 00000000000..298947742ae --- /dev/null +++ b/engine/src/flutter/include/minikin/AnalyzeStyle.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2013 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_ANALYZE_STYLE_H +#define MINIKIN_ANALYZE_STYLE_H + +namespace android { + +bool analyzeStyle(const uint8_t* os2_data, size_t os2_size, int* weight, bool* italic); + +} // namespace android + +#endif // MINIKIN_ANALYZE_STYLE_H \ No newline at end of file diff --git a/engine/src/flutter/include/minikin/CmapCoverage.h b/engine/src/flutter/include/minikin/CmapCoverage.h new file mode 100644 index 00000000000..7054e315fdc --- /dev/null +++ b/engine/src/flutter/include/minikin/CmapCoverage.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2013 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_CMAP_COVERAGE_H +#define MINIKIN_CMAP_COVERAGE_H + +#include + +namespace android { + +class CmapCoverage { +public: + static bool getCoverage(SparseBitSet &coverage, const uint8_t* cmap_data, size_t cmap_size); +}; + +} // namespace android + +#endif // MINIKIN_CMAP_COVERAGE_H diff --git a/engine/src/flutter/include/minikin/CssParse.h b/engine/src/flutter/include/minikin/CssParse.h new file mode 100644 index 00000000000..f79ba1f61ca --- /dev/null +++ b/engine/src/flutter/include/minikin/CssParse.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2013 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_CSS_PARSE_H +#define MINIKIN_CSS_PARSE_H + +#include +#include + +namespace android { + +enum CssTag { + unknown, + fontSize, + fontWeight, + fontStyle, + minikinHinting, +}; + +const std::string cssTagNames[] = { + "unknown", + "font-size", + "font-weight", + "font-style", + "-minikin-hinting", +}; + +class CssValue { +public: + enum Type { + UNKNOWN, + FLOAT + }; + enum Units { + SCALAR, + PERCENT, + PX, + EM + }; + CssValue() : mType(UNKNOWN) { } + explicit CssValue(double v) : + mType(FLOAT), floatValue(v), mUnits(SCALAR) { } + Type getType() const { return mType; } + double getFloatValue() const { return floatValue; } + int getIntValue() const { return floatValue; } + std::string toString(CssTag tag) const; + void setFloatValue(double v) { + mType = FLOAT; + floatValue = v; + } +private: + Type mType; + double floatValue; + Units mUnits; +}; + +class CssProperties { +public: + bool parse(const std::string& str); + bool hasTag(CssTag tag) const; + CssValue value(CssTag tag) const; + + // primarily for debugging + std::string toString() const; +private: + // We'll use STL map for now but can replace it with something + // more efficient if needed + std::map mMap; +}; + +} // namespace android + +#endif // MINIKIN_CSS_PARSE_H \ No newline at end of file diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h new file mode 100644 index 00000000000..3aa2acace21 --- /dev/null +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2013 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_COLLECTION_H +#define MINIKIN_FONT_COLLECTION_H + +#include + +#include +#include FT_FREETYPE_H +#include FT_TRUETYPE_TABLES_H + +#include "SparseBitSet.h" +#include "FontFamily.h" + +namespace android { + +class FontCollection { +public: + explicit FontCollection(const std::vector& typefaces); + + ~FontCollection(); + + const FontFamily* getFamilyForChar(uint32_t ch) const; + class Run { + public: + // Do copy constructor, assignment, destructor so it can be used in vectors + Run() : font(NULL) { } + Run(const Run& other): font(other.font), start(other.start), end(other.end) { + if (font) FT_Reference_Face(font); + } + Run& operator=(const Run& other) { + if (other.font) FT_Reference_Face(other.font); + if (font) FT_Done_Face(font); + font = other.font; + start = other.start; + end = other.end; + return *this; + } + ~Run() { if (font) FT_Done_Face(font); } + + FT_Face font; + int start; + int end; + }; + void itemize(const uint16_t *string, size_t string_length, FontStyle style, + std::vector* result) const; + private: + static const int kLogCharsPerPage = 8; + static const int kPageMask = (1 << kLogCharsPerPage) - 1; + + struct FontInstance { + SparseBitSet* mCoverage; + FontFamily* mFamily; + }; + + struct Range { + size_t start; + size_t end; + }; + + // Highest UTF-32 code point that can be mapped + uint32_t mMaxChar; + + // This vector has ownership of the bitsets and typeface objects. + std::vector mInstances; + + // This vector contains pointers into mInstances + std::vector mInstanceVec; + + // These are offsets into mInstanceVec, one range per page + std::vector mRanges; +}; + +} // namespace android + +#endif // MINIKIN_FONT_COLLECTION_H diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h new file mode 100644 index 00000000000..01ea2322521 --- /dev/null +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2013 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_FAMILY_H +#define MINIKIN_FONT_FAMILY_H + +#include + +namespace android { + +// FontStyle represents all style information needed to select an actual font +// from a collection. The implementation is packed into a single 32-bit word +// so it can be efficiently copied, embedded in other objects, etc. +class FontStyle { +public: + FontStyle(int weight = 4, bool italic = false) { + bits = (weight & kWeightMask) | (italic ? kItalicMask : 0); + } + int getWeight() { return bits & kWeightMask; } + bool getItalic() { return (bits & kItalicMask) != 0; } + bool operator==(const FontStyle other) { return bits == other.bits; } + // TODO: language, variant +private: + static const int kWeightMask = 0xf; + static const int kItalicMask = 16; + uint32_t bits; +}; + +class FontFamily { +public: + // Add font to family, extracting style information from the font + bool addFont(FT_Face typeface); + + void addFont(FT_Face typeface, FontStyle style); + FT_Face getClosestMatch(FontStyle style) const; + + // API's for enumerating the fonts in a family. These don't guarantee any particular order + size_t getNumFonts() const; + FT_Face getFont(size_t index) const; + FontStyle getStyle(size_t index) const; +private: + class Font { + public: + Font(FT_Face typeface, FontStyle style) : + typeface(typeface), style(style) { } + FT_Face typeface; + FontStyle style; + }; + std::vector mFonts; +}; + +} // namespace android + +#endif // MINIKIN_FONT_FAMILY_H diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h new file mode 100644 index 00000000000..7a6c6cfc25b --- /dev/null +++ b/engine/src/flutter/include/minikin/Layout.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2013 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_LAYOUT_H +#define MINIKIN_LAYOUT_H + +#include +#include FT_FREETYPE_H + +#include + +#include + +#include +#include + +namespace android { + +// The Bitmap class is for debugging. We'll probably move it out +// of here into a separate lightweight software rendering module +// (optional, as we'd hope most clients would do their own) +class Bitmap { +public: + Bitmap(int width, int height); + ~Bitmap(); + void writePnm(std::ofstream& o) const; + void drawGlyph(const FT_Bitmap& bitmap, int x, int y); +private: + int width; + int height; + uint8_t* buf; +}; + +struct LayoutGlyph { + // index into mFaces and mHbFonts vectors. We could imagine + // moving this into a run length representation, because it's + // more efficient for long strings, and we'll probably need + // something like that for paint attributes (color, underline, + // fake b/i, etc), as having those per-glyph is bloated. + int font_ix; + + unsigned int glyph_id; + float x; + float y; +}; + +class Layout { +public: + void dump() const; + void setFontCollection(const FontCollection *collection); + void doLayout(const uint16_t* buf, size_t nchars); + void draw(Bitmap*, int x0, int y0) const; + void setProperties(const std::string css); + + // This must be called before any invocations. + // TODO: probably have a factory instead + static void init(); +private: + // Find a face in the mFaces vector, or create a new entry + int findFace(FT_Face face); + + CssProperties mProps; // TODO: want spans + std::vector mGlyphs; + + // In future, this will be some kind of mapping from the + // identifier used to represent font-family to a font collection. + // But for the time being, it should be ok to have just one + // per layout. + const FontCollection *mCollection; + std::vector mFaces; + std::vector mHbFonts; +}; + +} // namespace android + +#endif // MINIKIN_LAYOUT_H diff --git a/engine/src/flutter/include/minikin/SparseBitSet.h b/engine/src/flutter/include/minikin/SparseBitSet.h new file mode 100644 index 00000000000..4004606f1df --- /dev/null +++ b/engine/src/flutter/include/minikin/SparseBitSet.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2012 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_SPARSE_BIT_SET_H +#define MINIKIN_SPARSE_BIT_SET_H + +#include +#include +#include "utils/UniquePtr.h" + +// --------------------------------------------------------------------------- + +namespace android { + +// This is an implementation of a set of integers. It is optimized for +// values that are somewhat sparse, in the ballpark of a maximum value +// of thousands to millions. It is particularly efficient when there are +// large gaps. The motivating example is Unicode coverage of a font, but +// the abstraction itself is fully general. + +class SparseBitSet { +public: + SparseBitSet(): mMaxVal(0) { + } + + // Clear the set + void clear(); + + // Initialize the set to a new value, represented by ranges. For + // simplicity, these ranges are arranged as pairs of values, + // inclusive of start, exclusive of end, laid out in a uint32 array. + void initFromRanges(const uint32_t* ranges, size_t nRanges); + + // Determine whether the value is included in the set + bool get(uint32_t ch) const { + if (ch >= mMaxVal) return false; + uint32_t *bitmap = &mBitmaps[mIndices[ch >> kLogValuesPerPage]]; + uint32_t index = ch & kPageMask; + return (bitmap[index >> kLogBitsPerEl] & (kElFirst >> (index & kElMask))) != 0; + } + + // One more than the maximum value in the set, or zero if empty + uint32_t length() const { + return mMaxVal; + } + + // The next set bit starting at fromIndex, inclusive, or kNotFound + // if none exists. + uint32_t nextSetBit(uint32_t fromIndex) const; + + static const uint32_t kNotFound = ~0u; + +private: + static const int kLogValuesPerPage = 8; + static const int kPageMask = (1 << kLogValuesPerPage) - 1; + static const int kLogBytesPerEl = 2; + static const int kLogBitsPerEl = kLogBytesPerEl + 3; + static const int kElMask = (1 << kLogBitsPerEl) - 1; + // invariant: sizeof(element) == (1 << kLogBytesPerEl) + typedef uint32_t element; + static const element kElAllOnes = ~((element)0); + static const element kElFirst = ((element)1) << kElMask; + static const uint32_t noZeroPage = ~0u; + + static uint32_t calcNumPages(const uint32_t* ranges, size_t nRanges); + static int CountLeadingZeros(element x); + + uint32_t mMaxVal; + UniquePtr mIndices; + UniquePtr mBitmaps; + uint32_t mZeroPageIndex; +}; + +// Note: this thing cannot be used in vectors yet. If that were important, we'd need to +// make the copy constructor work, and probably set up move traits as well. + +}; // namespace android + +#endif // MINIKIN_SPARSE_BIT_SET_H diff --git a/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp b/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp new file mode 100644 index 00000000000..09616452907 --- /dev/null +++ b/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2013 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 +#include + +#include + +namespace android { + +// should we have a single FontAnalyzer class this stuff lives in, to avoid dup? +static int32_t readU16(const uint8_t* data, size_t offset) { + return data[offset] << 8 | data[offset + 1]; +} + +bool analyzeStyle(const uint8_t* os2_data, size_t os2_size, int* weight, bool* italic) { + const size_t kUsWeightClassOffset = 4; + const size_t kFsSelectionOffset = 62; + const uint16_t kItalicFlag = (1 << 0); + if (os2_size < kFsSelectionOffset + 2) { + return false; + } + uint16_t weightClass = readU16(os2_data, kUsWeightClassOffset); + *weight = weightClass / 100; + uint16_t fsSelection = readU16(os2_data, kFsSelectionOffset); + *italic = (fsSelection & kItalicFlag) != 0; + return true; +} + +} // namespace android diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk new file mode 100644 index 00000000000..9795ad05d02 --- /dev/null +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -0,0 +1,43 @@ +# Copyright (C) 2013 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. + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +include external/stlport/libstlport.mk + +LOCAL_SRC_FILES := \ + AnalyzeStyle.cpp \ + CmapCoverage.cpp \ + CssParse.cpp \ + FontCollection.cpp \ + FontFamily.cpp \ + Layout.cpp \ + SparseBitSet.cpp + +LOCAL_MODULE := libminikin + +LOCAL_C_INCLUDES += \ + external/harfbuzz_ng/src \ + external/freetype/include \ + frameworks/minikin/include + +LOCAL_SHARED_LIBRARIES := \ + libharfbuzz_ng \ + libstlport + +LOCAL_STATIC_LIBARIES := \ + libft2 + +include $(BUILD_STATIC_LIBRARY) diff --git a/engine/src/flutter/libs/minikin/CmapCoverage.cpp b/engine/src/flutter/libs/minikin/CmapCoverage.cpp new file mode 100644 index 00000000000..4156d69d5a1 --- /dev/null +++ b/engine/src/flutter/libs/minikin/CmapCoverage.cpp @@ -0,0 +1,179 @@ +/* + * Copyright (C) 2013 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. + */ + +// Determine coverage of font given its raw "cmap" OpenType table + +#ifdef PRINTF_DEBUG +#include +#endif + +#include +using std::vector; + +#include +#include + +namespace android { + +// These could perhaps be optimized to use __builtin_bswap16 and friends. +static uint32_t readU16(const uint8_t* data, size_t offset) { + return data[offset] << 8 | data[offset + 1]; +} + +static uint32_t readU32(const uint8_t* data, size_t offset) { + return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]; +} + +static void addRange(vector &coverage, uint32_t start, uint32_t end) { +#ifdef PRINTF_DEBUG + printf("adding range %d-%d\n", start, end); +#endif + if (coverage.empty() || coverage.back() < start) { + coverage.push_back(start); + coverage.push_back(end); + } else { + coverage.back() = end; + } +} + +// Get the coverage information out of a Format 12 subtable, storing it in the coverage vector +static bool getCoverageFormat4(vector& coverage, const uint8_t* data, size_t size) { + const size_t kSegCountOffset = 6; + const size_t kEndCountOffset = 14; + const size_t kHeaderSize = 16; + const size_t kSegmentSize = 8; // total size of array elements for one segment + if (kEndCountOffset > size) { + return false; + } + size_t segCount = readU16(data, kSegCountOffset) >> 1; + if (kHeaderSize + segCount * kSegmentSize > size) { + return false; + } + for (size_t i = 0; i < segCount; i++) { + int end = readU16(data, kEndCountOffset + 2 * i); + int start = readU16(data, kHeaderSize + 2 * (segCount + i)); + int rangeOffset = readU16(data, kHeaderSize + 2 * (3 * segCount + i)); + if (rangeOffset == 0) { + int delta = readU16(data, kHeaderSize + 2 * (2 * segCount + i)); + if (((end + delta) & 0xffff) > end - start) { + addRange(coverage, start, end + 1); + } else { + for (int j = start; j < end + 1; j++) { + if (((j + delta) & 0xffff) != 0) { + addRange(coverage, j, j + 1); + } + } + } + } else { + for (int j = start; j < end + 1; j++) { + uint32_t actualRangeOffset = kHeaderSize + 6 * segCount + rangeOffset + + (i + j - start) * 2; + if (actualRangeOffset + 2 > size) { + return false; + } + int glyphId = readU16(data, actualRangeOffset); + if (glyphId != 0) { + addRange(coverage, j, j + 1); + } + } + } + } + return true; +} + +// Get the coverage information out of a Format 12 subtable, storing it in the coverage vector +static bool getCoverageFormat12(vector& coverage, const uint8_t* data, size_t size) { + const size_t kNGroupsOffset = 12; + const size_t kFirstGroupOffset = 16; + const size_t kGroupSize = 12; + const size_t kStartCharCodeOffset = 0; + const size_t kEndCharCodeOffset = 4; + if (kFirstGroupOffset > size) { + return false; + } + uint32_t nGroups = readU32(data, kNGroupsOffset); + if (kFirstGroupOffset + nGroups * kGroupSize > size) { + return false; + } + for (uint32_t i = 0; i < nGroups; i++) { + uint32_t groupOffset = kFirstGroupOffset + i * kGroupSize; + uint32_t start = readU32(data, groupOffset + kStartCharCodeOffset); + uint32_t end = readU32(data, groupOffset + kEndCharCodeOffset); + addRange(coverage, start, end + 1); // file is inclusive, vector is exclusive + } + return true; +} + +bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, size_t cmap_size) { + vector coverageVec; + const size_t kHeaderSize = 4; + const size_t kNumTablesOffset = 2; + const size_t kTableSize = 8; + const size_t kPlatformIdOffset = 0; + const size_t kEncodingIdOffset = 2; + const size_t kOffsetOffset = 4; + const int kMicrosoftPlatformId = 3; + const int kUnicodeBmpEncodingId = 1; + const int kUnicodeUcs4EncodingId = 10; + if (kHeaderSize > cmap_size) { + return false; + } + int numTables = readU16(cmap_data, kNumTablesOffset); + if (kHeaderSize + numTables * kTableSize > cmap_size) { + return false; + } + int bestTable = -1; + for (int i = 0; i < numTables; i++) { + uint16_t platformId = readU16(cmap_data, kHeaderSize + i * kTableSize + kPlatformIdOffset); + uint16_t encodingId = readU16(cmap_data, kHeaderSize + i * kTableSize + kEncodingIdOffset); + if (platformId == kMicrosoftPlatformId && encodingId == kUnicodeUcs4EncodingId) { + bestTable = i; + break; + } else if (platformId == kMicrosoftPlatformId && encodingId == kUnicodeBmpEncodingId) { + bestTable = i; + } + } +#ifdef PRINTF_DEBUG + printf("best table = %d\n", bestTable); +#endif + if (bestTable < 0) { + return false; + } + uint32_t offset = readU32(cmap_data, kHeaderSize + bestTable * kTableSize + kOffsetOffset); + if (offset + 2 > cmap_size) { + return false; + } + uint16_t format = readU16(cmap_data, offset); + bool success = false; + const uint8_t* tableData = cmap_data + offset; + const size_t tableSize = cmap_size - offset; + if (format == 4) { + success = getCoverageFormat4(coverageVec, tableData, tableSize); + } else if (format == 12) { + success = getCoverageFormat12(coverageVec, tableData, tableSize); + } + if (success) { + coverage.initFromRanges(&coverageVec.front(), coverageVec.size() >> 1); + } +#ifdef PRINTF_DEBUG + for (int i = 0; i < coverageVec.size(); i += 2) { + printf("%x:%x\n", coverageVec[i], coverageVec[i + 1]); + } +#endif + return success; +} + +} // namespace android diff --git a/engine/src/flutter/libs/minikin/CssParse.cpp b/engine/src/flutter/libs/minikin/CssParse.cpp new file mode 100644 index 00000000000..d4de23bee05 --- /dev/null +++ b/engine/src/flutter/libs/minikin/CssParse.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2013 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 +#include +#include +#include // for sprintf - for debugging + +#include + +using std::map; +using std::pair; +using std::string; + +namespace android { + +bool strEqC(const string str, size_t off, size_t len, const char* str2) { + if (len != strlen(str2)) return false; + return !memcmp(str.data() + off, str2, len); +} + +CssTag parseTag(const string str, size_t off, size_t len) { + if (len == 0) return unknown; + char c = str[off]; + if (c == 'f') { + if (strEqC(str, off, len, "font-size")) return fontSize; + if (strEqC(str, off, len, "font-weight")) return fontWeight; + if (strEqC(str, off, len, "font-style")) return fontStyle; + } else if (c == '-') { + if (strEqC(str, off, len, "-minikin-hinting")) return minikinHinting; + } + return unknown; +} + +bool parseValue(const string str, size_t *off, size_t len, CssTag tag, + CssValue* v) { + const char* data = str.data(); + char* endptr; + double fv = strtod(data + *off, &endptr); + if (endptr == data + *off) { + // No numeric value, try tag-specific idents + size_t end; + for (end = *off; end < len; end++) { + char c = data[end]; + if (c != '-' && !(c >= 'a' && c <= 'z') && + !(c >= '0' && c <= '9')) break; + } + size_t taglen = end - *off; + endptr += taglen; + if (tag == fontStyle) { + if (strEqC(str, *off, taglen, "normal")) { + fv = 0; + } else if (strEqC(str, *off, taglen, "italic")) { + fv = 1; + // TODO: oblique, but who really cares? + } else { + return false; + } + } else if (tag == fontWeight) { + if (strEqC(str, *off, taglen, "normal")) { + fv = 400; + } else if (strEqC(str, *off, taglen, "bold")) { + fv = 700; + } else { + return false; + } + } else { + return false; + } + } + v->setFloatValue(fv); + *off = endptr - data; + return true; +} + +string CssValue::toString(CssTag tag) const { + if (mType == FLOAT) { + if (tag == fontStyle) { + return floatValue ? "italic" : "normal"; + } + char buf[64]; + sprintf(buf, "%g", floatValue); + return string(buf); + } + return ""; +} + +bool CssProperties::parse(const string& str) { + size_t len = str.size(); + size_t i = 0; + while (true) { + size_t j = i; + while (j < len && str[j] == ' ') j++; + if (j == len) break; + size_t k = str.find_first_of(':', j); + if (k == string::npos) { + return false; // error: junk after end + } + CssTag tag = parseTag(str, j, k - j); +#ifdef VERBOSE + printf("parseTag result %d, ijk %lu %lu %lu\n", tag, i, j, k); +#endif + if (tag == unknown) return false; // error: unknown tag + k++; // skip over colon + while (k < len && str[k] == ' ') k++; + if (k == len) return false; // error: missing value + CssValue v; + if (!parseValue(str, &k, len, tag, &v)) break; +#ifdef VERBOSE + printf("parseValue ok\n"); +#endif + mMap.insert(pair(tag, v)); + while (k < len && str[k] == ' ') k++; + if (k < len) { + if (str[k] != ';') return false; + k++; + } + i = k; + } + return true; +} + +bool CssProperties::hasTag(CssTag tag) const { + return (mMap.find(tag) != mMap.end()); +} + +CssValue CssProperties::value(CssTag tag) const { + map::const_iterator it = mMap.find(tag); + if (it == mMap.end()) { + CssValue unknown; + return unknown; + } else { + return it->second; + } +} + +string CssProperties::toString() const { + string result; + for (map::const_iterator it = mMap.begin(); + it != mMap.end(); it++) { + result += cssTagNames[it->first]; + result += ": "; + result += it->second.toString(it->first); + result += ";\n"; + } + return result; +} + +} // namespace android diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp new file mode 100644 index 00000000000..7abbd3b3025 --- /dev/null +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2013 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. + */ + +#ifdef VERBOSE_DEBUG +#include // for debugging - remove +#endif + +#include +#include + +using std::vector; + +namespace android { + +template +static inline T max(T a, T b) { + return a>b ? a : b; +} + +FontCollection::FontCollection(const vector& typefaces) : + mMaxChar(0) { + vector lastChar; + size_t nTypefaces = typefaces.size(); +#ifdef VERBOSE_DEBUG + printf("nTypefaces = %d\n", nTypefaces); +#endif + const FontStyle defaultStyle; + for (size_t i = 0; i < nTypefaces; i++) { + FontFamily* family = typefaces[i]; + FontInstance dummy; + mInstances.push_back(dummy); // emplace_back would be better + FontInstance* instance = &mInstances.back(); + instance->mFamily = family; + instance->mCoverage = new SparseBitSet; + FT_Face typeface = family->getClosestMatch(defaultStyle); +#ifdef VERBOSE_DEBUG + printf("closest match = %x, family size = %d\n", typeface, family->getNumFonts()); +#endif + const uint32_t cmapTag = FT_MAKE_TAG('c', 'm', 'a', 'p'); + FT_ULong cmapSize = 0; + FT_Error error = FT_Load_Sfnt_Table(typeface, cmapTag, 0, NULL, &cmapSize); + UniquePtr cmapData(new uint8_t[cmapSize]); + error = FT_Load_Sfnt_Table(typeface, cmapTag, 0, + cmapData.get(), &cmapSize); + CmapCoverage::getCoverage(*instance->mCoverage, cmapData.get(), cmapSize); +#ifdef VERBOSE_DEBUG + printf("font coverage length=%d, first ch=%x\n", instance->mCoverage->length(), + instance->mCoverage->nextSetBit(0)); +#endif + mMaxChar = max(mMaxChar, instance->mCoverage->length()); + lastChar.push_back(instance->mCoverage->nextSetBit(0)); + // TODO: should probably ref typeface here, hmm + } + size_t nPages = mMaxChar >> kLogCharsPerPage; + size_t offset = 0; + for (size_t i = 0; i < nPages; i++) { + Range dummy; + mRanges.push_back(dummy); + Range* range = &mRanges.back(); +#ifdef VERBOSE_DEBUG + printf("i=%d: range start = %d\n", i, offset); +#endif + range->start = offset; + for (size_t j = 0; j < nTypefaces; j++) { + if (lastChar[j] < (i + 1) << kLogCharsPerPage) { + const FontInstance* instance = &mInstances[j]; + mInstanceVec.push_back(instance); + offset++; + uint32_t nextChar = instance->mCoverage->nextSetBit((i + 1) << kLogCharsPerPage); +#ifdef VERBOSE_DEBUG + printf("nextChar = %d (j = %d)\n", nextChar, j); +#endif + lastChar[j] = nextChar; + } + } + range->end = offset; + } +} + +FontCollection::~FontCollection() { + for (size_t i = 0; i < mInstances.size(); i++) { + delete mInstances[i].mCoverage; + // probably unref the typeface here too + } +} + +const FontFamily* FontCollection::getFamilyForChar(uint32_t ch) const { + if (ch >= mMaxChar) { + return NULL; + } + const Range& range = mRanges[ch >> kLogCharsPerPage]; +#ifdef VERBOSE_DEBUG + printf("querying range %d:%d\n", range.start, range.end); +#endif + for (size_t i = range.start; i < range.end; i++) { + const FontInstance* instance = mInstanceVec[i]; + if (instance->mCoverage->get(ch)) { + return instance->mFamily; + } + } + return NULL; +} + +void FontCollection::itemize(const uint16_t *string, size_t string_size, FontStyle style, + vector* result) const { + const FontFamily* lastFamily = NULL; + Run* run = NULL; + int nShorts; + for (size_t i = 0; i < string_size; i += nShorts) { + nShorts = 1; + uint32_t ch = string[i]; + // sigh, decode UTF-16 by hand here + if ((ch & 0xfc00) == 0xd800) { + if ((i + 1) < string_size) { + ch = 0x10000 + ((ch & 0x3ff) << 10) + (string[i + 1] & 0x3ff); + nShorts = 2; + } + } + const FontFamily* family = getFamilyForChar(ch); + if (i == 0 || family != lastFamily) { + Run dummy; + result->push_back(dummy); + run = &result->back(); + if (family == NULL) { + run->font = NULL; // maybe we should do something different here + } else { + run->font = family->getClosestMatch(style); + FT_Reference_Face(run->font); + } + lastFamily = family; + run->start = i; + } + run->end = i + nShorts; + } +} + +} // namespace android diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp new file mode 100644 index 00000000000..dc6e16ce834 --- /dev/null +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2013 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. + */ + +#define LOG_TAG "Minikin" + +#include +#include +#include +#include +#include +#include FT_FREETYPE_H +#include FT_TRUETYPE_TABLES_H +#include +#include + +using std::vector; + +namespace android { + +bool FontFamily::addFont(FT_Face typeface) { + const uint32_t os2Tag = FT_MAKE_TAG('O', 'S', '/', '2'); + FT_ULong os2Size = 0; + FT_Error error = FT_Load_Sfnt_Table(typeface, os2Tag, 0, NULL, &os2Size); + if (error != 0) return false; + UniquePtr os2Data(new uint8_t[os2Size]); + error = FT_Load_Sfnt_Table(typeface, os2Tag, 0, os2Data.get(), &os2Size); + if (error != 0) return false; + int weight; + bool italic; + if (analyzeStyle(os2Data.get(), os2Size, &weight, &italic)) { + //ALOGD("analyzed weight = %d, italic = %s", weight, italic ? "true" : "false"); + FontStyle style(weight, italic); + addFont(typeface, style); + return true; + } else { + ALOGD("failed to analyze style"); + } + return false; +} + +void FontFamily::addFont(FT_Face typeface, FontStyle style) { + mFonts.push_back(Font(typeface, style)); + ALOGD("added font, mFonts.size() = %d", mFonts.size()); +} + +// Compute a matching metric between two styles - 0 is an exact match +int computeMatch(FontStyle style1, FontStyle style2) { + if (style1 == style2) return 0; + int score = abs(style1.getWeight() - style2.getWeight()); + if (style1.getItalic() != style2.getItalic()) { + score += 2; + } + return score; +} + +FT_Face FontFamily::getClosestMatch(FontStyle style) const { + const Font* bestFont = NULL; + int bestMatch = 0; + for (size_t i = 0; i < mFonts.size(); i++) { + const Font& font = mFonts[i]; + int match = computeMatch(font.style, style); + if (i == 0 || match < bestMatch) { + bestFont = &font; + bestMatch = match; + } + } + return bestFont == NULL ? NULL : bestFont->typeface; +} + +size_t FontFamily::getNumFonts() const { + return mFonts.size(); +} + +FT_Face FontFamily::getFont(size_t index) const { + return mFonts[index].typeface; +} + +FontStyle FontFamily::getStyle(size_t index) const { + return mFonts[index].style; +} + +} // namespace android diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp new file mode 100644 index 00000000000..a8a596d7293 --- /dev/null +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -0,0 +1,264 @@ +/* + * Copyright (C) 2013 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 +#include +#include +#include // for debugging + +#include + +using std::string; +using std::vector; + +namespace android { + +// TODO: globals are not cool, move to a factory-ish object +hb_buffer_t* buffer = 0; + +Bitmap::Bitmap(int width, int height) : width(width), height(height) { + buf = new uint8_t[width * height](); +} + +Bitmap::~Bitmap() { + delete[] buf; +} + +void Bitmap::writePnm(std::ofstream &o) const { + o << "P5" << std::endl; + o << width << " " << height << std::endl; + o << "255" << std::endl; + o.write((const char *)buf, width * height); + o.close(); +} + +void Bitmap::drawGlyph(const FT_Bitmap& bitmap, int x, int y) { + int bmw = bitmap.width; + int bmh = bitmap.rows; + int x0 = std::max(0, x); + int x1 = std::min(width, x + bmw); + int y0 = std::max(0, y); + int y1 = std::min(height, y + bmh); + const unsigned char* src = bitmap.buffer + (y0 - y) * bmw + (x0 - x); + uint8_t* dst = buf + y0 * width; + for (int yy = y0; yy < y1; yy++) { + for (int xx = x0; xx < x1; xx++) { + int pixel = (int)dst[xx] + (int)src[xx - x]; + pixel = pixel > 0xff ? 0xff : pixel; + dst[xx] = pixel; + } + src += bmw; + dst += width; + } +} + +void Layout::init() { + buffer = hb_buffer_create(); +} + +void Layout::setFontCollection(const FontCollection *collection) { + mCollection = collection; +} + +hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { + FT_Face ftFace = reinterpret_cast(userData); + FT_ULong length = 0; + FT_Error error = FT_Load_Sfnt_Table(ftFace, tag, 0, NULL, &length); + if (error) { + return 0; + } + char *buffer = reinterpret_cast(malloc(length)); + if (!buffer) { + return 0; + } + error = FT_Load_Sfnt_Table(ftFace, tag, 0, + reinterpret_cast(buffer), &length); + if (error) { + free(buffer); + return 0; + } + return hb_blob_create(const_cast(buffer), length, + HB_MEMORY_MODE_WRITABLE, buffer, free); +} + +static hb_bool_t harfbuzzGetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoint_t unicode, hb_codepoint_t variationSelector, hb_codepoint_t* glyph, void* userData) +{ + FT_Face ftFace = reinterpret_cast(fontData); + FT_UInt glyph_index = FT_Get_Char_Index(ftFace, unicode); + *glyph = glyph_index; + return !!*glyph; +} + +static hb_position_t ft_pos_to_hb(FT_Pos pos) { + return pos << 2; +} + +static hb_position_t harfbuzzGetGlyphHorizontalAdvance(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, void* userData) +{ + FT_Face ftFace = reinterpret_cast(fontData); + hb_position_t advance = 0; + + FT_Load_Glyph(ftFace, glyph, FT_LOAD_DEFAULT); + return ft_pos_to_hb(ftFace->glyph->advance.x); +} + +static hb_bool_t harfbuzzGetGlyphHorizontalOrigin(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, hb_position_t* x, hb_position_t* y, void* userData) +{ + // Just return true, following the way that Harfbuzz-FreeType + // implementation does. + return true; +} + +hb_font_funcs_t* getHbFontFuncs() { + static hb_font_funcs_t* hbFontFuncs = 0; + + if (hbFontFuncs == 0) { + hbFontFuncs = hb_font_funcs_create(); + hb_font_funcs_set_glyph_func(hbFontFuncs, harfbuzzGetGlyph, 0, 0); + hb_font_funcs_set_glyph_h_advance_func(hbFontFuncs, harfbuzzGetGlyphHorizontalAdvance, 0, 0); + hb_font_funcs_set_glyph_h_origin_func(hbFontFuncs, harfbuzzGetGlyphHorizontalOrigin, 0, 0); + hb_font_funcs_make_immutable(hbFontFuncs); + } + return hbFontFuncs; +} + +hb_font_t* create_hb_font(FT_Face ftFace) { + hb_face_t* face = hb_face_create_for_tables(referenceTable, ftFace, NULL); + hb_font_t* font = hb_font_create(face); + hb_font_set_funcs(font, getHbFontFuncs(), ftFace, 0); + // TODO: manage ownership of face + return font; +} + +static float HBFixedToFloat(hb_position_t v) +{ + return scalbnf (v, -8); +} + +static hb_position_t HBFloatToFixed(float v) +{ + return scalbnf (v, +8); +} + +void Layout::dump() const { + for (size_t i = 0; i < mGlyphs.size(); i++) { + const LayoutGlyph& glyph = mGlyphs[i]; + std::cout << glyph.glyph_id << ": " << glyph.x << ", " << glyph.y << std::endl; + } +} + +// A couple of things probably need to change: +// 1. Deal with multiple sizes in a layout +// 2. We'll probably store FT_Face as primary and then use a cache +// for the hb fonts +int Layout::findFace(FT_Face face) { + unsigned int ix; + for (ix = 0; ix < mFaces.size(); ix++) { + if (mFaces[ix] == face) { + return ix; + } + } + double size = mProps.value(fontSize).getFloatValue(); + FT_Error error = FT_Set_Pixel_Sizes(face, 0, size); + mFaces.push_back(face); + hb_font_t *font = create_hb_font(face); + hb_font_set_ppem(font, size, size); + hb_font_set_scale(font, HBFloatToFixed(size), HBFloatToFixed(size)); + mHbFonts.push_back(font); + return ix; +} + +static FontStyle styleFromCss(const CssProperties &props) { + int weight = 4; + if (props.hasTag(fontWeight)) { + weight = props.value(fontWeight).getIntValue() / 100; + } + bool italic = false; + if (props.hasTag(fontStyle)) { + italic = props.value(fontStyle).getIntValue() != 0; + } + // TODO: italic property from CSS + return FontStyle(weight, italic); +} + +// TODO: API should probably take context +void Layout::doLayout(const uint16_t* buf, size_t nchars) { + FT_Error error; + + vector items; + FontStyle style = styleFromCss(mProps); + mCollection->itemize(buf, nchars, style, &items); + + mGlyphs.clear(); + mFaces.clear(); + mHbFonts.clear(); + float x = 0; + float y = 0; + for (size_t run_ix = 0; run_ix < items.size(); run_ix++) { + FontCollection::Run &run = items[run_ix]; + int font_ix = findFace(run.font); + hb_font_t *hbFont = mHbFonts[font_ix]; +#ifdef VERBOSE + std::cout << "Run " << run_ix << ", font " << font_ix << + " [" << run.start << ":" << run.end << "]" << std::endl; +#endif + + hb_buffer_reset(buffer); + hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); + hb_buffer_add_utf16(buffer, buf, nchars, run.start, run.end - run.start); + hb_shape(hbFont, buffer, NULL, 0); + unsigned int numGlyphs; + hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, &numGlyphs); + hb_glyph_position_t *positions = hb_buffer_get_glyph_positions(buffer, NULL); + for (unsigned int i = 0; i < numGlyphs; i++) { +#ifdef VERBOSE + std::cout << positions[i].x_advance << " " << positions[i].y_advance << " " << positions[i].x_offset << " " << positions[i].y_offset << std::endl; std::cout << "DoLayout " << info[i].codepoint << + ": " << HBFixedToFloat(positions[i].x_advance) << "; " << positions[i].x_offset << ", " << positions[i].y_offset << std::endl; +#endif + hb_codepoint_t glyph_ix = info[i].codepoint; + float xoff = HBFixedToFloat(positions[i].x_offset); + float yoff = HBFixedToFloat(positions[i].y_offset); + LayoutGlyph glyph = {font_ix, glyph_ix, x + xoff, y + yoff}; + mGlyphs.push_back(glyph); + x += HBFixedToFloat(positions[i].x_advance); + } + } +} + +void Layout::draw(Bitmap* surface, int x0, int y0) const { + FT_Error error; + FT_Int32 load_flags = FT_LOAD_DEFAULT; + if (mProps.hasTag(minikinHinting)) { + int hintflags = mProps.value(minikinHinting).getIntValue(); + if (hintflags & 1) load_flags |= FT_LOAD_NO_HINTING; + if (hintflags & 2) load_flags |= FT_LOAD_NO_AUTOHINT; + } + for (size_t i = 0; i < mGlyphs.size(); i++) { + const LayoutGlyph& glyph = mGlyphs[i]; + FT_Face face = mFaces[glyph.font_ix]; + error = FT_Load_Glyph(face, glyph.glyph_id, load_flags); + error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL); + surface->drawGlyph(face->glyph->bitmap, + x0 + int(floor(glyph.x + 0.5)) + face->glyph->bitmap_left, + y0 + int(floor(glyph.y + 0.5)) - face->glyph->bitmap_top); + } +} + +void Layout::setProperties(string css) { + mProps.parse(css); +} + +} // namespace android diff --git a/engine/src/flutter/libs/minikin/SparseBitSet.cpp b/engine/src/flutter/libs/minikin/SparseBitSet.cpp new file mode 100644 index 00000000000..e0b3c1d5a7e --- /dev/null +++ b/engine/src/flutter/libs/minikin/SparseBitSet.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2012 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 +#include +#include + +namespace android { + +const uint32_t SparseBitSet::kNotFound; + +void SparseBitSet::clear() { + mMaxVal = 0; + mIndices.reset(); + mBitmaps.reset(); +} + +uint32_t SparseBitSet::calcNumPages(const uint32_t* ranges, size_t nRanges) { + bool haveZeroPage = false; + uint32_t nonzeroPageEnd = 0; + uint32_t nPages = 0; + for (size_t i = 0; i < nRanges; i++) { + uint32_t start = ranges[i * 2]; + uint32_t end = ranges[i * 2 + 1]; + uint32_t startPage = start >> kLogValuesPerPage; + uint32_t endPage = (end - 1) >> kLogValuesPerPage; + if (startPage >= nonzeroPageEnd) { + if (startPage > nonzeroPageEnd) { + if (!haveZeroPage) { + haveZeroPage = true; + nPages++; + } + } + nPages++; + } + nPages += endPage - startPage; + nonzeroPageEnd = endPage + 1; + } + return nPages; +} + +void SparseBitSet::initFromRanges(const uint32_t* ranges, size_t nRanges) { + if (nRanges == 0) { + mMaxVal = 0; + mIndices.reset(); + mBitmaps.reset(); + return; + } + mMaxVal = ranges[nRanges * 2 - 1]; + size_t indexSize = (mMaxVal + kPageMask) >> kLogValuesPerPage; + mIndices.reset(new uint32_t[indexSize]); + uint32_t nPages = calcNumPages(ranges, nRanges); + mBitmaps.reset(new element[nPages << (kLogValuesPerPage - kLogBitsPerEl)]); + memset(mBitmaps.get(), 0, nPages << (kLogValuesPerPage - 3)); + mZeroPageIndex = noZeroPage; + uint32_t nonzeroPageEnd = 0; + uint32_t currentPage = 0; + for (size_t i = 0; i < nRanges; i++) { + uint32_t start = ranges[i * 2]; + uint32_t end = ranges[i * 2 + 1]; + uint32_t startPage = start >> kLogValuesPerPage; + uint32_t endPage = (end - 1) >> kLogValuesPerPage; + if (startPage >= nonzeroPageEnd) { + if (startPage > nonzeroPageEnd) { + if (mZeroPageIndex == noZeroPage) { + mZeroPageIndex = (currentPage++) << (kLogValuesPerPage - kLogBitsPerEl); + } + for (uint32_t j = nonzeroPageEnd; j < startPage; j++) { + mIndices[j] = mZeroPageIndex; + } + } + mIndices[startPage] = (currentPage++) << (kLogValuesPerPage - kLogBitsPerEl); + } + + size_t index = ((currentPage - 1) << (kLogValuesPerPage - kLogBitsPerEl)) + + ((start & kPageMask) >> kLogBitsPerEl); + size_t nElements = (end - (start & ~kElMask) + kElMask) >> kLogBitsPerEl; + if (nElements == 1) { + mBitmaps[index] |= (kElAllOnes >> (start & kElMask)) & + (kElAllOnes << ((-end) & kElMask)); + } else { + mBitmaps[index] |= kElAllOnes >> (start & kElMask); + for (size_t j = 1; j < nElements - 1; j++) { + mBitmaps[index + j] = kElAllOnes; + } + mBitmaps[index + nElements - 1] |= kElAllOnes << ((-end) & kElMask); + } + for (size_t j = startPage + 1; j < endPage + 1; j++) { + mIndices[j] = (currentPage++) << (kLogValuesPerPage - kLogBitsPerEl); + } + nonzeroPageEnd = endPage + 1; + } +} + +// Note: this implementation depends on GCC builtin, and also assumes 32-bit elements. +int SparseBitSet::CountLeadingZeros(element x) { + return __builtin_clz(x); +} + +uint32_t SparseBitSet::nextSetBit(uint32_t fromIndex) const { + if (fromIndex >= mMaxVal) { + return kNotFound; + } + uint32_t fromPage = fromIndex >> kLogValuesPerPage; + const element* bitmap = &mBitmaps[mIndices[fromPage]]; + uint32_t offset = (fromIndex & kPageMask) >> kLogBitsPerEl; + element e = bitmap[offset] & (kElAllOnes >> (fromIndex & kElMask)); + if (e != 0) { + return (fromIndex & ~kElMask) + CountLeadingZeros(e); + } + for (uint32_t j = offset + 1; j < (1 << (kLogValuesPerPage - kLogBitsPerEl)); j++) { + e = bitmap[j]; + if (e != 0) { + return (fromIndex & ~kPageMask) + (j << kLogBitsPerEl) + CountLeadingZeros(e); + } + } + uint32_t maxPage = (mMaxVal + kPageMask) >> kLogValuesPerPage; + for (uint32_t page = fromPage + 1; page < maxPage; page++) { + uint32_t index = mIndices[page]; + if (index == mZeroPageIndex) { + continue; + } + bitmap = &mBitmaps[index]; + for (uint32_t j = 0; j < (1 << (kLogValuesPerPage - kLogBitsPerEl)); j++) { + e = bitmap[j]; + if (e != 0) { + return (page << kLogValuesPerPage) + (j << kLogBitsPerEl) + CountLeadingZeros(e); + } + } + } + return kNotFound; +} + +} // namespace android diff --git a/engine/src/flutter/sample/Android.mk b/engine/src/flutter/sample/Android.mk new file mode 100644 index 00000000000..335e7ce7879 --- /dev/null +++ b/engine/src/flutter/sample/Android.mk @@ -0,0 +1,42 @@ +# Copyright (C) 2013 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. + +LOCAL_PATH:= $(call my-dir) + +include $(CLEAR_VARS) +include external/stlport/libstlport.mk + +LOCAL_MODULE_TAGS := tests + +LOCAL_C_INCLUDES += \ + external/harfbuzz_ng/src \ + external/freetype/include \ + external/icu4c/common \ + frameworks/minikin/include + +LOCAL_SRC_FILES:= example.cpp + +LOCAL_SHARED_LIBRARIES += \ + libutils \ + liblog \ + libcutils \ + libstlport \ + libharfbuzz_ng \ + libicuuc + +LOCAL_STATIC_LIBRARIES += libminikin libft2 + +LOCAL_MODULE:= minikin_example + +include $(BUILD_EXECUTABLE) diff --git a/engine/src/flutter/sample/example.cpp b/engine/src/flutter/sample/example.cpp new file mode 100644 index 00000000000..3f0ad9d9a7a --- /dev/null +++ b/engine/src/flutter/sample/example.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2013 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. + */ + +// This is a test program that uses Minikin to layout and draw some text. +// At the moment, it just draws a string into /data/local/tmp/foo.pgm. + +#include +#include +#include + +#include +#include + +#include + +using std::vector; + +namespace android { + +FT_Library library; // TODO: this should not be a global + +FontCollection *makeFontCollection() { + vectortypefaces; + const char *fns[] = { + "/system/fonts/Roboto-Regular.ttf", + "/system/fonts/Roboto-Italic.ttf", + "/system/fonts/Roboto-BoldItalic.ttf", + "/system/fonts/Roboto-Light.ttf", + "/system/fonts/Roboto-Thin.ttf", + "/system/fonts/Roboto-Bold.ttf", + "/system/fonts/Roboto-ThinItalic.ttf", + "/system/fonts/Roboto-LightItalic.ttf" + }; + + FontFamily *family = new FontFamily(); + FT_Face face; + FT_Error error; + for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) { + const char *fn = fns[i]; + printf("adding %s\n", fn); + error = FT_New_Face(library, fn, 0, &face); + if (error != 0) { + printf("error loading %s, %d\n", fn, error); + } + family->addFont(face); + } + typefaces.push_back(family); + +#if 0 + family = new FontFamily(); + const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf"; + error = FT_New_Face(library, fn, 0, &face); + family->addFont(face); + typefaces.push_back(family); +#endif + + return new FontCollection(typefaces); +} + +int runMinikinTest() { + FT_Error error = FT_Init_FreeType(&library); + if (error) { + return -1; + } + Layout::init(); + + FontCollection *collection = makeFontCollection(); + Layout layout; + layout.setFontCollection(collection); + layout.setProperties("font-size: 32;"); + const char *text = "hello world"; + icu::UnicodeString icuText = icu::UnicodeString::fromUTF8(text); + layout.doLayout(icuText.getBuffer(), icuText.length()); + layout.dump(); + Bitmap bitmap(200, 50); + layout.draw(&bitmap, 10, 40); + std::ofstream o; + o.open("/data/local/tmp/foo.pgm", std::ios::out | std::ios::binary); + bitmap.writePnm(o); + return 0; +} + +} + +int main(int argc, const char** argv) { + return android::runMinikinTest(); +} \ No newline at end of file From 8d9541c5fb3c7d3a8d960faf9d99aa5cde41ea72 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 22 May 2013 16:14:27 -0700 Subject: [PATCH 003/364] Introduce MinikinFont abstraction This commit removes the direct dependency on FreeType and replaces it with a MinikinFont abstraction, which is designed to support both FreeType and Skia fonts (and possibly others in the future). Also adds a "total advance" to the Layout, with an API for retrieving it. Change-Id: If20f92db9a43fd15b0fe9794b761ba00fb21338c --- .../flutter/include/minikin/FontCollection.h | 19 ++-- .../src/flutter/include/minikin/FontFamily.h | 12 +-- engine/src/flutter/include/minikin/Layout.h | 13 +-- .../src/flutter/include/minikin/MinikinFont.h | 70 ++++++++++++ .../include/minikin/MinikinFontFreeType.h | 71 +++++++++++++ engine/src/flutter/libs/minikin/Android.mk | 1 + .../flutter/libs/minikin/FontCollection.cpp | 13 ++- .../src/flutter/libs/minikin/FontFamily.cpp | 24 ++--- engine/src/flutter/libs/minikin/Layout.cpp | 100 +++++++++++------- .../libs/minikin/MinikinFontFreeType.cpp | 95 +++++++++++++++++ engine/src/flutter/sample/example.cpp | 15 +-- 11 files changed, 343 insertions(+), 90 deletions(-) create mode 100644 engine/src/flutter/include/minikin/MinikinFont.h create mode 100644 engine/src/flutter/include/minikin/MinikinFontFreeType.h create mode 100644 engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 3aa2acace21..a2a5391fc7e 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -19,12 +19,9 @@ #include -#include -#include FT_FREETYPE_H -#include FT_TRUETYPE_TABLES_H - -#include "SparseBitSet.h" -#include "FontFamily.h" +#include +#include +#include namespace android { @@ -40,19 +37,19 @@ public: // Do copy constructor, assignment, destructor so it can be used in vectors Run() : font(NULL) { } Run(const Run& other): font(other.font), start(other.start), end(other.end) { - if (font) FT_Reference_Face(font); + if (font) font->Ref(); } Run& operator=(const Run& other) { - if (other.font) FT_Reference_Face(other.font); - if (font) FT_Done_Face(font); + if (other.font) other.font->Ref(); + if (font) font->Unref(); font = other.font; start = other.start; end = other.end; return *this; } - ~Run() { if (font) FT_Done_Face(font); } + ~Run() { if (font) font->Unref(); } - FT_Face font; + MinikinFont* font; int start; int end; }; diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 01ea2322521..290220bbad2 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -42,21 +42,21 @@ private: class FontFamily { public: // Add font to family, extracting style information from the font - bool addFont(FT_Face typeface); + bool addFont(MinikinFont* typeface); - void addFont(FT_Face typeface, FontStyle style); - FT_Face getClosestMatch(FontStyle style) const; + void addFont(MinikinFont* typeface, FontStyle style); + MinikinFont* getClosestMatch(FontStyle style) const; // API's for enumerating the fonts in a family. These don't guarantee any particular order size_t getNumFonts() const; - FT_Face getFont(size_t index) const; + MinikinFont* getFont(size_t index) const; FontStyle getStyle(size_t index) const; private: class Font { public: - Font(FT_Face typeface, FontStyle style) : + Font(MinikinFont* typeface, FontStyle style) : typeface(typeface), style(style) { } - FT_Face typeface; + MinikinFont* typeface; FontStyle style; }; std::vector mFonts; diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 7a6c6cfc25b..fd0ed7545ca 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -17,15 +17,13 @@ #ifndef MINIKIN_LAYOUT_H #define MINIKIN_LAYOUT_H -#include -#include FT_FREETYPE_H - #include #include #include #include +#include namespace android { @@ -37,7 +35,7 @@ public: Bitmap(int width, int height); ~Bitmap(); void writePnm(std::ofstream& o) const; - void drawGlyph(const FT_Bitmap& bitmap, int x, int y); + void drawGlyph(const GlyphBitmap& bitmap, int x, int y); private: int width; int height; @@ -65,12 +63,14 @@ public: void draw(Bitmap*, int x0, int y0) const; void setProperties(const std::string css); + float getAdvance() const; + // This must be called before any invocations. // TODO: probably have a factory instead static void init(); private: // Find a face in the mFaces vector, or create a new entry - int findFace(FT_Face face); + int findFace(MinikinFont* face, MinikinPaint* paint); CssProperties mProps; // TODO: want spans std::vector mGlyphs; @@ -80,8 +80,9 @@ private: // But for the time being, it should be ok to have just one // per layout. const FontCollection *mCollection; - std::vector mFaces; + std::vector mFaces; std::vector mHbFonts; + float mAdvance; }; } // namespace android diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h new file mode 100644 index 00000000000..2c265c3bb3e --- /dev/null +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2013 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_H +#define MINIKIN_FONT_H + +// An abstraction for platform fonts, allowing Minikin to be used with +// multiple actual implementations of fonts. + +namespace android { + +class MinikinFont; + +// Possibly move into own .h file? +struct MinikinPaint { + MinikinFont *font; + float size; + // todo: skew, stretch, hinting +}; + +class MinikinFontFreeType; + +class MinikinFont { +public: + void Ref() { mRefcount_++; } + void Unref() { if (--mRefcount_ == 0) { delete this; } } + + //MinikinFont(); + virtual ~MinikinFont() = 0; + + virtual bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const = 0; + + virtual float GetHorizontalAdvance(uint32_t glyph_id, + const MinikinPaint &paint) const = 0; + + // If buf is NULL, just update size + virtual bool GetTable(uint32_t tag, uint8_t *buf, size_t *size) = 0; + + virtual int32_t GetUniqueId() const = 0; + + static uint32_t MakeTag(char c1, char c2, char c3, char c4) { + return ((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) | + ((uint32_t)c3 << 8) | (uint32_t)c4; + } + + // This is used to implement a downcast without RTTI + virtual MinikinFontFreeType* GetFreeType() { + return NULL; + } + +private: + int mRefcount_; +}; + +} // namespace android + +#endif // MINIKIN_FONT_H diff --git a/engine/src/flutter/include/minikin/MinikinFontFreeType.h b/engine/src/flutter/include/minikin/MinikinFontFreeType.h new file mode 100644 index 00000000000..70518319acf --- /dev/null +++ b/engine/src/flutter/include/minikin/MinikinFontFreeType.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2013 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_FREETYPE_H +#define MINIKIN_FONT_FREETYPE_H + +#include +#include FT_FREETYPE_H +#include FT_TRUETYPE_TABLES_H + +#include + +// An abstraction for platform fonts, allowing Minikin to be used with +// multiple actual implementations of fonts. + +namespace android { + +struct GlyphBitmap { + uint8_t *buffer; + int width; + int height; + int left; + int top; +}; + +class MinikinFontFreeType : public MinikinFont { +public: + explicit MinikinFontFreeType(FT_Face typeface); + + ~MinikinFontFreeType(); + + bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const; + + float GetHorizontalAdvance(uint32_t glyph_id, + const MinikinPaint &paint) const; + + // If buf is NULL, just update size + bool GetTable(uint32_t tag, uint8_t *buf, size_t *size); + + int32_t GetUniqueId() const; + + // Not a virtual method, as the protocol to access rendered + // glyph bitmaps is probably different depending on the + // backend. + bool Render(uint32_t glyph_id, + const MinikinPaint &paint, GlyphBitmap *result); + + MinikinFontFreeType* GetFreeType(); + +private: + FT_Face mTypeface; + int32_t mUniqueId; + static int32_t sIdCounter; +}; + +} // namespace android + +#endif // MINIKIN_FONT_FREETYPE_H diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 9795ad05d02..723ad1ff9e3 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -24,6 +24,7 @@ LOCAL_SRC_FILES := \ FontCollection.cpp \ FontFamily.cpp \ Layout.cpp \ + MinikinFontFreeType.cpp \ SparseBitSet.cpp LOCAL_MODULE := libminikin diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 7abbd3b3025..702bd2097fc 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -45,16 +45,15 @@ FontCollection::FontCollection(const vector& typefaces) : FontInstance* instance = &mInstances.back(); instance->mFamily = family; instance->mCoverage = new SparseBitSet; - FT_Face typeface = family->getClosestMatch(defaultStyle); + MinikinFont* typeface = family->getClosestMatch(defaultStyle); #ifdef VERBOSE_DEBUG printf("closest match = %x, family size = %d\n", typeface, family->getNumFonts()); #endif - const uint32_t cmapTag = FT_MAKE_TAG('c', 'm', 'a', 'p'); - FT_ULong cmapSize = 0; - FT_Error error = FT_Load_Sfnt_Table(typeface, cmapTag, 0, NULL, &cmapSize); + const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); + size_t cmapSize = 0; + bool ok = typeface->GetTable(cmapTag, NULL, &cmapSize); UniquePtr cmapData(new uint8_t[cmapSize]); - error = FT_Load_Sfnt_Table(typeface, cmapTag, 0, - cmapData.get(), &cmapSize); + ok = typeface->GetTable(cmapTag, cmapData.get(), &cmapSize); CmapCoverage::getCoverage(*instance->mCoverage, cmapData.get(), cmapSize); #ifdef VERBOSE_DEBUG printf("font coverage length=%d, first ch=%x\n", instance->mCoverage->length(), @@ -138,7 +137,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty run->font = NULL; // maybe we should do something different here } else { run->font = family->getClosestMatch(style); - FT_Reference_Face(run->font); + run->font->Ref(); } lastFamily = family; run->start = i; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index dc6e16ce834..0bc38a7736b 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -20,9 +20,7 @@ #include #include #include -#include -#include FT_FREETYPE_H -#include FT_TRUETYPE_TABLES_H +#include #include #include @@ -30,14 +28,14 @@ using std::vector; namespace android { -bool FontFamily::addFont(FT_Face typeface) { - const uint32_t os2Tag = FT_MAKE_TAG('O', 'S', '/', '2'); - FT_ULong os2Size = 0; - FT_Error error = FT_Load_Sfnt_Table(typeface, os2Tag, 0, NULL, &os2Size); - if (error != 0) return false; +bool FontFamily::addFont(MinikinFont* typeface) { + const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2'); + size_t os2Size = 0; + bool ok = typeface->GetTable(os2Tag, NULL, &os2Size); + if (!ok) return false; UniquePtr os2Data(new uint8_t[os2Size]); - error = FT_Load_Sfnt_Table(typeface, os2Tag, 0, os2Data.get(), &os2Size); - if (error != 0) return false; + ok = typeface->GetTable(os2Tag, os2Data.get(), &os2Size); + if (!ok) return false; int weight; bool italic; if (analyzeStyle(os2Data.get(), os2Size, &weight, &italic)) { @@ -51,7 +49,7 @@ bool FontFamily::addFont(FT_Face typeface) { return false; } -void FontFamily::addFont(FT_Face typeface, FontStyle style) { +void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { mFonts.push_back(Font(typeface, style)); ALOGD("added font, mFonts.size() = %d", mFonts.size()); } @@ -66,7 +64,7 @@ int computeMatch(FontStyle style1, FontStyle style2) { return score; } -FT_Face FontFamily::getClosestMatch(FontStyle style) const { +MinikinFont* FontFamily::getClosestMatch(FontStyle style) const { const Font* bestFont = NULL; int bestMatch = 0; for (size_t i = 0; i < mFonts.size(); i++) { @@ -84,7 +82,7 @@ size_t FontFamily::getNumFonts() const { return mFonts.size(); } -FT_Face FontFamily::getFont(size_t index) const { +MinikinFont* FontFamily::getFont(size_t index) const { return mFonts[index].typeface; } diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index a8a596d7293..d4e09c5dfe7 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -18,7 +18,9 @@ #include #include #include // for debugging +#include // ditto +#include #include using std::string; @@ -45,9 +47,11 @@ void Bitmap::writePnm(std::ofstream &o) const { o.close(); } -void Bitmap::drawGlyph(const FT_Bitmap& bitmap, int x, int y) { +void Bitmap::drawGlyph(const GlyphBitmap& bitmap, int x, int y) { int bmw = bitmap.width; - int bmh = bitmap.rows; + int bmh = bitmap.height; + x += bitmap.left; + y -= bitmap.top; int x0 = std::max(0, x); int x1 = std::min(width, x + bmw); int y0 = std::max(0, y); @@ -74,19 +78,20 @@ void Layout::setFontCollection(const FontCollection *collection) { } hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { - FT_Face ftFace = reinterpret_cast(userData); - FT_ULong length = 0; - FT_Error error = FT_Load_Sfnt_Table(ftFace, tag, 0, NULL, &length); - if (error) { + MinikinFont* font = reinterpret_cast(userData); + size_t length = 0; + bool ok = font->GetTable(tag, NULL, &length); + if (!ok) { return 0; } char *buffer = reinterpret_cast(malloc(length)); if (!buffer) { return 0; } - error = FT_Load_Sfnt_Table(ftFace, tag, 0, - reinterpret_cast(buffer), &length); - if (error) { + ok = font->GetTable(tag, reinterpret_cast(buffer), &length); + printf("referenceTable %c%c%c%c length=%d %d\n", + (tag >>24) & 0xff, (tag>>16)&0xff, (tag>>8)&0xff, tag&0xff, length, ok); + if (!ok) { free(buffer); return 0; } @@ -96,23 +101,22 @@ hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { static hb_bool_t harfbuzzGetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoint_t unicode, hb_codepoint_t variationSelector, hb_codepoint_t* glyph, void* userData) { - FT_Face ftFace = reinterpret_cast(fontData); - FT_UInt glyph_index = FT_Get_Char_Index(ftFace, unicode); - *glyph = glyph_index; - return !!*glyph; -} - -static hb_position_t ft_pos_to_hb(FT_Pos pos) { - return pos << 2; + MinikinPaint* paint = reinterpret_cast(fontData); + MinikinFont* font = paint->font; + uint32_t glyph_id; + bool ok = font->GetGlyph(unicode, &glyph_id); + if (ok) { + *glyph = glyph_id; + } + return ok; } static hb_position_t harfbuzzGetGlyphHorizontalAdvance(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, void* userData) { - FT_Face ftFace = reinterpret_cast(fontData); - hb_position_t advance = 0; - - FT_Load_Glyph(ftFace, glyph, FT_LOAD_DEFAULT); - return ft_pos_to_hb(ftFace->glyph->advance.x); + MinikinPaint* paint = reinterpret_cast(fontData); + MinikinFont* font = paint->font; + float advance = font->GetHorizontalAdvance(glyph, *paint); + return 256 * advance + 0.5; } static hb_bool_t harfbuzzGetGlyphHorizontalOrigin(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, hb_position_t* x, hb_position_t* y, void* userData) @@ -135,10 +139,10 @@ hb_font_funcs_t* getHbFontFuncs() { return hbFontFuncs; } -hb_font_t* create_hb_font(FT_Face ftFace) { - hb_face_t* face = hb_face_create_for_tables(referenceTable, ftFace, NULL); +hb_font_t* create_hb_font(MinikinFont* minikinFont, MinikinPaint* minikinPaint) { + hb_face_t* face = hb_face_create_for_tables(referenceTable, minikinFont, NULL); hb_font_t* font = hb_font_create(face); - hb_font_set_funcs(font, getHbFontFuncs(), ftFace, 0); + hb_font_set_funcs(font, getHbFontFuncs(), minikinPaint, 0); // TODO: manage ownership of face return font; } @@ -164,19 +168,15 @@ void Layout::dump() const { // 1. Deal with multiple sizes in a layout // 2. We'll probably store FT_Face as primary and then use a cache // for the hb fonts -int Layout::findFace(FT_Face face) { +int Layout::findFace(MinikinFont* face, MinikinPaint* paint) { unsigned int ix; for (ix = 0; ix < mFaces.size(); ix++) { if (mFaces[ix] == face) { return ix; } } - double size = mProps.value(fontSize).getFloatValue(); - FT_Error error = FT_Set_Pixel_Sizes(face, 0, size); mFaces.push_back(face); - hb_font_t *font = create_hb_font(face); - hb_font_set_ppem(font, size, size); - hb_font_set_scale(font, HBFloatToFixed(size), HBFloatToFixed(size)); + hb_font_t *font = create_hb_font(face, paint); mHbFonts.push_back(font); return ix; } @@ -190,7 +190,6 @@ static FontStyle styleFromCss(const CssProperties &props) { if (props.hasTag(fontStyle)) { italic = props.value(fontStyle).getIntValue() != 0; } - // TODO: italic property from CSS return FontStyle(weight, italic); } @@ -202,6 +201,10 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { FontStyle style = styleFromCss(mProps); mCollection->itemize(buf, nchars, style, &items); + MinikinPaint paint; + double size = mProps.value(fontSize).getFloatValue(); + paint.size = size; + mGlyphs.clear(); mFaces.clear(); mHbFonts.clear(); @@ -209,12 +212,15 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { float y = 0; for (size_t run_ix = 0; run_ix < items.size(); run_ix++) { FontCollection::Run &run = items[run_ix]; - int font_ix = findFace(run.font); + int font_ix = findFace(run.font, &paint); + paint.font = mFaces[font_ix]; hb_font_t *hbFont = mHbFonts[font_ix]; #ifdef VERBOSE std::cout << "Run " << run_ix << ", font " << font_ix << " [" << run.start << ":" << run.end << "]" << std::endl; #endif + hb_font_set_ppem(hbFont, size, size); + hb_font_set_scale(hbFont, HBFloatToFixed(size), HBFloatToFixed(size)); hb_buffer_reset(buffer); hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); @@ -236,24 +242,32 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { x += HBFixedToFloat(positions[i].x_advance); } } + mAdvance = x; } void Layout::draw(Bitmap* surface, int x0, int y0) const { - FT_Error error; - FT_Int32 load_flags = FT_LOAD_DEFAULT; + /* + TODO: redo as MinikinPaint settings if (mProps.hasTag(minikinHinting)) { int hintflags = mProps.value(minikinHinting).getIntValue(); if (hintflags & 1) load_flags |= FT_LOAD_NO_HINTING; if (hintflags & 2) load_flags |= FT_LOAD_NO_AUTOHINT; } + */ for (size_t i = 0; i < mGlyphs.size(); i++) { const LayoutGlyph& glyph = mGlyphs[i]; - FT_Face face = mFaces[glyph.font_ix]; - error = FT_Load_Glyph(face, glyph.glyph_id, load_flags); - error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL); - surface->drawGlyph(face->glyph->bitmap, - x0 + int(floor(glyph.x + 0.5)) + face->glyph->bitmap_left, - y0 + int(floor(glyph.y + 0.5)) - face->glyph->bitmap_top); + MinikinFont *mf = mFaces[glyph.font_ix]; + MinikinFontFreeType *face = static_cast(mf); + GlyphBitmap glyphBitmap; + MinikinPaint paint; + paint.size = mProps.value(fontSize).getFloatValue(); + bool ok = face->Render(glyph.glyph_id, paint, &glyphBitmap); + printf("glyphBitmap.width=%d, glyphBitmap.height=%d (%d, %d) x=%f, y=%f, ok=%d\n", + glyphBitmap.width, glyphBitmap.height, glyphBitmap.left, glyphBitmap.top, glyph.x, glyph.y, ok); + if (ok) { + surface->drawGlyph(glyphBitmap, + x0 + int(floor(glyph.x + 0.5)), y0 + int(floor(glyph.y + 0.5))); + } } } @@ -261,4 +275,8 @@ void Layout::setProperties(string css) { mProps.parse(css); } +float Layout::getAdvance() const { + return mAdvance; +} + } // namespace android diff --git a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp new file mode 100644 index 00000000000..be61345a9cb --- /dev/null +++ b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2013 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. + */ + +// Implementation of MinikinFont abstraction specialized for FreeType + +#include + +#include +#include FT_FREETYPE_H +#include FT_TRUETYPE_TABLES_H +#include FT_ADVANCES_H + +#include + +namespace android { + +int32_t MinikinFontFreeType::sIdCounter = 0; + +MinikinFontFreeType::MinikinFontFreeType(FT_Face typeface) : + mTypeface(typeface) { + mUniqueId = sIdCounter++; +} + +MinikinFontFreeType::~MinikinFontFreeType() { + FT_Done_Face(mTypeface); +} + +bool MinikinFontFreeType::GetGlyph(uint32_t codepoint, uint32_t *glyph) const { + FT_UInt glyph_index = FT_Get_Char_Index(mTypeface, codepoint); + *glyph = glyph_index; + return !!glyph_index; +} + +float MinikinFontFreeType::GetHorizontalAdvance(uint32_t glyph_id, + const MinikinPaint &paint) const { + FT_Set_Pixel_Sizes(mTypeface, 0, paint.size); + FT_UInt32 flags = FT_LOAD_DEFAULT; // TODO: respect hinting settings + FT_Fixed advance; + FT_Error error = FT_Get_Advance(mTypeface, glyph_id, flags, &advance); + return advance * (1.0 / 65536); +} + +bool MinikinFontFreeType::GetTable(uint32_t tag, uint8_t *buf, size_t *size) { + FT_ULong ftsize = *size; + FT_Error error = FT_Load_Sfnt_Table(mTypeface, tag, 0, buf, &ftsize); + if (error != 0) { + return false; + } + *size = ftsize; + return true; +} + +int32_t MinikinFontFreeType::GetUniqueId() const { + return mUniqueId; +} + +bool MinikinFontFreeType::Render(uint32_t glyph_id, + const MinikinPaint &paint, GlyphBitmap *result) { + FT_Error error; + FT_Int32 load_flags = FT_LOAD_DEFAULT; // TODO: respect hinting settings + error = FT_Load_Glyph(mTypeface, glyph_id, load_flags); + if (error != 0) { + return false; + } + error = FT_Render_Glyph(mTypeface->glyph, FT_RENDER_MODE_NORMAL); + if (error != 0) { + return false; + } + FT_Bitmap &bitmap = mTypeface->glyph->bitmap; + result->buffer = bitmap.buffer; + result->width = bitmap.width; + result->height = bitmap.rows; + result->left = mTypeface->glyph->bitmap_left; + result->top = mTypeface->glyph->bitmap_top; + return true; +} + +MinikinFontFreeType* MinikinFontFreeType::GetFreeType() { + return this; +} + +} // namespace android diff --git a/engine/src/flutter/sample/example.cpp b/engine/src/flutter/sample/example.cpp index 3f0ad9d9a7a..9b012ef0866 100644 --- a/engine/src/flutter/sample/example.cpp +++ b/engine/src/flutter/sample/example.cpp @@ -24,6 +24,7 @@ #include #include +#include #include using std::vector; @@ -55,15 +56,17 @@ FontCollection *makeFontCollection() { if (error != 0) { printf("error loading %s, %d\n", fn, error); } - family->addFont(face); + MinikinFont *font = new MinikinFontFreeType(face); + family->addFont(font); } typefaces.push_back(family); -#if 0 +#if 1 family = new FontFamily(); const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf"; error = FT_New_Face(library, fn, 0, &face); - family->addFont(face); + MinikinFont *font = new MinikinFontFreeType(face); + family->addFont(font); typefaces.push_back(family); #endif @@ -81,11 +84,11 @@ int runMinikinTest() { Layout layout; layout.setFontCollection(collection); layout.setProperties("font-size: 32;"); - const char *text = "hello world"; + const char *text = "fine world \xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa5\x87"; icu::UnicodeString icuText = icu::UnicodeString::fromUTF8(text); layout.doLayout(icuText.getBuffer(), icuText.length()); layout.dump(); - Bitmap bitmap(200, 50); + Bitmap bitmap(250, 50); layout.draw(&bitmap, 10, 40); std::ofstream o; o.open("/data/local/tmp/foo.pgm", std::ios::out | std::ios::binary); @@ -97,4 +100,4 @@ int runMinikinTest() { int main(int argc, const char** argv) { return android::runMinikinTest(); -} \ No newline at end of file +} From c905bdf4be0f0a1e19af584fdbac20042c074e5d Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 14 Jun 2013 14:12:07 -0700 Subject: [PATCH 004/364] Fix build breakage The MinikinFont class was missing a destructor. The build error was not caught because incremental builds didn't see fit to relink after I deleted one of the source files (that contained the impl of this destructor). Change-Id: Ic72d56fe28316cd2b2f808910e34ca6f177a1220 --- engine/src/flutter/include/minikin/MinikinFont.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 2c265c3bb3e..c08e4fe22d8 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -38,8 +38,7 @@ public: void Ref() { mRefcount_++; } void Unref() { if (--mRefcount_ == 0) { delete this; } } - //MinikinFont(); - virtual ~MinikinFont() = 0; + virtual ~MinikinFont() { }; virtual bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const = 0; From 79497ccc90b2eee0d8bacf4f82fc0d691f87f4bf Mon Sep 17 00:00:00 2001 From: Victoria Lease Date: Thu, 27 Jun 2013 15:43:55 -0700 Subject: [PATCH 005/364] Use shared ft2 lib, deal with libpng/zlib deps Bug: 9603326 Change-Id: I7df1f68fa3a44b37b1b279387f4ddfe942928bb0 --- engine/src/flutter/libs/minikin/Android.mk | 6 +++--- engine/src/flutter/sample/Android.mk | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 723ad1ff9e3..baac98c39dd 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -36,9 +36,9 @@ LOCAL_C_INCLUDES += \ LOCAL_SHARED_LIBRARIES := \ libharfbuzz_ng \ + libft2 \ + libpng \ + libz \ libstlport -LOCAL_STATIC_LIBARIES := \ - libft2 - include $(BUILD_STATIC_LIBRARY) diff --git a/engine/src/flutter/sample/Android.mk b/engine/src/flutter/sample/Android.mk index 335e7ce7879..939aca49f36 100644 --- a/engine/src/flutter/sample/Android.mk +++ b/engine/src/flutter/sample/Android.mk @@ -33,9 +33,12 @@ LOCAL_SHARED_LIBRARIES += \ libcutils \ libstlport \ libharfbuzz_ng \ - libicuuc + libicuuc \ + libft2 \ + libpng \ + libz -LOCAL_STATIC_LIBRARIES += libminikin libft2 +LOCAL_STATIC_LIBRARIES += libminikin LOCAL_MODULE:= minikin_example From 0ab6d024ffdc90c10f16331e8e553a533140d713 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Wed, 11 Sep 2013 15:02:30 -0700 Subject: [PATCH 006/364] Use canonical UniquePtr.h header Change-Id: Id50e9d6fe2f08d3121b168b45791a8e8fb045d7f --- engine/src/flutter/libs/minikin/FontFamily.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 0bc38a7736b..558fd77c168 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -19,10 +19,10 @@ #include #include #include -#include #include #include #include +#include using std::vector; From 014dae7e78c849444274b75a50afa242534f3291 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Wed, 11 Sep 2013 23:24:24 -0700 Subject: [PATCH 007/364] Use canonical UniquePtr.h file Change-Id: I00953971034a7d00ca165accdab528d2b8ff27a7 --- engine/src/flutter/include/minikin/SparseBitSet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/flutter/include/minikin/SparseBitSet.h b/engine/src/flutter/include/minikin/SparseBitSet.h index 4004606f1df..72b83057c6c 100644 --- a/engine/src/flutter/include/minikin/SparseBitSet.h +++ b/engine/src/flutter/include/minikin/SparseBitSet.h @@ -19,7 +19,7 @@ #include #include -#include "utils/UniquePtr.h" +#include // --------------------------------------------------------------------------- From eee04fd1e59376f0383c5accf217cfe0b3d3653d Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 15 Jul 2013 14:19:59 -0700 Subject: [PATCH 008/364] A basket of features: itemization, bounds, refcount This patch improves script run itemization and also exposes metrics and bounds for layouts. In addition, there is a fair amount of internal cleanup, including ref counting, and making the MinikinFont abstraction strong enough to support both FreeType and Skia implementations. There is also a sample implementation using Skia, in the sample directory. As part of its functionality, his patch measures the bounds of the layout and gives access through Layout::GetBounds(). The corresponding method is not implemented in the FreeType-only implementation of MinikinFont, so that will probably have to be fixed. Change-Id: Ib1a3fe9d7c90519ac651fb4aa957848e4bb758ec --- engine/src/flutter/include/minikin/Layout.h | 26 ++- .../src/flutter/include/minikin/MinikinFont.h | 28 +++ engine/src/flutter/libs/minikin/Android.mk | 4 +- .../flutter/libs/minikin/FontCollection.cpp | 19 +- .../src/flutter/libs/minikin/FontFamily.cpp | 1 - engine/src/flutter/libs/minikin/Layout.cpp | 180 ++++++++++++++++-- engine/src/flutter/sample/Android.mk | 36 +++- engine/src/flutter/sample/MinikinSkia.cpp | 64 +++++++ engine/src/flutter/sample/MinikinSkia.h | 26 +++ engine/src/flutter/sample/example_skia.cpp | 152 +++++++++++++++ 10 files changed, 499 insertions(+), 37 deletions(-) create mode 100644 engine/src/flutter/sample/MinikinSkia.cpp create mode 100644 engine/src/flutter/sample/MinikinSkia.h create mode 100644 engine/src/flutter/sample/example_skia.cpp diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index fd0ed7545ca..896478b219a 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -57,32 +57,50 @@ struct LayoutGlyph { class Layout { public: + void dump() const; - void setFontCollection(const FontCollection *collection); + void setFontCollection(const FontCollection* collection); void doLayout(const uint16_t* buf, size_t nchars); void draw(Bitmap*, int x0, int y0) const; void setProperties(const std::string css); - float getAdvance() const; - // This must be called before any invocations. // TODO: probably have a factory instead static void init(); + + // public accessors + size_t nGlyphs() const; + // Does not bump reference; ownership is still layout + MinikinFont *getFont(int i) const; + unsigned int getGlyphId(int i) const; + float getX(int i) const; + float getY(int i) const; + + float getAdvance() const; + + // Get advances, copying into caller-provided buffer. The size of this + // buffer must match the length of the string (nchars arg to doLayout). + void getAdvances(float* advances); + + void getBounds(MinikinRect* rect); + private: // Find a face in the mFaces vector, or create a new entry int findFace(MinikinFont* face, MinikinPaint* paint); CssProperties mProps; // TODO: want spans std::vector mGlyphs; + std::vector mAdvances; // In future, this will be some kind of mapping from the // identifier used to represent font-family to a font collection. // But for the time being, it should be ok to have just one // per layout. - const FontCollection *mCollection; + const FontCollection* mCollection; std::vector mFaces; std::vector mHbFonts; float mAdvance; + MinikinRect mBounds; }; } // namespace android diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index c08e4fe22d8..e84f5df63f2 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -31,6 +31,29 @@ struct MinikinPaint { // todo: skew, stretch, hinting }; +struct MinikinRect { + float mLeft, mTop, mRight, mBottom; + bool isEmpty() const { + return mLeft == mRight || mTop == mBottom; + } + void set(const MinikinRect& r) { + mLeft = r.mLeft; + mTop = r.mTop; + mRight = r.mRight; + mBottom = r.mBottom; + } + void offset(float dx, float dy) { + mLeft += dx; + mTop += dy; + mRight += dx; + mBottom += dy; + } + void setEmpty() { + mLeft = mTop = mRight = mBottom = 0; + } + void join(const MinikinRect& r); +}; + class MinikinFontFreeType; class MinikinFont { @@ -38,6 +61,8 @@ public: void Ref() { mRefcount_++; } void Unref() { if (--mRefcount_ == 0) { delete this; } } + MinikinFont() : mRefcount_(1) { } + virtual ~MinikinFont() { }; virtual bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const = 0; @@ -45,6 +70,9 @@ public: virtual float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const = 0; + virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id, + const MinikinPaint &paint) const = 0; + // If buf is NULL, just update size virtual bool GetTable(uint32_t tag, uint8_t *buf, size_t *size) = 0; diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index baac98c39dd..5e134954a04 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -32,13 +32,15 @@ LOCAL_MODULE := libminikin LOCAL_C_INCLUDES += \ external/harfbuzz_ng/src \ external/freetype/include \ + external/icu4c/common \ frameworks/minikin/include LOCAL_SHARED_LIBRARIES := \ libharfbuzz_ng \ libft2 \ + liblog \ libpng \ libz \ libstlport -include $(BUILD_STATIC_LIBRARY) +include $(BUILD_SHARED_LIBRARY) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 702bd2097fc..aa37825da61 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -14,9 +14,10 @@ * limitations under the License. */ -#ifdef VERBOSE_DEBUG -#include // for debugging - remove -#endif +// #define VERBOSE_DEBUG + +#define LOG_TAG "Minikin" +#include #include #include @@ -35,7 +36,7 @@ FontCollection::FontCollection(const vector& typefaces) : vector lastChar; size_t nTypefaces = typefaces.size(); #ifdef VERBOSE_DEBUG - printf("nTypefaces = %d\n", nTypefaces); + ALOGD("nTypefaces = %d\n", nTypefaces); #endif const FontStyle defaultStyle; for (size_t i = 0; i < nTypefaces; i++) { @@ -47,7 +48,7 @@ FontCollection::FontCollection(const vector& typefaces) : instance->mCoverage = new SparseBitSet; MinikinFont* typeface = family->getClosestMatch(defaultStyle); #ifdef VERBOSE_DEBUG - printf("closest match = %x, family size = %d\n", typeface, family->getNumFonts()); + ALOGD("closest match = %p, family size = %d\n", typeface, family->getNumFonts()); #endif const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); size_t cmapSize = 0; @@ -56,7 +57,7 @@ FontCollection::FontCollection(const vector& typefaces) : ok = typeface->GetTable(cmapTag, cmapData.get(), &cmapSize); CmapCoverage::getCoverage(*instance->mCoverage, cmapData.get(), cmapSize); #ifdef VERBOSE_DEBUG - printf("font coverage length=%d, first ch=%x\n", instance->mCoverage->length(), + ALOGD("font coverage length=%d, first ch=%x\n", instance->mCoverage->length(), instance->mCoverage->nextSetBit(0)); #endif mMaxChar = max(mMaxChar, instance->mCoverage->length()); @@ -70,7 +71,7 @@ FontCollection::FontCollection(const vector& typefaces) : mRanges.push_back(dummy); Range* range = &mRanges.back(); #ifdef VERBOSE_DEBUG - printf("i=%d: range start = %d\n", i, offset); + ALOGD("i=%d: range start = %d\n", i, offset); #endif range->start = offset; for (size_t j = 0; j < nTypefaces; j++) { @@ -80,7 +81,7 @@ FontCollection::FontCollection(const vector& typefaces) : offset++; uint32_t nextChar = instance->mCoverage->nextSetBit((i + 1) << kLogCharsPerPage); #ifdef VERBOSE_DEBUG - printf("nextChar = %d (j = %d)\n", nextChar, j); + ALOGD("nextChar = %d (j = %d)\n", nextChar, j); #endif lastChar[j] = nextChar; } @@ -102,7 +103,7 @@ const FontFamily* FontCollection::getFamilyForChar(uint32_t ch) const { } const Range& range = mRanges[ch >> kLogCharsPerPage]; #ifdef VERBOSE_DEBUG - printf("querying range %d:%d\n", range.start, range.end); + ALOGD("querying range %d:%d\n", range.start, range.end); #endif for (size_t i = range.start; i < range.end; i++) { const FontInstance* instance = mInstanceVec[i]; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 558fd77c168..16031cee38a 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -51,7 +51,6 @@ bool FontFamily::addFont(MinikinFont* typeface) { void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { mFonts.push_back(Font(typeface, style)); - ALOGD("added font, mFonts.size() = %d", mFonts.size()); } // Compute a matching metric between two styles - 0 is an exact match diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index d4e09c5dfe7..ffaa451813d 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -14,12 +14,19 @@ * limitations under the License. */ +#define LOG_TAG "Minikin" +#include + #include #include #include #include // for debugging #include // ditto +#include + +#include + #include #include @@ -31,6 +38,8 @@ namespace android { // TODO: globals are not cool, move to a factory-ish object hb_buffer_t* buffer = 0; +Mutex gLock; + Bitmap::Bitmap(int width, int height) : width(width), height(height) { buf = new uint8_t[width * height](); } @@ -69,11 +78,23 @@ void Bitmap::drawGlyph(const GlyphBitmap& bitmap, int x, int y) { } } +void MinikinRect::join(const MinikinRect& r) { + if (isEmpty()) { + set(r); + } else if (!r.isEmpty()) { + mLeft = std::min(mLeft, r.mLeft); + mTop = std::min(mTop, r.mTop); + mRight = std::max(mRight, r.mRight); + mBottom = std::max(mBottom, r.mBottom); + } +} + +// TODO: the actual initialization is deferred, maybe make this explicit void Layout::init() { - buffer = hb_buffer_create(); } void Layout::setFontCollection(const FontCollection *collection) { + ALOGD("setFontCollection(%p)", collection); mCollection = collection; } @@ -193,8 +214,76 @@ static FontStyle styleFromCss(const CssProperties &props) { return FontStyle(weight, italic); } +static hb_script_t codePointToScript(hb_codepoint_t codepoint) { + static hb_unicode_funcs_t *u = 0; + if (!u) { + u = hb_icu_get_unicode_funcs(); + } + return hb_unicode_script(u, codepoint); +} + +static hb_codepoint_t decodeUtf16(const uint16_t *chars, size_t len, ssize_t *iter) { + const uint16_t v = chars[(*iter)++]; + // test whether v in (0xd800..0xdfff), lead or trail surrogate + if ((v & 0xf800) == 0xd800) { + // test whether v in (0xd800..0xdbff), lead surrogate + if (size_t(*iter) < len && (v & 0xfc00) == 0xd800) { + const uint16_t v2 = chars[(*iter)++]; + // test whether v2 in (0xdc00..0xdfff), trail surrogate + if ((v2 & 0xfc00) == 0xdc00) { + // (0xd800 0xdc00) in utf-16 maps to 0x10000 in ucs-32 + const hb_codepoint_t delta = (0xd800 << 10) + 0xdc00 - 0x10000; + return (((hb_codepoint_t)v) << 10) + v2 - delta; + } + (*iter) -= 2; + return ~0u; + } else { + (*iter)--; + return ~0u; + } + } else { + return v; + } +} + +static hb_script_t getScriptRun(const uint16_t *chars, size_t len, ssize_t *iter) { + if (size_t(*iter) == len) { + return HB_SCRIPT_UNKNOWN; + } + uint32_t cp = decodeUtf16(chars, len, iter); + hb_script_t current_script = codePointToScript(cp); + for (;;) { + if (size_t(*iter) == len) + break; + const ssize_t prev_iter = *iter; + cp = decodeUtf16(chars, len, iter); + const hb_script_t script = codePointToScript(cp); + if (script != current_script) { + if (current_script == HB_SCRIPT_INHERITED || + current_script == HB_SCRIPT_COMMON) { + current_script = script; + } else if (script == HB_SCRIPT_INHERITED || + script == HB_SCRIPT_COMMON) { + continue; + } else { + *iter = prev_iter; + break; + } + } + } + if (current_script == HB_SCRIPT_INHERITED) { + current_script = HB_SCRIPT_COMMON; + } + + return current_script; +} + // TODO: API should probably take context void Layout::doLayout(const uint16_t* buf, size_t nchars) { + AutoMutex _l(gLock); + if (buffer == 0) { + buffer = hb_buffer_create(); + } FT_Error error; vector items; @@ -208,6 +297,9 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { mGlyphs.clear(); mFaces.clear(); mHbFonts.clear(); + mBounds.setEmpty(); + mAdvances.clear(); + mAdvances.resize(nchars, 0); float x = 0; float y = 0; for (size_t run_ix = 0; run_ix < items.size(); run_ix++) { @@ -215,6 +307,10 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { int font_ix = findFace(run.font, &paint); paint.font = mFaces[font_ix]; hb_font_t *hbFont = mHbFonts[font_ix]; + if (paint.font == NULL) { + // TODO: should log what went wrong + continue; + } #ifdef VERBOSE std::cout << "Run " << run_ix << ", font " << font_ix << " [" << run.start << ":" << run.end << "]" << std::endl; @@ -222,24 +318,38 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { hb_font_set_ppem(hbFont, size, size); hb_font_set_scale(hbFont, HBFloatToFixed(size), HBFloatToFixed(size)); - hb_buffer_reset(buffer); - hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); - hb_buffer_add_utf16(buffer, buf, nchars, run.start, run.end - run.start); - hb_shape(hbFont, buffer, NULL, 0); - unsigned int numGlyphs; - hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, &numGlyphs); - hb_glyph_position_t *positions = hb_buffer_get_glyph_positions(buffer, NULL); - for (unsigned int i = 0; i < numGlyphs; i++) { -#ifdef VERBOSE - std::cout << positions[i].x_advance << " " << positions[i].y_advance << " " << positions[i].x_offset << " " << positions[i].y_offset << std::endl; std::cout << "DoLayout " << info[i].codepoint << - ": " << HBFixedToFloat(positions[i].x_advance) << "; " << positions[i].x_offset << ", " << positions[i].y_offset << std::endl; -#endif - hb_codepoint_t glyph_ix = info[i].codepoint; - float xoff = HBFixedToFloat(positions[i].x_offset); - float yoff = HBFixedToFloat(positions[i].y_offset); - LayoutGlyph glyph = {font_ix, glyph_ix, x + xoff, y + yoff}; - mGlyphs.push_back(glyph); - x += HBFixedToFloat(positions[i].x_advance); + int srunend; + for (int srunstart = run.start; srunstart < run.end; srunstart = srunend) { + srunend = srunstart; + hb_script_t script = getScriptRun(buf, run.end, &srunend); + + hb_buffer_reset(buffer); + hb_buffer_set_script(buffer, script); + hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); + hb_buffer_add_utf16(buffer, buf, nchars, srunstart, srunend - srunstart); + hb_shape(hbFont, buffer, NULL, 0); + unsigned int numGlyphs; + hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, &numGlyphs); + hb_glyph_position_t *positions = hb_buffer_get_glyph_positions(buffer, NULL); + for (unsigned int i = 0; i < numGlyphs; i++) { + #ifdef VERBOSE + std::cout << positions[i].x_advance << " " << positions[i].y_advance << " " << positions[i].x_offset << " " << positions[i].y_offset << std::endl; std::cout << "DoLayout " << info[i].codepoint << + ": " << HBFixedToFloat(positions[i].x_advance) << "; " << positions[i].x_offset << ", " << positions[i].y_offset << std::endl; + #endif + hb_codepoint_t glyph_ix = info[i].codepoint; + float xoff = HBFixedToFloat(positions[i].x_offset); + float yoff = HBFixedToFloat(positions[i].y_offset); + LayoutGlyph glyph = {font_ix, glyph_ix, x + xoff, y + yoff}; + mGlyphs.push_back(glyph); + float xAdvance = HBFixedToFloat(positions[i].x_advance); + MinikinRect glyphBounds; + paint.font->GetBounds(&glyphBounds, glyph_ix, paint); + glyphBounds.offset(x + xoff, y + yoff); + mBounds.join(glyphBounds); + size_t cluster = info[i].cluster; + mAdvances[cluster] += xAdvance; + x += xAdvance; + } } } mAdvance = x; @@ -275,8 +385,40 @@ void Layout::setProperties(string css) { mProps.parse(css); } +size_t Layout::nGlyphs() const { + return mGlyphs.size(); +} + +MinikinFont *Layout::getFont(int i) const { + const LayoutGlyph& glyph = mGlyphs[i]; + return mFaces[glyph.font_ix]; +} + +unsigned int Layout::getGlyphId(int i) const { + const LayoutGlyph& glyph = mGlyphs[i]; + return glyph.glyph_id; +} + +float Layout::getX(int i) const { + const LayoutGlyph& glyph = mGlyphs[i]; + return glyph.x; +} + +float Layout::getY(int i) const { + const LayoutGlyph& glyph = mGlyphs[i]; + return glyph.y; +} + float Layout::getAdvance() const { return mAdvance; } +void Layout::getAdvances(float* advances) { + memcpy(advances, &mAdvances[0], mAdvances.size() * sizeof(float)); +} + +void Layout::getBounds(MinikinRect* bounds) { + bounds->set(mBounds); +} + } // namespace android diff --git a/engine/src/flutter/sample/Android.mk b/engine/src/flutter/sample/Android.mk index 939aca49f36..a19019ad829 100644 --- a/engine/src/flutter/sample/Android.mk +++ b/engine/src/flutter/sample/Android.mk @@ -36,10 +36,40 @@ LOCAL_SHARED_LIBRARIES += \ libicuuc \ libft2 \ libpng \ - libz - -LOCAL_STATIC_LIBRARIES += libminikin + libz \ + libminikin LOCAL_MODULE:= minikin_example include $(BUILD_EXECUTABLE) + + +include $(CLEAR_VARS) +include external/stlport/libstlport.mk + +LOCAL_MODULE_TAG := tests + +LOCAL_C_INCLUDES += \ + external/harfbuzz_ng/src \ + external/freetype/include \ + external/icu4c/common \ + frameworks/minikin/include \ + external/skia/src/core + +LOCAL_SRC_FILES:= example_skia.cpp \ + MinikinSkia.cpp + +LOCAL_SHARED_LIBRARIES += \ + libutils \ + liblog \ + libcutils \ + libstlport \ + libharfbuzz_ng \ + libicuuc \ + libskia \ + libminikin \ + libft2 + +LOCAL_MODULE:= minikin_skia_example + +include $(BUILD_EXECUTABLE) diff --git a/engine/src/flutter/sample/MinikinSkia.cpp b/engine/src/flutter/sample/MinikinSkia.cpp new file mode 100644 index 00000000000..d67e59fbbcc --- /dev/null +++ b/engine/src/flutter/sample/MinikinSkia.cpp @@ -0,0 +1,64 @@ +#include +#include + +#include +#include "MinikinSkia.h" + +namespace android { + +MinikinFontSkia::MinikinFontSkia(SkTypeface *typeface) : + mTypeface(typeface) { +} + +MinikinFontSkia::~MinikinFontSkia() { + SkSafeUnref(mTypeface); +} + +bool MinikinFontSkia::GetGlyph(uint32_t codepoint, uint32_t *glyph) const { + SkPaint paint; + paint.setTypeface(mTypeface); + paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); + uint16_t glyph16; + paint.textToGlyphs(&codepoint, sizeof(codepoint), &glyph16); + *glyph = glyph16; + //printf("glyph for U+%04x = %d\n", codepoint, glyph16); + return !!glyph; +} + +float MinikinFontSkia::GetHorizontalAdvance(uint32_t glyph_id, + const MinikinPaint &paint) const { + SkPaint skpaint; + skpaint.setTypeface(mTypeface); + skpaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); + // TODO: set paint from Minikin + skpaint.setTextSize(100); + uint16_t glyph16 = glyph_id; + SkScalar skWidth; + SkRect skBounds; + skpaint.getTextWidths(&glyph16, sizeof(glyph16), &skWidth, &skBounds); + // bounds? + //printf("advance for glyph %d = %f\n", glyph_id, SkScalarToFP(skWidth)); + return skWidth; +} + +bool MinikinFontSkia::GetTable(uint32_t tag, uint8_t *buf, size_t *size) { + if (buf == NULL) { + const size_t tableSize = mTypeface->getTableSize(tag); + *size = tableSize; + return tableSize != 0; + } else { + const size_t actualSize = mTypeface->getTableData(tag, 0, *size, buf); + *size = actualSize; + return actualSize != 0; + } +} + +SkTypeface *MinikinFontSkia::GetSkTypeface() { + return mTypeface; +} + +int32_t MinikinFontSkia::GetUniqueId() const { + return mTypeface->uniqueID(); +} + +} diff --git a/engine/src/flutter/sample/MinikinSkia.h b/engine/src/flutter/sample/MinikinSkia.h new file mode 100644 index 00000000000..8286a4c5c6b --- /dev/null +++ b/engine/src/flutter/sample/MinikinSkia.h @@ -0,0 +1,26 @@ +namespace android { + +class MinikinFontSkia : public MinikinFont { +public: + explicit MinikinFontSkia(SkTypeface *typeface); + + ~MinikinFontSkia(); + + bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const; + + float GetHorizontalAdvance(uint32_t glyph_id, + const MinikinPaint &paint) const; + + // If buf is NULL, just update size + bool GetTable(uint32_t tag, uint8_t *buf, size_t *size); + + int32_t GetUniqueId() const; + + SkTypeface *GetSkTypeface(); + +private: + SkTypeface *mTypeface; + +}; + +} // namespace android \ No newline at end of file diff --git a/engine/src/flutter/sample/example_skia.cpp b/engine/src/flutter/sample/example_skia.cpp new file mode 100644 index 00000000000..ff13b5c1873 --- /dev/null +++ b/engine/src/flutter/sample/example_skia.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2013 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. + */ + +// This is a test program that uses Minikin to layout and draw some text. +// At the moment, it just draws a string into /data/local/tmp/foo.pgm. + +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include "MinikinSkia.h" + +using std::vector; + +namespace android { + +FT_Library library; // TODO: this should not be a global + +FontCollection *makeFontCollection() { + vectortypefaces; + const char *fns[] = { + "/system/fonts/Roboto-Regular.ttf", + "/system/fonts/Roboto-Italic.ttf", + "/system/fonts/Roboto-BoldItalic.ttf", + "/system/fonts/Roboto-Light.ttf", + "/system/fonts/Roboto-Thin.ttf", + "/system/fonts/Roboto-Bold.ttf", + "/system/fonts/Roboto-ThinItalic.ttf", + "/system/fonts/Roboto-LightItalic.ttf" + }; + + FontFamily *family = new FontFamily(); + FT_Face face; + FT_Error error; + for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) { + const char *fn = fns[i]; + SkTypeface *skFace = SkTypeface::CreateFromFile(fn); + MinikinFont *font = new MinikinFontSkia(skFace); + family->addFont(font); + } + typefaces.push_back(family); + +#if 1 + family = new FontFamily(); + const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf"; + SkTypeface *skFace = SkTypeface::CreateFromFile(fn); + MinikinFont *font = new MinikinFontSkia(skFace); + family->addFont(font); + typefaces.push_back(family); +#endif + + return new FontCollection(typefaces); +} + +// Maybe move to MinikinSkia (esp. instead of opening GetSkTypeface publicly)? + +void drawToSkia(SkCanvas *canvas, SkPaint *paint, Layout *layout, float x, float y) { + size_t nGlyphs = layout->nGlyphs(); + uint16_t *glyphs = new uint16_t[nGlyphs]; + SkPoint *pos = new SkPoint[nGlyphs]; + SkTypeface *lastFace = NULL; + SkTypeface *skFace = NULL; + size_t start = 0; + + paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); + for (size_t i = 0; i < nGlyphs; i++) { + MinikinFontSkia *mfs = static_cast(layout->getFont(i)); + skFace = mfs->GetSkTypeface(); + glyphs[i] = layout->getGlyphId(i); + pos[i].fX = SkFloatToScalar(x + layout->getX(i)); + pos[i].fY = SkFloatToScalar(y + layout->getY(i)); + if (i > 0 && skFace != lastFace) { + paint->setTypeface(lastFace); + canvas->drawPosText(glyphs + start, (i - start) << 1, pos + start, *paint); + start = i; + } + lastFace = skFace; + } + paint->setTypeface(skFace); + canvas->drawPosText(glyphs + start, (nGlyphs - start) << 1, pos + start, *paint); + delete[] glyphs; + delete[] pos; +} + +int runMinikinTest() { + FT_Error error = FT_Init_FreeType(&library); + if (error) { + return -1; + } + Layout::init(); + + FontCollection *collection = makeFontCollection(); + Layout layout; + layout.setFontCollection(collection); + layout.setProperties("font-size: 32; font-weight: 700;"); + const char *text = "fine world \xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa5\x87"; + icu::UnicodeString icuText = icu::UnicodeString::fromUTF8(text); + layout.doLayout(icuText.getBuffer(), icuText.length()); + layout.dump(); + + SkAutoGraphics ag; + + SkScalar width = 800; + SkScalar height = 600; + SkBitmap bitmap; + bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); + bitmap.allocPixels(); + SkCanvas canvas(bitmap); + SkPaint paint; + paint.setARGB(255, 0, 0, 128); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(2); + paint.setTextSize(100); + paint.setAntiAlias(true); + canvas.drawLine(10, 300, 10 + layout.getAdvance(), 300, paint); + paint.setStyle(SkPaint::kFill_Style); + drawToSkia(&canvas, &paint, &layout, 10, 300); + + SkImageEncoder::EncodeFile("/data/local/tmp/foo.png", bitmap, SkImageEncoder::kPNG_Type, 100); + return 0; +} + +} + +int main(int argc, const char** argv) { + return android::runMinikinTest(); +} From 02b919bc17dce9d91a29a1d8faeb628bc8913fa9 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 5 May 2014 16:11:17 -0700 Subject: [PATCH 009/364] Better refcounting and locking All major externally accessible objects (especially FontFamily and FontCollection) are now reference counted. In addition, there is a global lock intended to make operations thread-safe. WIP notice: in this version of the patch, not all external API entry points are protected by the lock. That should be fixed. Change-Id: I14106196e99eb101e8bf1bcb4b81359759d2086c --- .../flutter/include/minikin/FontCollection.h | 11 ++--- .../src/flutter/include/minikin/FontFamily.h | 6 ++- .../src/flutter/include/minikin/MinikinFont.h | 19 ++------- .../include/minikin/MinikinRefCounted.h | 42 +++++++++++++++++++ engine/src/flutter/libs/minikin/Android.mk | 2 + .../flutter/libs/minikin/FontCollection.cpp | 6 +-- .../src/flutter/libs/minikin/FontFamily.cpp | 7 ++++ engine/src/flutter/libs/minikin/Layout.cpp | 7 +--- .../flutter/libs/minikin/MinikinInternal.cpp | 25 +++++++++++ .../flutter/libs/minikin/MinikinInternal.h | 34 +++++++++++++++ .../libs/minikin/MinikinRefCounted.cpp | 35 ++++++++++++++++ 11 files changed, 164 insertions(+), 30 deletions(-) create mode 100644 engine/src/flutter/include/minikin/MinikinRefCounted.h create mode 100644 engine/src/flutter/libs/minikin/MinikinInternal.cpp create mode 100644 engine/src/flutter/libs/minikin/MinikinInternal.h create mode 100644 engine/src/flutter/libs/minikin/MinikinRefCounted.cpp diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index a2a5391fc7e..dc48f8e0a24 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -19,13 +19,14 @@ #include +#include #include #include #include namespace android { -class FontCollection { +class FontCollection : public MinikinRefCounted { public: explicit FontCollection(const std::vector& typefaces); @@ -37,17 +38,17 @@ public: // Do copy constructor, assignment, destructor so it can be used in vectors Run() : font(NULL) { } Run(const Run& other): font(other.font), start(other.start), end(other.end) { - if (font) font->Ref(); + if (font) font->RefLocked(); } Run& operator=(const Run& other) { - if (other.font) other.font->Ref(); - if (font) font->Unref(); + if (other.font) other.font->RefLocked(); + if (font) font->UnrefLocked(); font = other.font; start = other.start; end = other.end; return *this; } - ~Run() { if (font) font->Unref(); } + ~Run() { if (font) font->UnrefLocked(); } MinikinFont* font; int start; diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 290220bbad2..3b59017631a 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -19,6 +19,8 @@ #include +#include + namespace android { // FontStyle represents all style information needed to select an actual font @@ -39,8 +41,10 @@ private: uint32_t bits; }; -class FontFamily { +class FontFamily : public MinikinRefCounted { public: + ~FontFamily(); + // Add font to family, extracting style information from the font bool addFont(MinikinFont* typeface); diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index e84f5df63f2..568f19da7fe 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -17,6 +17,8 @@ #ifndef MINIKIN_FONT_H #define MINIKIN_FONT_H +#include + // An abstraction for platform fonts, allowing Minikin to be used with // multiple actual implementations of fonts. @@ -56,15 +58,8 @@ struct MinikinRect { class MinikinFontFreeType; -class MinikinFont { +class MinikinFont : public MinikinRefCounted { public: - void Ref() { mRefcount_++; } - void Unref() { if (--mRefcount_ == 0) { delete this; } } - - MinikinFont() : mRefcount_(1) { } - - virtual ~MinikinFont() { }; - virtual bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const = 0; virtual float GetHorizontalAdvance(uint32_t glyph_id, @@ -82,14 +77,6 @@ public: return ((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) | ((uint32_t)c3 << 8) | (uint32_t)c4; } - - // This is used to implement a downcast without RTTI - virtual MinikinFontFreeType* GetFreeType() { - return NULL; - } - -private: - int mRefcount_; }; } // namespace android diff --git a/engine/src/flutter/include/minikin/MinikinRefCounted.h b/engine/src/flutter/include/minikin/MinikinRefCounted.h new file mode 100644 index 00000000000..74d27fec7d3 --- /dev/null +++ b/engine/src/flutter/include/minikin/MinikinRefCounted.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2014 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. + */ + +// Base class for reference counted objects in Minikin + +#ifndef MINIKIN_REF_COUNTED_H +#define MINIKIN_REF_COUNTED_H + +namespace android { + +class MinikinRefCounted { +public: + void RefLocked() { mRefcount_++; } + void UnrefLocked() { if (--mRefcount_ == 0) { delete this; } } + + // These refcount operations take the global lock. + void Ref(); + void Unref(); + + MinikinRefCounted() : mRefcount_(1) { } + + virtual ~MinikinRefCounted() { }; +private: + int mRefcount_; +}; + +} + +#endif // MINIKIN_REF_COUNTED_H \ No newline at end of file diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 5e134954a04..c4412859c41 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -24,6 +24,8 @@ LOCAL_SRC_FILES := \ FontCollection.cpp \ FontFamily.cpp \ Layout.cpp \ + MinikinInternal.cpp \ + MinikinRefCounted.cpp \ MinikinFontFreeType.cpp \ SparseBitSet.cpp diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index aa37825da61..18e528efb05 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -41,6 +41,7 @@ FontCollection::FontCollection(const vector& typefaces) : const FontStyle defaultStyle; for (size_t i = 0; i < nTypefaces; i++) { FontFamily* family = typefaces[i]; + family->RefLocked(); FontInstance dummy; mInstances.push_back(dummy); // emplace_back would be better FontInstance* instance = &mInstances.back(); @@ -62,7 +63,6 @@ FontCollection::FontCollection(const vector& typefaces) : #endif mMaxChar = max(mMaxChar, instance->mCoverage->length()); lastChar.push_back(instance->mCoverage->nextSetBit(0)); - // TODO: should probably ref typeface here, hmm } size_t nPages = mMaxChar >> kLogCharsPerPage; size_t offset = 0; @@ -93,7 +93,7 @@ FontCollection::FontCollection(const vector& typefaces) : FontCollection::~FontCollection() { for (size_t i = 0; i < mInstances.size(); i++) { delete mInstances[i].mCoverage; - // probably unref the typeface here too + mInstances[i].mFamily->UnrefLocked(); } } @@ -138,7 +138,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty run->font = NULL; // maybe we should do something different here } else { run->font = family->getClosestMatch(style); - run->font->Ref(); + run->font->RefLocked(); } lastFamily = family; run->start = i; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 16031cee38a..d8525ffa6de 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -28,6 +28,12 @@ using std::vector; namespace android { +FontFamily::~FontFamily() { + for (size_t i = 0; i < mFonts.size(); i++) { + mFonts[i].typeface->UnrefLocked(); + } +} + bool FontFamily::addFont(MinikinFont* typeface) { const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2'); size_t os2Size = 0; @@ -50,6 +56,7 @@ bool FontFamily::addFont(MinikinFont* typeface) { } void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { + typeface->RefLocked(); mFonts.push_back(Font(typeface, style)); } diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index ffaa451813d..20e2d9e45b8 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -25,8 +25,7 @@ #include -#include - +#include "MinikinInternal.h" #include #include @@ -38,8 +37,6 @@ namespace android { // TODO: globals are not cool, move to a factory-ish object hb_buffer_t* buffer = 0; -Mutex gLock; - Bitmap::Bitmap(int width, int height) : width(width), height(height) { buf = new uint8_t[width * height](); } @@ -280,7 +277,7 @@ static hb_script_t getScriptRun(const uint16_t *chars, size_t len, ssize_t *iter // TODO: API should probably take context void Layout::doLayout(const uint16_t* buf, size_t nchars) { - AutoMutex _l(gLock); + AutoMutex _l(gMinikinLock); if (buffer == 0) { buffer = hb_buffer_create(); } diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp new file mode 100644 index 00000000000..71c8649b1e3 --- /dev/null +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2014 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. + */ + +// Definitions internal to Minikin + +#include "MinikinInternal.h" + +namespace android { + +Mutex gMinikinLock; + +} diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.h b/engine/src/flutter/libs/minikin/MinikinInternal.h new file mode 100644 index 00000000000..b8430df550b --- /dev/null +++ b/engine/src/flutter/libs/minikin/MinikinInternal.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2014 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. + */ + +// Definitions internal to Minikin + +#ifndef MINIKIN_INTERNAL_H +#define MINIKIN_INTERNAL_H + +#include + +namespace android { + +// All external Minikin interfaces are designed to be thread-safe. +// Presently, that's implemented by through a global lock, and having +// all external interfaces take that lock. + +extern Mutex gMinikinLock; + +} + +#endif // MINIKIN_INTERNAL_H diff --git a/engine/src/flutter/libs/minikin/MinikinRefCounted.cpp b/engine/src/flutter/libs/minikin/MinikinRefCounted.cpp new file mode 100644 index 00000000000..9fa3ae46317 --- /dev/null +++ b/engine/src/flutter/libs/minikin/MinikinRefCounted.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2014 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. + */ + +// Base class for reference counted objects in Minikin + +#include "MinikinInternal.h" + +#include + +namespace android { + +void MinikinRefCounted::Ref() { + AutoMutex _l(gMinikinLock); + this->RefLocked(); +} + +void MinikinRefCounted::Unref() { + AutoMutex _l(gMinikinLock); + this->UnrefLocked(); +} + +} From 7b250767bc37242995b8faff6e497b1055465ac8 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 14 May 2014 11:01:32 -0700 Subject: [PATCH 010/364] Fix build breakage in sample code This updates the Skia sample implementation to implement GetBounds, but the FreeType implementation is NYI (to be fixed in future commit). Change-Id: I24eda14d5fb11c2a1e81394ad8c779de3292dd79 --- .../include/minikin/MinikinFontFreeType.h | 3 ++ .../libs/minikin/MinikinFontFreeType.cpp | 5 +++ engine/src/flutter/sample/MinikinSkia.cpp | 35 ++++++++++++++----- engine/src/flutter/sample/MinikinSkia.h | 3 ++ 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/engine/src/flutter/include/minikin/MinikinFontFreeType.h b/engine/src/flutter/include/minikin/MinikinFontFreeType.h index 70518319acf..13a513982b3 100644 --- a/engine/src/flutter/include/minikin/MinikinFontFreeType.h +++ b/engine/src/flutter/include/minikin/MinikinFontFreeType.h @@ -47,6 +47,9 @@ public: float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const; + void GetBounds(MinikinRect* bounds, uint32_t glyph_id, + const MinikinPaint& paint) const; + // If buf is NULL, just update size bool GetTable(uint32_t tag, uint8_t *buf, size_t *size); diff --git a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp index be61345a9cb..a251ddadbf1 100644 --- a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp @@ -53,6 +53,11 @@ float MinikinFontFreeType::GetHorizontalAdvance(uint32_t glyph_id, return advance * (1.0 / 65536); } +void MinikinFontFreeType::GetBounds(MinikinRect* bounds, uint32_t glyph_id, + const MinikinPaint& paint) const { + // TODO: NYI +} + bool MinikinFontFreeType::GetTable(uint32_t tag, uint8_t *buf, size_t *size) { FT_ULong ftsize = *size; FT_Error error = FT_Load_Sfnt_Table(mTypeface, tag, 0, buf, &ftsize); diff --git a/engine/src/flutter/sample/MinikinSkia.cpp b/engine/src/flutter/sample/MinikinSkia.cpp index d67e59fbbcc..8b499d81312 100644 --- a/engine/src/flutter/sample/MinikinSkia.cpp +++ b/engine/src/flutter/sample/MinikinSkia.cpp @@ -25,22 +25,39 @@ bool MinikinFontSkia::GetGlyph(uint32_t codepoint, uint32_t *glyph) const { return !!glyph; } +static void MinikinFontSkia_SetSkiaPaint(SkTypeface* typeface, SkPaint* skPaint, const MinikinPaint& paint) { + skPaint->setTypeface(typeface); + skPaint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); + // TODO: set more paint parameters from Minikin + skPaint->setTextSize(paint.size); +} + float MinikinFontSkia::GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const { - SkPaint skpaint; - skpaint.setTypeface(mTypeface); - skpaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); - // TODO: set paint from Minikin - skpaint.setTextSize(100); + SkPaint skPaint; uint16_t glyph16 = glyph_id; SkScalar skWidth; - SkRect skBounds; - skpaint.getTextWidths(&glyph16, sizeof(glyph16), &skWidth, &skBounds); - // bounds? - //printf("advance for glyph %d = %f\n", glyph_id, SkScalarToFP(skWidth)); + MinikinFontSkia_SetSkiaPaint(mTypeface, &skPaint, paint); + skPaint.getTextWidths(&glyph16, sizeof(glyph16), &skWidth, NULL); +#ifdef VERBOSE + ALOGD("width for typeface %d glyph %d = %f", mTypeface->uniqueID(), glyph_id +#endif return skWidth; } +void MinikinFontSkia::GetBounds(MinikinRect* bounds, uint32_t glyph_id, + const MinikinPaint& paint) const { + SkPaint skPaint; + uint16_t glyph16 = glyph_id; + SkRect skBounds; + MinikinFontSkia_SetSkiaPaint(mTypeface, &skPaint, paint); + skPaint.getTextWidths(&glyph16, sizeof(glyph16), NULL, &skBounds); + bounds->mLeft = skBounds.fLeft; + bounds->mTop = skBounds.fTop; + bounds->mRight = skBounds.fRight; + bounds->mBottom = skBounds.fBottom; +} + bool MinikinFontSkia::GetTable(uint32_t tag, uint8_t *buf, size_t *size) { if (buf == NULL) { const size_t tableSize = mTypeface->getTableSize(tag); diff --git a/engine/src/flutter/sample/MinikinSkia.h b/engine/src/flutter/sample/MinikinSkia.h index 8286a4c5c6b..fca6ca23228 100644 --- a/engine/src/flutter/sample/MinikinSkia.h +++ b/engine/src/flutter/sample/MinikinSkia.h @@ -11,6 +11,9 @@ public: float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const; + void GetBounds(MinikinRect* bounds, uint32_t glyph_id, + const MinikinPaint& paint) const; + // If buf is NULL, just update size bool GetTable(uint32_t tag, uint8_t *buf, size_t *size); From df405e1da1439864d4596c97e4675ba582fbe45e Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 14 May 2014 12:33:09 -0700 Subject: [PATCH 011/364] Fix 64-bit cleanliness problem This patch fixes a problem where int and ssize_t were being conflated. Change-Id: I642a4ee1d59d81723034fdfe33bd8ca29a5dc322 --- engine/src/flutter/libs/minikin/Layout.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 20e2d9e45b8..08365b354ec 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -315,8 +315,8 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { hb_font_set_ppem(hbFont, size, size); hb_font_set_scale(hbFont, HBFloatToFixed(size), HBFloatToFixed(size)); - int srunend; - for (int srunstart = run.start; srunstart < run.end; srunstart = srunend) { + ssize_t srunend; + for (ssize_t srunstart = run.start; srunstart < run.end; srunstart = srunend) { srunend = srunstart; hb_script_t script = getScriptRun(buf, run.end, &srunend); From 686d245a0f231167240e156c010609275e571068 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 12 May 2014 15:10:30 -0700 Subject: [PATCH 012/364] Initial BiDi support This patch contains a very basic implementation of BiDi. It respects the BiDi flags passed in as an explicit parameter (through the "-minikin-bidi" pseudo-CSS property), but doesn't yet do its own BiDi run detection. It also takes some shortcuts (marked as TODO) that are based on reasonable assumptions of the current font stack, but not universally valid. Even with these shortcomings, it seems to display RTL text from TextView correctly. Change-Id: I223433923c4eb06f90c0327e86bfbe0aff71d4f5 --- engine/src/flutter/include/minikin/CssParse.h | 2 ++ engine/src/flutter/libs/minikin/CssParse.cpp | 1 + engine/src/flutter/libs/minikin/Layout.cpp | 13 +++++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/include/minikin/CssParse.h b/engine/src/flutter/include/minikin/CssParse.h index f79ba1f61ca..2dceb4ac26c 100644 --- a/engine/src/flutter/include/minikin/CssParse.h +++ b/engine/src/flutter/include/minikin/CssParse.h @@ -28,6 +28,7 @@ enum CssTag { fontWeight, fontStyle, minikinHinting, + minikinBidi, }; const std::string cssTagNames[] = { @@ -36,6 +37,7 @@ const std::string cssTagNames[] = { "font-weight", "font-style", "-minikin-hinting", + "-minikin-bidi", }; class CssValue { diff --git a/engine/src/flutter/libs/minikin/CssParse.cpp b/engine/src/flutter/libs/minikin/CssParse.cpp index d4de23bee05..5bb6949b9a2 100644 --- a/engine/src/flutter/libs/minikin/CssParse.cpp +++ b/engine/src/flutter/libs/minikin/CssParse.cpp @@ -41,6 +41,7 @@ CssTag parseTag(const string str, size_t off, size_t len) { if (strEqC(str, off, len, "font-style")) return fontStyle; } else if (c == '-') { if (strEqC(str, off, len, "-minikin-hinting")) return minikinHinting; + if (strEqC(str, off, len, "-minikin-bidi")) return minikinBidi; } return unknown; } diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 08365b354ec..3a0be6abefc 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -19,10 +19,12 @@ #include #include +#include #include #include // for debugging #include // ditto +#include #include #include "MinikinInternal.h" @@ -91,7 +93,6 @@ void Layout::init() { } void Layout::setFontCollection(const FontCollection *collection) { - ALOGD("setFontCollection(%p)", collection); mCollection = collection; } @@ -290,6 +291,11 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { MinikinPaint paint; double size = mProps.value(fontSize).getFloatValue(); paint.size = size; + int bidiFlags = mProps.hasTag(minikinBidi) ? mProps.value(minikinBidi).getIntValue() : 0; + bool isRtl = (bidiFlags & 1) != 0; // TODO: do real bidi algo + if (isRtl) { + std::reverse(items.begin(), items.end()); + } mGlyphs.clear(); mFaces.clear(); @@ -315,6 +321,9 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { hb_font_set_ppem(hbFont, size, size); hb_font_set_scale(hbFont, HBFloatToFixed(size), HBFloatToFixed(size)); + // TODO: if there are multiple scripts within a font in an RTL run, + // we need to reorder those runs. This is unlikely with our current + // font stack, but should be done for correctness. ssize_t srunend; for (ssize_t srunstart = run.start; srunstart < run.end; srunstart = srunend) { srunend = srunstart; @@ -322,7 +331,7 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { hb_buffer_reset(buffer); hb_buffer_set_script(buffer, script); - hb_buffer_set_direction(buffer, HB_DIRECTION_LTR); + hb_buffer_set_direction(buffer, isRtl? HB_DIRECTION_RTL : HB_DIRECTION_LTR); hb_buffer_add_utf16(buffer, buf, nchars, srunstart, srunend - srunstart); hb_shape(hbFont, buffer, NULL, 0); unsigned int numGlyphs; From 521c14790be4696a14b3b4a49d2c9846f4a90551 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Thu, 15 May 2014 10:52:56 -0400 Subject: [PATCH 013/364] Remove references to SkFloatToScalar. The macro has been deprecated, now that SkScalar is never fixed point. Fixes minikin build. Change-Id: I02838a7fa167c5cf58ad225f3f2f52659495492c --- engine/src/flutter/sample/example_skia.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/sample/example_skia.cpp b/engine/src/flutter/sample/example_skia.cpp index ff13b5c1873..e686621c345 100644 --- a/engine/src/flutter/sample/example_skia.cpp +++ b/engine/src/flutter/sample/example_skia.cpp @@ -92,8 +92,8 @@ void drawToSkia(SkCanvas *canvas, SkPaint *paint, Layout *layout, float x, float MinikinFontSkia *mfs = static_cast(layout->getFont(i)); skFace = mfs->GetSkTypeface(); glyphs[i] = layout->getGlyphId(i); - pos[i].fX = SkFloatToScalar(x + layout->getX(i)); - pos[i].fY = SkFloatToScalar(y + layout->getY(i)); + pos[i].fX = x + layout->getX(i); + pos[i].fY = y + layout->getY(i); if (i > 0 && skFace != lastFace) { paint->setTypeface(lastFace); canvas->drawPosText(glyphs + start, (i - start) << 1, pos + start, *paint); From 4841666ebe6aba70a957ee47ed26dbc3e63d189c Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 19 May 2014 13:21:21 -0700 Subject: [PATCH 014/364] Fix incomplete refcounting and locking These changes were supposed to be committed in the previous patch "Better refcounting and locking" but seem to have gotten lost in a rebase. It fixes a memory leak and some possible race conditions. Change-Id: I54ca1e37500ec49756fe317cc6d6d03da9911501 --- engine/src/flutter/include/minikin/FontFamily.h | 2 ++ engine/src/flutter/include/minikin/Layout.h | 6 ++++++ engine/src/flutter/libs/minikin/FontCollection.cpp | 2 ++ engine/src/flutter/libs/minikin/FontFamily.cpp | 11 +++++++++-- engine/src/flutter/libs/minikin/Layout.cpp | 7 +++++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 3b59017631a..82fcfe9af87 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -56,6 +56,8 @@ public: MinikinFont* getFont(size_t index) const; FontStyle getStyle(size_t index) const; private: + void addFontLocked(MinikinFont* typeface, FontStyle style); + class Font { public: Font(MinikinFont* typeface, FontStyle style) : diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 896478b219a..4fe9d8772fa 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -55,8 +55,14 @@ struct LayoutGlyph { float y; }; +// Lifecycle and threading assumptions for Layout: +// The object is assumed to be owned by a single thread; multiple threads +// may not mutate it at the same time. +// The lifetime of the FontCollection set through setFontCollection must +// extend through the lifetime of the Layout object. class Layout { public: + ~Layout(); void dump() const; void setFontCollection(const FontCollection* collection); diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 18e528efb05..cd7b19e0096 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -19,6 +19,7 @@ #define LOG_TAG "Minikin" #include +#include "MinikinInternal.h" #include #include @@ -33,6 +34,7 @@ static inline T max(T a, T b) { FontCollection::FontCollection(const vector& typefaces) : mMaxChar(0) { + AutoMutex _l(gMinikinLock); vector lastChar; size_t nTypefaces = typefaces.size(); #ifdef VERBOSE_DEBUG diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index d8525ffa6de..d818f77eec2 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -19,6 +19,8 @@ #include #include #include + +#include "MinikinInternal.h" #include #include #include @@ -35,6 +37,7 @@ FontFamily::~FontFamily() { } bool FontFamily::addFont(MinikinFont* typeface) { + AutoMutex _l(gMinikinLock); const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2'); size_t os2Size = 0; bool ok = typeface->GetTable(os2Tag, NULL, &os2Size); @@ -47,7 +50,7 @@ bool FontFamily::addFont(MinikinFont* typeface) { if (analyzeStyle(os2Data.get(), os2Size, &weight, &italic)) { //ALOGD("analyzed weight = %d, italic = %s", weight, italic ? "true" : "false"); FontStyle style(weight, italic); - addFont(typeface, style); + addFontLocked(typeface, style); return true; } else { ALOGD("failed to analyze style"); @@ -56,7 +59,11 @@ bool FontFamily::addFont(MinikinFont* typeface) { } void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { - typeface->RefLocked(); + AutoMutex _l(gMinikinLock); + addFontLocked(typeface, style); +} + +void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { typeface->RefLocked(); mFonts.push_back(Font(typeface, style)); } diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 3a0be6abefc..f32e9f4e4f9 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -161,6 +161,7 @@ hb_font_funcs_t* getHbFontFuncs() { hb_font_t* create_hb_font(MinikinFont* minikinFont, MinikinPaint* minikinPaint) { hb_face_t* face = hb_face_create_for_tables(referenceTable, minikinFont, NULL); hb_font_t* font = hb_font_create(face); + hb_face_destroy(face); hb_font_set_funcs(font, getHbFontFuncs(), minikinPaint, 0); // TODO: manage ownership of face return font; @@ -176,6 +177,12 @@ static hb_position_t HBFloatToFixed(float v) return scalbnf (v, +8); } +Layout::~Layout() { + for (size_t ix = 0; ix < mHbFonts.size(); ix++) { + hb_font_destroy(mHbFonts[ix]); + } +} + void Layout::dump() const { for (size_t i = 0; i < mGlyphs.size(); i++) { const LayoutGlyph& glyph = mGlyphs[i]; From e9ee2563318ba73da8674526388888d0dee5aca5 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 19 May 2014 11:58:20 -0700 Subject: [PATCH 015/364] Do BiDi algorithm for text layout This patch extends the previous BiDi support (when the direction for the entire string was given by the caller) to run the BiDi algorithm (provided by ICU) over the string to break it into BiDi runs. Thus, it handles mixed LTR and RTL strings in a single layout, and also respects heuristics for inferring the paragraph direction from the string. Change-Id: Ia4b869de3c139c5a7d16b8ce7766870b98a815ea --- engine/src/flutter/include/minikin/Layout.h | 4 + engine/src/flutter/libs/minikin/Android.mk | 3 +- engine/src/flutter/libs/minikin/Layout.cpp | 88 ++++++++++++++++++--- 3 files changed, 85 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 4fe9d8772fa..6c338db280e 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -94,6 +94,10 @@ private: // Find a face in the mFaces vector, or create a new entry int findFace(MinikinFont* face, MinikinPaint* paint); + // Lay out a single bidi run + void doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, FontStyle style, MinikinPaint& paint); + CssProperties mProps; // TODO: want spans std::vector mGlyphs; std::vector mAdvances; diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index c4412859c41..f1f035497af 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -43,6 +43,7 @@ LOCAL_SHARED_LIBRARIES := \ liblog \ libpng \ libz \ - libstlport + libstlport \ + libicuuc include $(BUILD_SHARED_LIBRARY) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index f32e9f4e4f9..918bc2e87d8 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -39,6 +39,21 @@ namespace android { // TODO: globals are not cool, move to a factory-ish object hb_buffer_t* buffer = 0; +// TODO: these should move into the header file, but for now we don't want +// to cause namespace collisions with TextLayout.h +enum { + kBidi_LTR = 0, + kBidi_RTL = 1, + kBidi_Default_LTR = 2, + kBidi_Default_RTL = 3, + kBidi_Force_LTR = 4, + kBidi_Force_RTL = 5, + + kBidi_Mask = 0x7 +}; + +const int kDirection_Mask = 0x1; + Bitmap::Bitmap(int width, int height) : width(width), height(height) { buf = new uint8_t[width * height](); } @@ -291,18 +306,14 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { } FT_Error error; - vector items; FontStyle style = styleFromCss(mProps); - mCollection->itemize(buf, nchars, style, &items); MinikinPaint paint; double size = mProps.value(fontSize).getFloatValue(); paint.size = size; int bidiFlags = mProps.hasTag(minikinBidi) ? mProps.value(minikinBidi).getIntValue() : 0; - bool isRtl = (bidiFlags & 1) != 0; // TODO: do real bidi algo - if (isRtl) { - std::reverse(items.begin(), items.end()); - } + bool isRtl = (bidiFlags & kDirection_Mask) != 0; + bool doSingleRun = true; mGlyphs.clear(); mFaces.clear(); @@ -310,7 +321,65 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { mBounds.setEmpty(); mAdvances.clear(); mAdvances.resize(nchars, 0); - float x = 0; + mAdvance = 0; + if (!(bidiFlags == kBidi_Force_LTR || bidiFlags == kBidi_Force_RTL)) { + UBiDi* bidi = ubidi_open(); + if (bidi) { + UErrorCode status = U_ZERO_ERROR; + UBiDiLevel bidiReq = bidiFlags; + if (bidiFlags == kBidi_Default_LTR) { + bidiReq = UBIDI_DEFAULT_LTR; + } else if (bidiFlags == kBidi_Default_RTL) { + bidiReq = UBIDI_DEFAULT_RTL; + } + ubidi_setPara(bidi, buf, nchars, bidiReq, NULL, &status); + if (U_SUCCESS(status)) { + int paraDir = ubidi_getParaLevel(bidi) & kDirection_Mask; + ssize_t rc = ubidi_countRuns(bidi, &status); + if (!U_SUCCESS(status) || rc < 1) { + ALOGD("error counting bidi runs, status = %d", status); + } + if (!U_SUCCESS(status) || rc <= 1) { + isRtl = (paraDir == kBidi_RTL); + } else { + doSingleRun = false; + // iterate through runs + for (ssize_t i = 0; i < (ssize_t)rc; i++) { + int32_t startRun = -1; + int32_t lengthRun = -1; + UBiDiDirection runDir = ubidi_getVisualRun(bidi, i, &startRun, &lengthRun); + if (startRun == -1 || lengthRun == -1) { + ALOGE("invalid visual run"); + // Note: this case will lose text; can it ever actually happen? + break; + } + isRtl = (runDir == UBIDI_RTL); + // TODO: min/max with context + doLayoutRun(buf, startRun, lengthRun, nchars, isRtl, style, paint); + } + } + } else { + ALOGE("error calling ubidi_setPara, status = %d", status); + } + ubidi_close(bidi); + } else { + ALOGE("error creating bidi object"); + } + } + if (doSingleRun) { + doLayoutRun(buf, 0, nchars, nchars, isRtl, style, paint); + } +} + +void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, FontStyle style, MinikinPaint& paint) { + vector items; + mCollection->itemize(buf + start, count, style, &items); + if (isRtl) { + std::reverse(items.begin(), items.end()); + } + + float x = mAdvance; float y = 0; for (size_t run_ix = 0; run_ix < items.size(); run_ix++) { FontCollection::Run &run = items[run_ix]; @@ -325,6 +394,7 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { std::cout << "Run " << run_ix << ", font " << font_ix << " [" << run.start << ":" << run.end << "]" << std::endl; #endif + double size = paint.size; hb_font_set_ppem(hbFont, size, size); hb_font_set_scale(hbFont, HBFloatToFixed(size), HBFloatToFixed(size)); @@ -334,12 +404,12 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { ssize_t srunend; for (ssize_t srunstart = run.start; srunstart < run.end; srunstart = srunend) { srunend = srunstart; - hb_script_t script = getScriptRun(buf, run.end, &srunend); + hb_script_t script = getScriptRun(buf + start, run.end, &srunend); hb_buffer_reset(buffer); hb_buffer_set_script(buffer, script); hb_buffer_set_direction(buffer, isRtl? HB_DIRECTION_RTL : HB_DIRECTION_LTR); - hb_buffer_add_utf16(buffer, buf, nchars, srunstart, srunend - srunstart); + hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart); hb_shape(hbFont, buffer, NULL, 0); unsigned int numGlyphs; hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, &numGlyphs); From 8893e8692be3b069f1d9b40970979060b31ecfc4 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 19 May 2014 13:21:21 -0700 Subject: [PATCH 016/364] Fix incomplete refcounting and locking These changes were supposed to be committed in the previous patch "Better refcounting and locking" but seem to have gotten lost in a rebase. It fixes a memory leak and some possible race conditions. Change-Id: I54ca1e37500ec49756fe317cc6d6d03da9911501 --- engine/src/flutter/include/minikin/FontFamily.h | 2 ++ engine/src/flutter/include/minikin/Layout.h | 6 ++++++ engine/src/flutter/libs/minikin/FontCollection.cpp | 2 ++ engine/src/flutter/libs/minikin/FontFamily.cpp | 11 +++++++++-- engine/src/flutter/libs/minikin/Layout.cpp | 7 +++++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 3b59017631a..82fcfe9af87 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -56,6 +56,8 @@ public: MinikinFont* getFont(size_t index) const; FontStyle getStyle(size_t index) const; private: + void addFontLocked(MinikinFont* typeface, FontStyle style); + class Font { public: Font(MinikinFont* typeface, FontStyle style) : diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 896478b219a..4fe9d8772fa 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -55,8 +55,14 @@ struct LayoutGlyph { float y; }; +// Lifecycle and threading assumptions for Layout: +// The object is assumed to be owned by a single thread; multiple threads +// may not mutate it at the same time. +// The lifetime of the FontCollection set through setFontCollection must +// extend through the lifetime of the Layout object. class Layout { public: + ~Layout(); void dump() const; void setFontCollection(const FontCollection* collection); diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 18e528efb05..cd7b19e0096 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -19,6 +19,7 @@ #define LOG_TAG "Minikin" #include +#include "MinikinInternal.h" #include #include @@ -33,6 +34,7 @@ static inline T max(T a, T b) { FontCollection::FontCollection(const vector& typefaces) : mMaxChar(0) { + AutoMutex _l(gMinikinLock); vector lastChar; size_t nTypefaces = typefaces.size(); #ifdef VERBOSE_DEBUG diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index d8525ffa6de..d818f77eec2 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -19,6 +19,8 @@ #include #include #include + +#include "MinikinInternal.h" #include #include #include @@ -35,6 +37,7 @@ FontFamily::~FontFamily() { } bool FontFamily::addFont(MinikinFont* typeface) { + AutoMutex _l(gMinikinLock); const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2'); size_t os2Size = 0; bool ok = typeface->GetTable(os2Tag, NULL, &os2Size); @@ -47,7 +50,7 @@ bool FontFamily::addFont(MinikinFont* typeface) { if (analyzeStyle(os2Data.get(), os2Size, &weight, &italic)) { //ALOGD("analyzed weight = %d, italic = %s", weight, italic ? "true" : "false"); FontStyle style(weight, italic); - addFont(typeface, style); + addFontLocked(typeface, style); return true; } else { ALOGD("failed to analyze style"); @@ -56,7 +59,11 @@ bool FontFamily::addFont(MinikinFont* typeface) { } void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { - typeface->RefLocked(); + AutoMutex _l(gMinikinLock); + addFontLocked(typeface, style); +} + +void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { typeface->RefLocked(); mFonts.push_back(Font(typeface, style)); } diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 3a0be6abefc..f32e9f4e4f9 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -161,6 +161,7 @@ hb_font_funcs_t* getHbFontFuncs() { hb_font_t* create_hb_font(MinikinFont* minikinFont, MinikinPaint* minikinPaint) { hb_face_t* face = hb_face_create_for_tables(referenceTable, minikinFont, NULL); hb_font_t* font = hb_font_create(face); + hb_face_destroy(face); hb_font_set_funcs(font, getHbFontFuncs(), minikinPaint, 0); // TODO: manage ownership of face return font; @@ -176,6 +177,12 @@ static hb_position_t HBFloatToFixed(float v) return scalbnf (v, +8); } +Layout::~Layout() { + for (size_t ix = 0; ix < mHbFonts.size(); ix++) { + hb_font_destroy(mHbFonts[ix]); + } +} + void Layout::dump() const { for (size_t i = 0; i < mGlyphs.size(); i++) { const LayoutGlyph& glyph = mGlyphs[i]; From 6bbcf44f6805bc5f913be9f4f7e04be020f685f3 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 21 May 2014 08:37:49 -0700 Subject: [PATCH 017/364] Caching for layouts and harfbuzz faces This patch adds caching for both layouts and for HarfBuzz face objects. The granularity of the cache for layouts is words, so it splits the input string at word boundaries (using a heuristic). There are is also some refactoring to reduce the amount of allocation and copying, and movement towards properly supporting contexts. The size of the caches is a fixed number of entries; thus, it is possible to consume a large amount of memory by filling the cache with lots of large strings. This should be refined towards a scheme that bounds the total memory used by the cache. Change-Id: Ie8176857e2d78656ce5479a7c04969819ef2718d --- .../flutter/include/minikin/FontCollection.h | 11 +- .../src/flutter/include/minikin/FontFamily.h | 14 +- engine/src/flutter/include/minikin/Layout.h | 41 +- .../src/flutter/include/minikin/MinikinFont.h | 1 + engine/src/flutter/libs/minikin/Android.mk | 3 +- .../flutter/libs/minikin/FontCollection.cpp | 13 + engine/src/flutter/libs/minikin/Layout.cpp | 388 +++++++++++++++--- engine/src/flutter/sample/example.cpp | 2 +- 8 files changed, 390 insertions(+), 83 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index dc48f8e0a24..c6c2ed05b0e 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -54,9 +54,12 @@ public: int start; int end; }; + void itemize(const uint16_t *string, size_t string_length, FontStyle style, std::vector* result) const; - private: + + uint32_t getId() const; +private: static const int kLogCharsPerPage = 8; static const int kPageMask = (1 << kLogCharsPerPage) - 1; @@ -70,6 +73,12 @@ public: size_t end; }; + // static for allocating unique id's + static uint32_t sNextId; + + // unique id for this font collection (suitable for cache key) + uint32_t mId; + // Highest UTF-32 code point that can be mapped uint32_t mMaxChar; diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 82fcfe9af87..a4fe9cb9e40 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -19,6 +19,8 @@ #include +#include + #include namespace android { @@ -31,16 +33,22 @@ public: FontStyle(int weight = 4, bool italic = false) { bits = (weight & kWeightMask) | (italic ? kItalicMask : 0); } - int getWeight() { return bits & kWeightMask; } - bool getItalic() { return (bits & kItalicMask) != 0; } - bool operator==(const FontStyle other) { return bits == other.bits; } + int getWeight() const { return bits & kWeightMask; } + bool getItalic() const { return (bits & kItalicMask) != 0; } + bool operator==(const FontStyle other) const { return bits == other.bits; } // TODO: language, variant + + hash_t hash() const { return bits; } private: static const int kWeightMask = 0xf; static const int kItalicMask = 16; uint32_t bits; }; +inline hash_t hash_type(const FontStyle &style) { + return style.hash(); +} + class FontFamily : public MinikinRefCounted { public: ~FontFamily(); diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 6c338db280e..a1ef0c13b8f 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -55,6 +55,9 @@ struct LayoutGlyph { float y; }; +// Internal state used during layout operation +class LayoutContext; + // Lifecycle and threading assumptions for Layout: // The object is assumed to be owned by a single thread; multiple threads // may not mutate it at the same time. @@ -62,13 +65,19 @@ struct LayoutGlyph { // extend through the lifetime of the Layout object. class Layout { public: - ~Layout(); - void dump() const; void setFontCollection(const FontCollection* collection); + + // deprecated - missing functionality void doLayout(const uint16_t* buf, size_t nchars); - void draw(Bitmap*, int x0, int y0) const; - void setProperties(const std::string css); + + void doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + const std::string& css); + + void draw(Bitmap*, int x0, int y0, float size) const; + + // deprecated - pass as argument to doLayout instead + void setProperties(const std::string& css); // This must be called before any invocations. // TODO: probably have a factory instead @@ -92,23 +101,31 @@ public: private: // Find a face in the mFaces vector, or create a new entry - int findFace(MinikinFont* face, MinikinPaint* paint); + int findFace(MinikinFont* face, LayoutContext* ctx); + + // Lay out a single bidi run + void doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, LayoutContext* ctx); + + // Lay out a single word + void doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, LayoutContext* ctx, size_t bufStart); // Lay out a single bidi run void doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - bool isRtl, FontStyle style, MinikinPaint& paint); + bool isRtl, LayoutContext* ctx); + + // Append another layout (for example, cached value) into this one + void appendLayout(Layout* src, size_t start); + + // deprecated - remove when setProperties is removed + std::string mCssString; - CssProperties mProps; // TODO: want spans std::vector mGlyphs; std::vector mAdvances; - // In future, this will be some kind of mapping from the - // identifier used to represent font-family to a font collection. - // But for the time being, it should be ok to have just one - // per layout. const FontCollection* mCollection; std::vector mFaces; - std::vector mHbFonts; float mAdvance; MinikinRect mBounds; }; diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 568f19da7fe..dbb89f83312 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -27,6 +27,7 @@ namespace android { class MinikinFont; // Possibly move into own .h file? +// Note: if you add a field here, also update LayoutCacheKey struct MinikinPaint { MinikinFont *font; float size; diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index f1f035497af..a1d88c29e55 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -44,6 +44,7 @@ LOCAL_SHARED_LIBRARIES := \ libpng \ libz \ libstlport \ - libicuuc + libicuuc \ + libutils include $(BUILD_SHARED_LIBRARY) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index cd7b19e0096..67089dbe8be 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -32,9 +32,12 @@ static inline T max(T a, T b) { return a>b ? a : b; } +uint32_t FontCollection::sNextId = 0; + FontCollection::FontCollection(const vector& typefaces) : mMaxChar(0) { AutoMutex _l(gMinikinLock); + mId = sNextId++; vector lastChar; size_t nTypefaces = typefaces.size(); #ifdef VERBOSE_DEBUG @@ -50,6 +53,12 @@ FontCollection::FontCollection(const vector& typefaces) : instance->mFamily = family; instance->mCoverage = new SparseBitSet; MinikinFont* typeface = family->getClosestMatch(defaultStyle); + if (typeface == NULL) { + ALOGE("FontCollection: closest match was null"); + // TODO: we shouldn't hit this, as there should be more robust + // checks upstream to prevent empty/invalid FontFamily objects + continue; + } #ifdef VERBOSE_DEBUG ALOGD("closest match = %p, family size = %d\n", typeface, family->getNumFonts()); #endif @@ -149,4 +158,8 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } } +uint32_t FontCollection::getId() const { + return mId; +} + } // namespace android diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 918bc2e87d8..886b7d1f1c4 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -24,6 +24,11 @@ #include // for debugging #include // ditto +#include +#include +#include +#include + #include #include @@ -36,9 +41,6 @@ using std::vector; namespace android { -// TODO: globals are not cool, move to a factory-ish object -hb_buffer_t* buffer = 0; - // TODO: these should move into the header file, but for now we don't want // to cause namespace collisions with TextLayout.h enum { @@ -54,6 +56,114 @@ enum { const int kDirection_Mask = 0x1; +// Layout cache datatypes + +class LayoutCacheKey { +public: + LayoutCacheKey(const FontCollection* collection, const MinikinPaint& paint, FontStyle style, + const uint16_t* chars, size_t start, size_t count, size_t nchars, bool dir) + : mStart(start), mCount(count), mId(collection->getId()), mStyle(style), + mSize(paint.size), mIsRtl(dir) { + mText.setTo(chars, nchars); + } + bool operator==(const LayoutCacheKey &other) const; + hash_t hash() const; + + // This is present to avoid having to copy the text more than once. + const uint16_t* textBuf() { return mText.string(); } +private: + String16 mText; + size_t mStart; + size_t mCount; + uint32_t mId; // for the font collection + FontStyle mStyle; + float mSize; + bool mIsRtl; + // Note: any fields added to MinikinPaint must also be reflected here. + // TODO: language matching (possibly integrate into style) +}; + +class LayoutCache : private OnEntryRemoved { +public: + LayoutCache() : mCache(kMaxEntries) { + mCache.setOnEntryRemovedListener(this); + } + + // callback for OnEntryRemoved + void operator()(LayoutCacheKey& key, Layout*& value) { + delete value; + } + + LruCache mCache; +private: + //static const size_t kMaxEntries = LruCache::kUnlimitedCapacity; + + // TODO: eviction based on memory footprint; for now, we just use a constant + // number of strings + static const size_t kMaxEntries = 5000; +}; + +class HbFaceCache : private OnEntryRemoved { +public: + HbFaceCache() : mCache(kMaxEntries) { + mCache.setOnEntryRemovedListener(this); + } + + // callback for OnEntryRemoved + void operator()(int32_t& key, hb_face_t*& value) { + hb_face_destroy(value); + } + + LruCache mCache; +private: + static const size_t kMaxEntries = 100; +}; + +class LayoutEngine : public Singleton { +public: + LayoutEngine() { + hbBuffer = hb_buffer_create(); + } + + hb_buffer_t* hbBuffer; + LayoutCache layoutCache; + HbFaceCache hbFaceCache; +}; + +ANDROID_SINGLETON_STATIC_INSTANCE(LayoutEngine); + +bool LayoutCacheKey::operator==(const LayoutCacheKey& other) const { + return mId == other.mId && + mStart == other.mStart && + mCount == other.mCount && + mStyle == other.mStyle && + mSize == other.mSize && + mIsRtl == other.mIsRtl && + mText == other.mText; +} + +hash_t LayoutCacheKey::hash() const { + uint32_t hash = JenkinsHashMix(0, mId); + hash = JenkinsHashMix(hash, mStart); + hash = JenkinsHashMix(hash, mCount); + hash = JenkinsHashMix(hash, hash_type(mStyle)); + hash = JenkinsHashMix(hash, hash_type(mSize)); + hash = JenkinsHashMix(hash, hash_type(mIsRtl)); + hash = JenkinsHashMixShorts(hash, mText.string(), mText.size()); + return JenkinsHashWhiten(hash); +} + +struct LayoutContext { + MinikinPaint paint; + FontStyle style; + CssProperties props; + std::vector hbFonts; // parallel to mFaces +}; + +hash_t hash_type(const LayoutCacheKey& key) { + return key.hash(); +} + Bitmap::Bitmap(int width, int height) : width(width), height(height) { buf = new uint8_t[width * height](); } @@ -107,18 +217,18 @@ void MinikinRect::join(const MinikinRect& r) { void Layout::init() { } -void Layout::setFontCollection(const FontCollection *collection) { +void Layout::setFontCollection(const FontCollection* collection) { mCollection = collection; } hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { - MinikinFont* font = reinterpret_cast(userData); + MinikinFont* font = reinterpret_cast(userData); size_t length = 0; bool ok = font->GetTable(tag, NULL, &length); if (!ok) { return 0; } - char *buffer = reinterpret_cast(malloc(length)); + char* buffer = reinterpret_cast(malloc(length)); if (!buffer) { return 0; } @@ -135,7 +245,7 @@ hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { static hb_bool_t harfbuzzGetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoint_t unicode, hb_codepoint_t variationSelector, hb_codepoint_t* glyph, void* userData) { - MinikinPaint* paint = reinterpret_cast(fontData); + MinikinPaint* paint = reinterpret_cast(fontData); MinikinFont* font = paint->font; uint32_t glyph_id; bool ok = font->GetGlyph(unicode, &glyph_id); @@ -147,7 +257,7 @@ static hb_bool_t harfbuzzGetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoin static hb_position_t harfbuzzGetGlyphHorizontalAdvance(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, void* userData) { - MinikinPaint* paint = reinterpret_cast(fontData); + MinikinPaint* paint = reinterpret_cast(fontData); MinikinFont* font = paint->font; float advance = font->GetHorizontalAdvance(glyph, *paint); return 256 * advance + 0.5; @@ -173,12 +283,21 @@ hb_font_funcs_t* getHbFontFuncs() { return hbFontFuncs; } -hb_font_t* create_hb_font(MinikinFont* minikinFont, MinikinPaint* minikinPaint) { - hb_face_t* face = hb_face_create_for_tables(referenceTable, minikinFont, NULL); +static hb_face_t* getHbFace(MinikinFont* minikinFont) { + HbFaceCache& cache = LayoutEngine::getInstance().hbFaceCache; + int32_t fontId = minikinFont->GetUniqueId(); + hb_face_t* face = cache.mCache.get(fontId); + if (face == NULL) { + face = hb_face_create_for_tables(referenceTable, minikinFont, NULL); + cache.mCache.put(fontId, face); + } + return face; +} + +static hb_font_t* create_hb_font(MinikinFont* minikinFont, MinikinPaint* minikinPaint) { + hb_face_t* face = getHbFace(minikinFont); hb_font_t* font = hb_font_create(face); - hb_face_destroy(face); hb_font_set_funcs(font, getHbFontFuncs(), minikinPaint, 0); - // TODO: manage ownership of face return font; } @@ -192,12 +311,6 @@ static hb_position_t HBFloatToFixed(float v) return scalbnf (v, +8); } -Layout::~Layout() { - for (size_t ix = 0; ix < mHbFonts.size(); ix++) { - hb_font_destroy(mHbFonts[ix]); - } -} - void Layout::dump() const { for (size_t i = 0; i < mGlyphs.size(); i++) { const LayoutGlyph& glyph = mGlyphs[i]; @@ -205,11 +318,7 @@ void Layout::dump() const { } } -// A couple of things probably need to change: -// 1. Deal with multiple sizes in a layout -// 2. We'll probably store FT_Face as primary and then use a cache -// for the hb fonts -int Layout::findFace(MinikinFont* face, MinikinPaint* paint) { +int Layout::findFace(MinikinFont* face, LayoutContext* ctx) { unsigned int ix; for (ix = 0; ix < mFaces.size(); ix++) { if (mFaces[ix] == face) { @@ -217,8 +326,12 @@ int Layout::findFace(MinikinFont* face, MinikinPaint* paint) { } } mFaces.push_back(face); - hb_font_t *font = create_hb_font(face, paint); - mHbFonts.push_back(font); + // Note: ctx == NULL means we're copying from the cache, no need to create + // corresponding hb_font object. + if (ctx != NULL) { + hb_font_t* font = create_hb_font(face, &ctx->paint); + ctx->hbFonts.push_back(font); + } return ix; } @@ -235,14 +348,14 @@ static FontStyle styleFromCss(const CssProperties &props) { } static hb_script_t codePointToScript(hb_codepoint_t codepoint) { - static hb_unicode_funcs_t *u = 0; + static hb_unicode_funcs_t* u = 0; if (!u) { u = hb_icu_get_unicode_funcs(); } return hb_unicode_script(u, codepoint); } -static hb_codepoint_t decodeUtf16(const uint16_t *chars, size_t len, ssize_t *iter) { +static hb_codepoint_t decodeUtf16(const uint16_t* chars, size_t len, ssize_t* iter) { const uint16_t v = chars[(*iter)++]; // test whether v in (0xd800..0xdfff), lead or trail surrogate if ((v & 0xf800) == 0xd800) { @@ -266,7 +379,7 @@ static hb_codepoint_t decodeUtf16(const uint16_t *chars, size_t len, ssize_t *it } } -static hb_script_t getScriptRun(const uint16_t *chars, size_t len, ssize_t *iter) { +static hb_script_t getScriptRun(const uint16_t* chars, size_t len, ssize_t* iter) { if (size_t(*iter) == len) { return HB_SCRIPT_UNKNOWN; } @@ -298,29 +411,99 @@ static hb_script_t getScriptRun(const uint16_t *chars, size_t len, ssize_t *iter return current_script; } -// TODO: API should probably take context -void Layout::doLayout(const uint16_t* buf, size_t nchars) { - AutoMutex _l(gMinikinLock); - if (buffer == 0) { - buffer = hb_buffer_create(); +/** + * For the purpose of layout, a word break is a boundary with no + * kerning or complex script processing. This is necessarily a + * heuristic, but should be accurate most of the time. + */ +static bool isWordBreak(int c) { + if (c == ' ' || (c >= 0x2000 && c <= 0x200a) || c == 0x3000) { + // spaces + return true; } - FT_Error error; + if ((c >= 0x3400 && c <= 0x9fff)) { + // CJK ideographs (and yijing hexagram symbols) + return true; + } + // Note: kana is not included, as sophisticated fonts may kern kana + return false; +} - FontStyle style = styleFromCss(mProps); +/** + * Return offset of previous word break. It is either < offset or == 0. + */ +static size_t getPrevWordBreak(const uint16_t* chars, size_t offset) { + if (offset == 0) return 0; + if (isWordBreak(chars[offset - 1])) { + return offset - 1; + } + for (size_t i = offset - 1; i > 0; i--) { + if (isWordBreak(chars[i - 1])) { + return i; + } + } + return 0; +} - MinikinPaint paint; - double size = mProps.value(fontSize).getFloatValue(); - paint.size = size; - int bidiFlags = mProps.hasTag(minikinBidi) ? mProps.value(minikinBidi).getIntValue() : 0; +/** + * Return offset of next word break. It is either > offset or == len. + */ +static size_t getNextWordBreak(const uint16_t* chars, size_t offset, size_t len) { + if (offset >= len) return len; + if (isWordBreak(chars[offset])) { + return offset + 1; + } + for (size_t i = offset + 1; i < len; i++) { + if (isWordBreak(chars[i])) { + return i; + } + } + return len; +} + +// deprecated API, to avoid breaking client +void Layout::doLayout(const uint16_t* buf, size_t nchars) { + doLayout(buf, 0, nchars, nchars, mCssString); +} + +// TODO: use some standard implementation +template +static T mymin(const T& a, const T& b) { + return a < b ? a : b; +} + +template +static T mymax(const T& a, const T& b) { + return a > b ? a : b; +} + +static void clearHbFonts(LayoutContext* ctx) { + for (size_t i = 0; i < ctx->hbFonts.size(); i++) { + hb_font_destroy(ctx->hbFonts[i]); + } + ctx->hbFonts.clear(); +} + +// TODO: API should probably take context +void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + const std::string& css) { + AutoMutex _l(gMinikinLock); + LayoutContext ctx; + + ctx.props.parse(css); + ctx.style = styleFromCss(ctx.props); + + double size = ctx.props.value(fontSize).getFloatValue(); + ctx.paint.size = size; + int bidiFlags = ctx.props.hasTag(minikinBidi) ? ctx.props.value(minikinBidi).getIntValue() : 0; bool isRtl = (bidiFlags & kDirection_Mask) != 0; bool doSingleRun = true; mGlyphs.clear(); mFaces.clear(); - mHbFonts.clear(); mBounds.setEmpty(); mAdvances.clear(); - mAdvances.resize(nchars, 0); + mAdvances.resize(count, 0); mAdvance = 0; if (!(bidiFlags == kBidi_Force_LTR || bidiFlags == kBidi_Force_RTL)) { UBiDi* bidi = ubidi_open(); @@ -332,12 +515,12 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { } else if (bidiFlags == kBidi_Default_RTL) { bidiReq = UBIDI_DEFAULT_RTL; } - ubidi_setPara(bidi, buf, nchars, bidiReq, NULL, &status); + ubidi_setPara(bidi, buf, bufSize, bidiReq, NULL, &status); if (U_SUCCESS(status)) { int paraDir = ubidi_getParaLevel(bidi) & kDirection_Mask; ssize_t rc = ubidi_countRuns(bidi, &status); - if (!U_SUCCESS(status) || rc < 1) { - ALOGD("error counting bidi runs, status = %d", status); + if (!U_SUCCESS(status) || rc < 0) { + ALOGW("error counting bidi runs, status = %d", status); } if (!U_SUCCESS(status) || rc <= 1) { isRtl = (paraDir == kBidi_RTL); @@ -350,12 +533,12 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { UBiDiDirection runDir = ubidi_getVisualRun(bidi, i, &startRun, &lengthRun); if (startRun == -1 || lengthRun == -1) { ALOGE("invalid visual run"); - // Note: this case will lose text; can it ever actually happen? - break; + // skip the invalid run + continue; } isRtl = (runDir == UBIDI_RTL); // TODO: min/max with context - doLayoutRun(buf, startRun, lengthRun, nchars, isRtl, style, paint); + doLayoutRunCached(buf, startRun, lengthRun, bufSize, isRtl, &ctx); } } } else { @@ -367,14 +550,63 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { } } if (doSingleRun) { - doLayoutRun(buf, 0, nchars, nchars, isRtl, style, paint); + doLayoutRunCached(buf, start, count, bufSize, isRtl, &ctx); + } + clearHbFonts(&ctx); +} + +void Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, LayoutContext* ctx) { + if (!isRtl) { + // left to right + size_t wordstart = start == bufSize ? start : getPrevWordBreak(buf, start + 1); + size_t wordend; + for (size_t iter = start; iter < start + count; iter = wordend) { + wordend = getNextWordBreak(buf, iter, bufSize); + size_t wordcount = mymin(start + count, wordend) - iter; + doLayoutWord(buf + wordstart, iter - wordstart, wordcount, wordend - wordstart, + isRtl, ctx, iter); + wordstart = wordend; + } + } else { + // right to left + size_t wordstart; + size_t end = start + count; + size_t wordend = end == 0 ? 0 : getNextWordBreak(buf, end - 1, bufSize); + for (size_t iter = end; iter > start; iter = wordstart) { + wordstart = getPrevWordBreak(buf, iter); + size_t bufStart = mymax(start, wordstart); + doLayoutWord(buf + wordstart, bufStart - wordstart, iter - bufStart, + wordend - wordstart, isRtl, ctx, bufStart); + wordend = wordstart; + } } } +void Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, LayoutContext* ctx, size_t bufStart) { + LayoutCache& cache = LayoutEngine::getInstance().layoutCache; + LayoutCacheKey key(mCollection, ctx->paint, ctx->style, buf, start, count, bufSize, isRtl); + Layout* value = cache.mCache.get(key); + if (value == NULL) { + value = new Layout(); + value->setFontCollection(mCollection); + value->mAdvances.resize(count, 0); + clearHbFonts(ctx); + // Note: we do the layout from the copy stored in the key, in case a + // badly-behaved client is mutating the buffer in a separate thread. + value->doLayoutRun(key.textBuf(), start, count, bufSize, isRtl, ctx); + } + appendLayout(value, bufStart); + cache.mCache.put(key, value); + +} + void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - bool isRtl, FontStyle style, MinikinPaint& paint) { + bool isRtl, LayoutContext* ctx) { + hb_buffer_t* buffer = LayoutEngine::getInstance().hbBuffer; vector items; - mCollection->itemize(buf + start, count, style, &items); + mCollection->itemize(buf + start, count, ctx->style, &items); if (isRtl) { std::reverse(items.begin(), items.end()); } @@ -383,10 +615,10 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t float y = 0; for (size_t run_ix = 0; run_ix < items.size(); run_ix++) { FontCollection::Run &run = items[run_ix]; - int font_ix = findFace(run.font, &paint); - paint.font = mFaces[font_ix]; - hb_font_t *hbFont = mHbFonts[font_ix]; - if (paint.font == NULL) { + int font_ix = findFace(run.font, ctx); + ctx->paint.font = mFaces[font_ix]; + hb_font_t* hbFont = ctx->hbFonts[font_ix]; + if (ctx->paint.font == NULL) { // TODO: should log what went wrong continue; } @@ -394,7 +626,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t std::cout << "Run " << run_ix << ", font " << font_ix << " [" << run.start << ":" << run.end << "]" << std::endl; #endif - double size = paint.size; + double size = ctx->paint.size; hb_font_set_ppem(hbFont, size, size); hb_font_set_scale(hbFont, HBFloatToFixed(size), HBFloatToFixed(size)); @@ -412,8 +644,8 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart); hb_shape(hbFont, buffer, NULL, 0); unsigned int numGlyphs; - hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, &numGlyphs); - hb_glyph_position_t *positions = hb_buffer_get_glyph_positions(buffer, NULL); + hb_glyph_info_t* info = hb_buffer_get_glyph_infos(buffer, &numGlyphs); + hb_glyph_position_t* positions = hb_buffer_get_glyph_positions(buffer, NULL); for (unsigned int i = 0; i < numGlyphs; i++) { #ifdef VERBOSE std::cout << positions[i].x_advance << " " << positions[i].y_advance << " " << positions[i].x_offset << " " << positions[i].y_offset << std::endl; std::cout << "DoLayout " << info[i].codepoint << @@ -426,7 +658,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t mGlyphs.push_back(glyph); float xAdvance = HBFixedToFloat(positions[i].x_advance); MinikinRect glyphBounds; - paint.font->GetBounds(&glyphBounds, glyph_ix, paint); + ctx->paint.font->GetBounds(&glyphBounds, glyph_ix, ctx->paint); glyphBounds.offset(x + xoff, y + yoff); mBounds.join(glyphBounds); size_t cluster = info[i].cluster; @@ -438,7 +670,33 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t mAdvance = x; } -void Layout::draw(Bitmap* surface, int x0, int y0) const { +void Layout::appendLayout(Layout* src, size_t start) { + // Note: size==1 is by far most common, should have specialized vector for this + std::vector fontMap; + for (size_t i = 0; i < src->mFaces.size(); i++) { + int font_ix = findFace(src->mFaces[i], NULL); + fontMap.push_back(font_ix); + } + int x0 = mAdvance; + for (size_t i = 0; i < src->mGlyphs.size(); i++) { + LayoutGlyph& srcGlyph = src->mGlyphs[i]; + int font_ix = fontMap[srcGlyph.font_ix]; + unsigned int glyph_id = srcGlyph.glyph_id; + float x = x0 + srcGlyph.x; + float y = srcGlyph.y; + LayoutGlyph glyph = {font_ix, glyph_id, x, y}; + mGlyphs.push_back(glyph); + } + for (size_t i = 0; i < src->mAdvances.size(); i++) { + mAdvances[i + start] = src->mAdvances[i]; + } + MinikinRect srcBounds(src->mBounds); + srcBounds.offset(x0, 0); + mBounds.join(srcBounds); + mAdvance += src->mAdvance; +} + +void Layout::draw(Bitmap* surface, int x0, int y0, float size) const { /* TODO: redo as MinikinPaint settings if (mProps.hasTag(minikinHinting)) { @@ -449,11 +707,11 @@ void Layout::draw(Bitmap* surface, int x0, int y0) const { */ for (size_t i = 0; i < mGlyphs.size(); i++) { const LayoutGlyph& glyph = mGlyphs[i]; - MinikinFont *mf = mFaces[glyph.font_ix]; - MinikinFontFreeType *face = static_cast(mf); + MinikinFont* mf = mFaces[glyph.font_ix]; + MinikinFontFreeType* face = static_cast(mf); GlyphBitmap glyphBitmap; MinikinPaint paint; - paint.size = mProps.value(fontSize).getFloatValue(); + paint.size = size; bool ok = face->Render(glyph.glyph_id, paint, &glyphBitmap); printf("glyphBitmap.width=%d, glyphBitmap.height=%d (%d, %d) x=%f, y=%f, ok=%d\n", glyphBitmap.width, glyphBitmap.height, glyphBitmap.left, glyphBitmap.top, glyph.x, glyph.y, ok); @@ -464,15 +722,15 @@ void Layout::draw(Bitmap* surface, int x0, int y0) const { } } -void Layout::setProperties(string css) { - mProps.parse(css); +void Layout::setProperties(const string& css) { + mCssString = css; } size_t Layout::nGlyphs() const { return mGlyphs.size(); } -MinikinFont *Layout::getFont(int i) const { +MinikinFont* Layout::getFont(int i) const { const LayoutGlyph& glyph = mGlyphs[i]; return mFaces[glyph.font_ix]; } diff --git a/engine/src/flutter/sample/example.cpp b/engine/src/flutter/sample/example.cpp index 9b012ef0866..b8bd66f4be5 100644 --- a/engine/src/flutter/sample/example.cpp +++ b/engine/src/flutter/sample/example.cpp @@ -89,7 +89,7 @@ int runMinikinTest() { layout.doLayout(icuText.getBuffer(), icuText.length()); layout.dump(); Bitmap bitmap(250, 50); - layout.draw(&bitmap, 10, 40); + layout.draw(&bitmap, 10, 40, 32); std::ofstream o; o.open("/data/local/tmp/foo.pgm", std::ios::out | std::ios::binary); bitmap.writePnm(o); From b1f16e880b39439054918774f8e53da2d4d0a133 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 23 May 2014 22:44:35 -0700 Subject: [PATCH 018/364] Fix native crash in Latin-1 typefaces This is a fix for bug 15171911 Timely crashes (native crash in libminikin) when I go to add a new alarm This patch fixes an off-by-one error that caused typefaces with only one page of Unicode coverage (ASCII or Latin-1) to have nPages = 0 instead of the correct value of 1 in the corresponding FontCollection. Change-Id: Id8be0c9e5713b8af22d863992921ee6382416a34 --- engine/src/flutter/libs/minikin/FontCollection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index cd7b19e0096..8919dc1a5e7 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -66,7 +66,7 @@ FontCollection::FontCollection(const vector& typefaces) : mMaxChar = max(mMaxChar, instance->mCoverage->length()); lastChar.push_back(instance->mCoverage->nextSetBit(0)); } - size_t nPages = mMaxChar >> kLogCharsPerPage; + size_t nPages = (mMaxChar + kPageMask) >> kLogCharsPerPage; size_t offset = 0; for (size_t i = 0; i < nPages; i++) { Range dummy; From 5261296f2aa237df758c0491ec3acc373132b83b Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 19 May 2014 11:58:20 -0700 Subject: [PATCH 019/364] Do BiDi algorithm for text layout This is a fix for bug 15130102 "Language name for Hebrew displayed the wrong way around on keyboard". This patch extends the previous BiDi support (when the direction for the entire string was given by the caller) to run the BiDi algorithm (provided by ICU) over the string to break it into BiDi runs. Thus, it handles mixed LTR and RTL strings in a single layout, and also respects heuristics for inferring the paragraph direction from the string. Change-Id: Ia4b869de3c139c5a7d16b8ce7766870b98a815ea (cherry picked from commit 4b3a941128454e55893d65433a835e78a9e9781d) --- engine/src/flutter/include/minikin/Layout.h | 4 + engine/src/flutter/libs/minikin/Android.mk | 3 +- engine/src/flutter/libs/minikin/Layout.cpp | 88 ++++++++++++++++++--- 3 files changed, 85 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 4fe9d8772fa..6c338db280e 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -94,6 +94,10 @@ private: // Find a face in the mFaces vector, or create a new entry int findFace(MinikinFont* face, MinikinPaint* paint); + // Lay out a single bidi run + void doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, FontStyle style, MinikinPaint& paint); + CssProperties mProps; // TODO: want spans std::vector mGlyphs; std::vector mAdvances; diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index c4412859c41..f1f035497af 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -43,6 +43,7 @@ LOCAL_SHARED_LIBRARIES := \ liblog \ libpng \ libz \ - libstlport + libstlport \ + libicuuc include $(BUILD_SHARED_LIBRARY) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index f32e9f4e4f9..918bc2e87d8 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -39,6 +39,21 @@ namespace android { // TODO: globals are not cool, move to a factory-ish object hb_buffer_t* buffer = 0; +// TODO: these should move into the header file, but for now we don't want +// to cause namespace collisions with TextLayout.h +enum { + kBidi_LTR = 0, + kBidi_RTL = 1, + kBidi_Default_LTR = 2, + kBidi_Default_RTL = 3, + kBidi_Force_LTR = 4, + kBidi_Force_RTL = 5, + + kBidi_Mask = 0x7 +}; + +const int kDirection_Mask = 0x1; + Bitmap::Bitmap(int width, int height) : width(width), height(height) { buf = new uint8_t[width * height](); } @@ -291,18 +306,14 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { } FT_Error error; - vector items; FontStyle style = styleFromCss(mProps); - mCollection->itemize(buf, nchars, style, &items); MinikinPaint paint; double size = mProps.value(fontSize).getFloatValue(); paint.size = size; int bidiFlags = mProps.hasTag(minikinBidi) ? mProps.value(minikinBidi).getIntValue() : 0; - bool isRtl = (bidiFlags & 1) != 0; // TODO: do real bidi algo - if (isRtl) { - std::reverse(items.begin(), items.end()); - } + bool isRtl = (bidiFlags & kDirection_Mask) != 0; + bool doSingleRun = true; mGlyphs.clear(); mFaces.clear(); @@ -310,7 +321,65 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { mBounds.setEmpty(); mAdvances.clear(); mAdvances.resize(nchars, 0); - float x = 0; + mAdvance = 0; + if (!(bidiFlags == kBidi_Force_LTR || bidiFlags == kBidi_Force_RTL)) { + UBiDi* bidi = ubidi_open(); + if (bidi) { + UErrorCode status = U_ZERO_ERROR; + UBiDiLevel bidiReq = bidiFlags; + if (bidiFlags == kBidi_Default_LTR) { + bidiReq = UBIDI_DEFAULT_LTR; + } else if (bidiFlags == kBidi_Default_RTL) { + bidiReq = UBIDI_DEFAULT_RTL; + } + ubidi_setPara(bidi, buf, nchars, bidiReq, NULL, &status); + if (U_SUCCESS(status)) { + int paraDir = ubidi_getParaLevel(bidi) & kDirection_Mask; + ssize_t rc = ubidi_countRuns(bidi, &status); + if (!U_SUCCESS(status) || rc < 1) { + ALOGD("error counting bidi runs, status = %d", status); + } + if (!U_SUCCESS(status) || rc <= 1) { + isRtl = (paraDir == kBidi_RTL); + } else { + doSingleRun = false; + // iterate through runs + for (ssize_t i = 0; i < (ssize_t)rc; i++) { + int32_t startRun = -1; + int32_t lengthRun = -1; + UBiDiDirection runDir = ubidi_getVisualRun(bidi, i, &startRun, &lengthRun); + if (startRun == -1 || lengthRun == -1) { + ALOGE("invalid visual run"); + // Note: this case will lose text; can it ever actually happen? + break; + } + isRtl = (runDir == UBIDI_RTL); + // TODO: min/max with context + doLayoutRun(buf, startRun, lengthRun, nchars, isRtl, style, paint); + } + } + } else { + ALOGE("error calling ubidi_setPara, status = %d", status); + } + ubidi_close(bidi); + } else { + ALOGE("error creating bidi object"); + } + } + if (doSingleRun) { + doLayoutRun(buf, 0, nchars, nchars, isRtl, style, paint); + } +} + +void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, FontStyle style, MinikinPaint& paint) { + vector items; + mCollection->itemize(buf + start, count, style, &items); + if (isRtl) { + std::reverse(items.begin(), items.end()); + } + + float x = mAdvance; float y = 0; for (size_t run_ix = 0; run_ix < items.size(); run_ix++) { FontCollection::Run &run = items[run_ix]; @@ -325,6 +394,7 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { std::cout << "Run " << run_ix << ", font " << font_ix << " [" << run.start << ":" << run.end << "]" << std::endl; #endif + double size = paint.size; hb_font_set_ppem(hbFont, size, size); hb_font_set_scale(hbFont, HBFloatToFixed(size), HBFloatToFixed(size)); @@ -334,12 +404,12 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { ssize_t srunend; for (ssize_t srunstart = run.start; srunstart < run.end; srunstart = srunend) { srunend = srunstart; - hb_script_t script = getScriptRun(buf, run.end, &srunend); + hb_script_t script = getScriptRun(buf + start, run.end, &srunend); hb_buffer_reset(buffer); hb_buffer_set_script(buffer, script); hb_buffer_set_direction(buffer, isRtl? HB_DIRECTION_RTL : HB_DIRECTION_LTR); - hb_buffer_add_utf16(buffer, buf, nchars, srunstart, srunend - srunstart); + hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart); hb_shape(hbFont, buffer, NULL, 0); unsigned int numGlyphs; hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, &numGlyphs); From ddfa014d55c11da8e73580b639917f2e2a441add Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 21 May 2014 08:37:49 -0700 Subject: [PATCH 020/364] Caching for layouts and harfbuzz faces This patch adds caching for both layouts and for HarfBuzz face objects. The granularity of the cache for layouts is words, so it splits the input string at word boundaries (using a heuristic). There are is also some refactoring to reduce the amount of allocation and copying, and movement towards properly supporting contexts. The size of the caches is a fixed number of entries; thus, it is possible to consume a large amount of memory by filling the cache with lots of large strings. This should be refined towards a scheme that bounds the total memory used by the cache. This patch fixes bug 15237293 "Regression: Measure performance is significantly slower with minikin". Change-Id: Ie8176857e2d78656ce5479a7c04969819ef2718d --- .../flutter/include/minikin/FontCollection.h | 11 +- .../src/flutter/include/minikin/FontFamily.h | 14 +- engine/src/flutter/include/minikin/Layout.h | 41 +- .../src/flutter/include/minikin/MinikinFont.h | 1 + engine/src/flutter/libs/minikin/Android.mk | 3 +- .../flutter/libs/minikin/FontCollection.cpp | 13 + engine/src/flutter/libs/minikin/Layout.cpp | 388 +++++++++++++++--- engine/src/flutter/sample/example.cpp | 2 +- 8 files changed, 390 insertions(+), 83 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index dc48f8e0a24..c6c2ed05b0e 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -54,9 +54,12 @@ public: int start; int end; }; + void itemize(const uint16_t *string, size_t string_length, FontStyle style, std::vector* result) const; - private: + + uint32_t getId() const; +private: static const int kLogCharsPerPage = 8; static const int kPageMask = (1 << kLogCharsPerPage) - 1; @@ -70,6 +73,12 @@ public: size_t end; }; + // static for allocating unique id's + static uint32_t sNextId; + + // unique id for this font collection (suitable for cache key) + uint32_t mId; + // Highest UTF-32 code point that can be mapped uint32_t mMaxChar; diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 82fcfe9af87..a4fe9cb9e40 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -19,6 +19,8 @@ #include +#include + #include namespace android { @@ -31,16 +33,22 @@ public: FontStyle(int weight = 4, bool italic = false) { bits = (weight & kWeightMask) | (italic ? kItalicMask : 0); } - int getWeight() { return bits & kWeightMask; } - bool getItalic() { return (bits & kItalicMask) != 0; } - bool operator==(const FontStyle other) { return bits == other.bits; } + int getWeight() const { return bits & kWeightMask; } + bool getItalic() const { return (bits & kItalicMask) != 0; } + bool operator==(const FontStyle other) const { return bits == other.bits; } // TODO: language, variant + + hash_t hash() const { return bits; } private: static const int kWeightMask = 0xf; static const int kItalicMask = 16; uint32_t bits; }; +inline hash_t hash_type(const FontStyle &style) { + return style.hash(); +} + class FontFamily : public MinikinRefCounted { public: ~FontFamily(); diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 6c338db280e..a1ef0c13b8f 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -55,6 +55,9 @@ struct LayoutGlyph { float y; }; +// Internal state used during layout operation +class LayoutContext; + // Lifecycle and threading assumptions for Layout: // The object is assumed to be owned by a single thread; multiple threads // may not mutate it at the same time. @@ -62,13 +65,19 @@ struct LayoutGlyph { // extend through the lifetime of the Layout object. class Layout { public: - ~Layout(); - void dump() const; void setFontCollection(const FontCollection* collection); + + // deprecated - missing functionality void doLayout(const uint16_t* buf, size_t nchars); - void draw(Bitmap*, int x0, int y0) const; - void setProperties(const std::string css); + + void doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + const std::string& css); + + void draw(Bitmap*, int x0, int y0, float size) const; + + // deprecated - pass as argument to doLayout instead + void setProperties(const std::string& css); // This must be called before any invocations. // TODO: probably have a factory instead @@ -92,23 +101,31 @@ public: private: // Find a face in the mFaces vector, or create a new entry - int findFace(MinikinFont* face, MinikinPaint* paint); + int findFace(MinikinFont* face, LayoutContext* ctx); + + // Lay out a single bidi run + void doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, LayoutContext* ctx); + + // Lay out a single word + void doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, LayoutContext* ctx, size_t bufStart); // Lay out a single bidi run void doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - bool isRtl, FontStyle style, MinikinPaint& paint); + bool isRtl, LayoutContext* ctx); + + // Append another layout (for example, cached value) into this one + void appendLayout(Layout* src, size_t start); + + // deprecated - remove when setProperties is removed + std::string mCssString; - CssProperties mProps; // TODO: want spans std::vector mGlyphs; std::vector mAdvances; - // In future, this will be some kind of mapping from the - // identifier used to represent font-family to a font collection. - // But for the time being, it should be ok to have just one - // per layout. const FontCollection* mCollection; std::vector mFaces; - std::vector mHbFonts; float mAdvance; MinikinRect mBounds; }; diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 568f19da7fe..dbb89f83312 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -27,6 +27,7 @@ namespace android { class MinikinFont; // Possibly move into own .h file? +// Note: if you add a field here, also update LayoutCacheKey struct MinikinPaint { MinikinFont *font; float size; diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index f1f035497af..a1d88c29e55 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -44,6 +44,7 @@ LOCAL_SHARED_LIBRARIES := \ libpng \ libz \ libstlport \ - libicuuc + libicuuc \ + libutils include $(BUILD_SHARED_LIBRARY) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 8919dc1a5e7..e6ff117ad74 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -32,9 +32,12 @@ static inline T max(T a, T b) { return a>b ? a : b; } +uint32_t FontCollection::sNextId = 0; + FontCollection::FontCollection(const vector& typefaces) : mMaxChar(0) { AutoMutex _l(gMinikinLock); + mId = sNextId++; vector lastChar; size_t nTypefaces = typefaces.size(); #ifdef VERBOSE_DEBUG @@ -50,6 +53,12 @@ FontCollection::FontCollection(const vector& typefaces) : instance->mFamily = family; instance->mCoverage = new SparseBitSet; MinikinFont* typeface = family->getClosestMatch(defaultStyle); + if (typeface == NULL) { + ALOGE("FontCollection: closest match was null"); + // TODO: we shouldn't hit this, as there should be more robust + // checks upstream to prevent empty/invalid FontFamily objects + continue; + } #ifdef VERBOSE_DEBUG ALOGD("closest match = %p, family size = %d\n", typeface, family->getNumFonts()); #endif @@ -149,4 +158,8 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } } +uint32_t FontCollection::getId() const { + return mId; +} + } // namespace android diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 918bc2e87d8..886b7d1f1c4 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -24,6 +24,11 @@ #include // for debugging #include // ditto +#include +#include +#include +#include + #include #include @@ -36,9 +41,6 @@ using std::vector; namespace android { -// TODO: globals are not cool, move to a factory-ish object -hb_buffer_t* buffer = 0; - // TODO: these should move into the header file, but for now we don't want // to cause namespace collisions with TextLayout.h enum { @@ -54,6 +56,114 @@ enum { const int kDirection_Mask = 0x1; +// Layout cache datatypes + +class LayoutCacheKey { +public: + LayoutCacheKey(const FontCollection* collection, const MinikinPaint& paint, FontStyle style, + const uint16_t* chars, size_t start, size_t count, size_t nchars, bool dir) + : mStart(start), mCount(count), mId(collection->getId()), mStyle(style), + mSize(paint.size), mIsRtl(dir) { + mText.setTo(chars, nchars); + } + bool operator==(const LayoutCacheKey &other) const; + hash_t hash() const; + + // This is present to avoid having to copy the text more than once. + const uint16_t* textBuf() { return mText.string(); } +private: + String16 mText; + size_t mStart; + size_t mCount; + uint32_t mId; // for the font collection + FontStyle mStyle; + float mSize; + bool mIsRtl; + // Note: any fields added to MinikinPaint must also be reflected here. + // TODO: language matching (possibly integrate into style) +}; + +class LayoutCache : private OnEntryRemoved { +public: + LayoutCache() : mCache(kMaxEntries) { + mCache.setOnEntryRemovedListener(this); + } + + // callback for OnEntryRemoved + void operator()(LayoutCacheKey& key, Layout*& value) { + delete value; + } + + LruCache mCache; +private: + //static const size_t kMaxEntries = LruCache::kUnlimitedCapacity; + + // TODO: eviction based on memory footprint; for now, we just use a constant + // number of strings + static const size_t kMaxEntries = 5000; +}; + +class HbFaceCache : private OnEntryRemoved { +public: + HbFaceCache() : mCache(kMaxEntries) { + mCache.setOnEntryRemovedListener(this); + } + + // callback for OnEntryRemoved + void operator()(int32_t& key, hb_face_t*& value) { + hb_face_destroy(value); + } + + LruCache mCache; +private: + static const size_t kMaxEntries = 100; +}; + +class LayoutEngine : public Singleton { +public: + LayoutEngine() { + hbBuffer = hb_buffer_create(); + } + + hb_buffer_t* hbBuffer; + LayoutCache layoutCache; + HbFaceCache hbFaceCache; +}; + +ANDROID_SINGLETON_STATIC_INSTANCE(LayoutEngine); + +bool LayoutCacheKey::operator==(const LayoutCacheKey& other) const { + return mId == other.mId && + mStart == other.mStart && + mCount == other.mCount && + mStyle == other.mStyle && + mSize == other.mSize && + mIsRtl == other.mIsRtl && + mText == other.mText; +} + +hash_t LayoutCacheKey::hash() const { + uint32_t hash = JenkinsHashMix(0, mId); + hash = JenkinsHashMix(hash, mStart); + hash = JenkinsHashMix(hash, mCount); + hash = JenkinsHashMix(hash, hash_type(mStyle)); + hash = JenkinsHashMix(hash, hash_type(mSize)); + hash = JenkinsHashMix(hash, hash_type(mIsRtl)); + hash = JenkinsHashMixShorts(hash, mText.string(), mText.size()); + return JenkinsHashWhiten(hash); +} + +struct LayoutContext { + MinikinPaint paint; + FontStyle style; + CssProperties props; + std::vector hbFonts; // parallel to mFaces +}; + +hash_t hash_type(const LayoutCacheKey& key) { + return key.hash(); +} + Bitmap::Bitmap(int width, int height) : width(width), height(height) { buf = new uint8_t[width * height](); } @@ -107,18 +217,18 @@ void MinikinRect::join(const MinikinRect& r) { void Layout::init() { } -void Layout::setFontCollection(const FontCollection *collection) { +void Layout::setFontCollection(const FontCollection* collection) { mCollection = collection; } hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { - MinikinFont* font = reinterpret_cast(userData); + MinikinFont* font = reinterpret_cast(userData); size_t length = 0; bool ok = font->GetTable(tag, NULL, &length); if (!ok) { return 0; } - char *buffer = reinterpret_cast(malloc(length)); + char* buffer = reinterpret_cast(malloc(length)); if (!buffer) { return 0; } @@ -135,7 +245,7 @@ hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { static hb_bool_t harfbuzzGetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoint_t unicode, hb_codepoint_t variationSelector, hb_codepoint_t* glyph, void* userData) { - MinikinPaint* paint = reinterpret_cast(fontData); + MinikinPaint* paint = reinterpret_cast(fontData); MinikinFont* font = paint->font; uint32_t glyph_id; bool ok = font->GetGlyph(unicode, &glyph_id); @@ -147,7 +257,7 @@ static hb_bool_t harfbuzzGetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoin static hb_position_t harfbuzzGetGlyphHorizontalAdvance(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, void* userData) { - MinikinPaint* paint = reinterpret_cast(fontData); + MinikinPaint* paint = reinterpret_cast(fontData); MinikinFont* font = paint->font; float advance = font->GetHorizontalAdvance(glyph, *paint); return 256 * advance + 0.5; @@ -173,12 +283,21 @@ hb_font_funcs_t* getHbFontFuncs() { return hbFontFuncs; } -hb_font_t* create_hb_font(MinikinFont* minikinFont, MinikinPaint* minikinPaint) { - hb_face_t* face = hb_face_create_for_tables(referenceTable, minikinFont, NULL); +static hb_face_t* getHbFace(MinikinFont* minikinFont) { + HbFaceCache& cache = LayoutEngine::getInstance().hbFaceCache; + int32_t fontId = minikinFont->GetUniqueId(); + hb_face_t* face = cache.mCache.get(fontId); + if (face == NULL) { + face = hb_face_create_for_tables(referenceTable, minikinFont, NULL); + cache.mCache.put(fontId, face); + } + return face; +} + +static hb_font_t* create_hb_font(MinikinFont* minikinFont, MinikinPaint* minikinPaint) { + hb_face_t* face = getHbFace(minikinFont); hb_font_t* font = hb_font_create(face); - hb_face_destroy(face); hb_font_set_funcs(font, getHbFontFuncs(), minikinPaint, 0); - // TODO: manage ownership of face return font; } @@ -192,12 +311,6 @@ static hb_position_t HBFloatToFixed(float v) return scalbnf (v, +8); } -Layout::~Layout() { - for (size_t ix = 0; ix < mHbFonts.size(); ix++) { - hb_font_destroy(mHbFonts[ix]); - } -} - void Layout::dump() const { for (size_t i = 0; i < mGlyphs.size(); i++) { const LayoutGlyph& glyph = mGlyphs[i]; @@ -205,11 +318,7 @@ void Layout::dump() const { } } -// A couple of things probably need to change: -// 1. Deal with multiple sizes in a layout -// 2. We'll probably store FT_Face as primary and then use a cache -// for the hb fonts -int Layout::findFace(MinikinFont* face, MinikinPaint* paint) { +int Layout::findFace(MinikinFont* face, LayoutContext* ctx) { unsigned int ix; for (ix = 0; ix < mFaces.size(); ix++) { if (mFaces[ix] == face) { @@ -217,8 +326,12 @@ int Layout::findFace(MinikinFont* face, MinikinPaint* paint) { } } mFaces.push_back(face); - hb_font_t *font = create_hb_font(face, paint); - mHbFonts.push_back(font); + // Note: ctx == NULL means we're copying from the cache, no need to create + // corresponding hb_font object. + if (ctx != NULL) { + hb_font_t* font = create_hb_font(face, &ctx->paint); + ctx->hbFonts.push_back(font); + } return ix; } @@ -235,14 +348,14 @@ static FontStyle styleFromCss(const CssProperties &props) { } static hb_script_t codePointToScript(hb_codepoint_t codepoint) { - static hb_unicode_funcs_t *u = 0; + static hb_unicode_funcs_t* u = 0; if (!u) { u = hb_icu_get_unicode_funcs(); } return hb_unicode_script(u, codepoint); } -static hb_codepoint_t decodeUtf16(const uint16_t *chars, size_t len, ssize_t *iter) { +static hb_codepoint_t decodeUtf16(const uint16_t* chars, size_t len, ssize_t* iter) { const uint16_t v = chars[(*iter)++]; // test whether v in (0xd800..0xdfff), lead or trail surrogate if ((v & 0xf800) == 0xd800) { @@ -266,7 +379,7 @@ static hb_codepoint_t decodeUtf16(const uint16_t *chars, size_t len, ssize_t *it } } -static hb_script_t getScriptRun(const uint16_t *chars, size_t len, ssize_t *iter) { +static hb_script_t getScriptRun(const uint16_t* chars, size_t len, ssize_t* iter) { if (size_t(*iter) == len) { return HB_SCRIPT_UNKNOWN; } @@ -298,29 +411,99 @@ static hb_script_t getScriptRun(const uint16_t *chars, size_t len, ssize_t *iter return current_script; } -// TODO: API should probably take context -void Layout::doLayout(const uint16_t* buf, size_t nchars) { - AutoMutex _l(gMinikinLock); - if (buffer == 0) { - buffer = hb_buffer_create(); +/** + * For the purpose of layout, a word break is a boundary with no + * kerning or complex script processing. This is necessarily a + * heuristic, but should be accurate most of the time. + */ +static bool isWordBreak(int c) { + if (c == ' ' || (c >= 0x2000 && c <= 0x200a) || c == 0x3000) { + // spaces + return true; } - FT_Error error; + if ((c >= 0x3400 && c <= 0x9fff)) { + // CJK ideographs (and yijing hexagram symbols) + return true; + } + // Note: kana is not included, as sophisticated fonts may kern kana + return false; +} - FontStyle style = styleFromCss(mProps); +/** + * Return offset of previous word break. It is either < offset or == 0. + */ +static size_t getPrevWordBreak(const uint16_t* chars, size_t offset) { + if (offset == 0) return 0; + if (isWordBreak(chars[offset - 1])) { + return offset - 1; + } + for (size_t i = offset - 1; i > 0; i--) { + if (isWordBreak(chars[i - 1])) { + return i; + } + } + return 0; +} - MinikinPaint paint; - double size = mProps.value(fontSize).getFloatValue(); - paint.size = size; - int bidiFlags = mProps.hasTag(minikinBidi) ? mProps.value(minikinBidi).getIntValue() : 0; +/** + * Return offset of next word break. It is either > offset or == len. + */ +static size_t getNextWordBreak(const uint16_t* chars, size_t offset, size_t len) { + if (offset >= len) return len; + if (isWordBreak(chars[offset])) { + return offset + 1; + } + for (size_t i = offset + 1; i < len; i++) { + if (isWordBreak(chars[i])) { + return i; + } + } + return len; +} + +// deprecated API, to avoid breaking client +void Layout::doLayout(const uint16_t* buf, size_t nchars) { + doLayout(buf, 0, nchars, nchars, mCssString); +} + +// TODO: use some standard implementation +template +static T mymin(const T& a, const T& b) { + return a < b ? a : b; +} + +template +static T mymax(const T& a, const T& b) { + return a > b ? a : b; +} + +static void clearHbFonts(LayoutContext* ctx) { + for (size_t i = 0; i < ctx->hbFonts.size(); i++) { + hb_font_destroy(ctx->hbFonts[i]); + } + ctx->hbFonts.clear(); +} + +// TODO: API should probably take context +void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + const std::string& css) { + AutoMutex _l(gMinikinLock); + LayoutContext ctx; + + ctx.props.parse(css); + ctx.style = styleFromCss(ctx.props); + + double size = ctx.props.value(fontSize).getFloatValue(); + ctx.paint.size = size; + int bidiFlags = ctx.props.hasTag(minikinBidi) ? ctx.props.value(minikinBidi).getIntValue() : 0; bool isRtl = (bidiFlags & kDirection_Mask) != 0; bool doSingleRun = true; mGlyphs.clear(); mFaces.clear(); - mHbFonts.clear(); mBounds.setEmpty(); mAdvances.clear(); - mAdvances.resize(nchars, 0); + mAdvances.resize(count, 0); mAdvance = 0; if (!(bidiFlags == kBidi_Force_LTR || bidiFlags == kBidi_Force_RTL)) { UBiDi* bidi = ubidi_open(); @@ -332,12 +515,12 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { } else if (bidiFlags == kBidi_Default_RTL) { bidiReq = UBIDI_DEFAULT_RTL; } - ubidi_setPara(bidi, buf, nchars, bidiReq, NULL, &status); + ubidi_setPara(bidi, buf, bufSize, bidiReq, NULL, &status); if (U_SUCCESS(status)) { int paraDir = ubidi_getParaLevel(bidi) & kDirection_Mask; ssize_t rc = ubidi_countRuns(bidi, &status); - if (!U_SUCCESS(status) || rc < 1) { - ALOGD("error counting bidi runs, status = %d", status); + if (!U_SUCCESS(status) || rc < 0) { + ALOGW("error counting bidi runs, status = %d", status); } if (!U_SUCCESS(status) || rc <= 1) { isRtl = (paraDir == kBidi_RTL); @@ -350,12 +533,12 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { UBiDiDirection runDir = ubidi_getVisualRun(bidi, i, &startRun, &lengthRun); if (startRun == -1 || lengthRun == -1) { ALOGE("invalid visual run"); - // Note: this case will lose text; can it ever actually happen? - break; + // skip the invalid run + continue; } isRtl = (runDir == UBIDI_RTL); // TODO: min/max with context - doLayoutRun(buf, startRun, lengthRun, nchars, isRtl, style, paint); + doLayoutRunCached(buf, startRun, lengthRun, bufSize, isRtl, &ctx); } } } else { @@ -367,14 +550,63 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { } } if (doSingleRun) { - doLayoutRun(buf, 0, nchars, nchars, isRtl, style, paint); + doLayoutRunCached(buf, start, count, bufSize, isRtl, &ctx); + } + clearHbFonts(&ctx); +} + +void Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, LayoutContext* ctx) { + if (!isRtl) { + // left to right + size_t wordstart = start == bufSize ? start : getPrevWordBreak(buf, start + 1); + size_t wordend; + for (size_t iter = start; iter < start + count; iter = wordend) { + wordend = getNextWordBreak(buf, iter, bufSize); + size_t wordcount = mymin(start + count, wordend) - iter; + doLayoutWord(buf + wordstart, iter - wordstart, wordcount, wordend - wordstart, + isRtl, ctx, iter); + wordstart = wordend; + } + } else { + // right to left + size_t wordstart; + size_t end = start + count; + size_t wordend = end == 0 ? 0 : getNextWordBreak(buf, end - 1, bufSize); + for (size_t iter = end; iter > start; iter = wordstart) { + wordstart = getPrevWordBreak(buf, iter); + size_t bufStart = mymax(start, wordstart); + doLayoutWord(buf + wordstart, bufStart - wordstart, iter - bufStart, + wordend - wordstart, isRtl, ctx, bufStart); + wordend = wordstart; + } } } +void Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, LayoutContext* ctx, size_t bufStart) { + LayoutCache& cache = LayoutEngine::getInstance().layoutCache; + LayoutCacheKey key(mCollection, ctx->paint, ctx->style, buf, start, count, bufSize, isRtl); + Layout* value = cache.mCache.get(key); + if (value == NULL) { + value = new Layout(); + value->setFontCollection(mCollection); + value->mAdvances.resize(count, 0); + clearHbFonts(ctx); + // Note: we do the layout from the copy stored in the key, in case a + // badly-behaved client is mutating the buffer in a separate thread. + value->doLayoutRun(key.textBuf(), start, count, bufSize, isRtl, ctx); + } + appendLayout(value, bufStart); + cache.mCache.put(key, value); + +} + void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - bool isRtl, FontStyle style, MinikinPaint& paint) { + bool isRtl, LayoutContext* ctx) { + hb_buffer_t* buffer = LayoutEngine::getInstance().hbBuffer; vector items; - mCollection->itemize(buf + start, count, style, &items); + mCollection->itemize(buf + start, count, ctx->style, &items); if (isRtl) { std::reverse(items.begin(), items.end()); } @@ -383,10 +615,10 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t float y = 0; for (size_t run_ix = 0; run_ix < items.size(); run_ix++) { FontCollection::Run &run = items[run_ix]; - int font_ix = findFace(run.font, &paint); - paint.font = mFaces[font_ix]; - hb_font_t *hbFont = mHbFonts[font_ix]; - if (paint.font == NULL) { + int font_ix = findFace(run.font, ctx); + ctx->paint.font = mFaces[font_ix]; + hb_font_t* hbFont = ctx->hbFonts[font_ix]; + if (ctx->paint.font == NULL) { // TODO: should log what went wrong continue; } @@ -394,7 +626,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t std::cout << "Run " << run_ix << ", font " << font_ix << " [" << run.start << ":" << run.end << "]" << std::endl; #endif - double size = paint.size; + double size = ctx->paint.size; hb_font_set_ppem(hbFont, size, size); hb_font_set_scale(hbFont, HBFloatToFixed(size), HBFloatToFixed(size)); @@ -412,8 +644,8 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart); hb_shape(hbFont, buffer, NULL, 0); unsigned int numGlyphs; - hb_glyph_info_t *info = hb_buffer_get_glyph_infos(buffer, &numGlyphs); - hb_glyph_position_t *positions = hb_buffer_get_glyph_positions(buffer, NULL); + hb_glyph_info_t* info = hb_buffer_get_glyph_infos(buffer, &numGlyphs); + hb_glyph_position_t* positions = hb_buffer_get_glyph_positions(buffer, NULL); for (unsigned int i = 0; i < numGlyphs; i++) { #ifdef VERBOSE std::cout << positions[i].x_advance << " " << positions[i].y_advance << " " << positions[i].x_offset << " " << positions[i].y_offset << std::endl; std::cout << "DoLayout " << info[i].codepoint << @@ -426,7 +658,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t mGlyphs.push_back(glyph); float xAdvance = HBFixedToFloat(positions[i].x_advance); MinikinRect glyphBounds; - paint.font->GetBounds(&glyphBounds, glyph_ix, paint); + ctx->paint.font->GetBounds(&glyphBounds, glyph_ix, ctx->paint); glyphBounds.offset(x + xoff, y + yoff); mBounds.join(glyphBounds); size_t cluster = info[i].cluster; @@ -438,7 +670,33 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t mAdvance = x; } -void Layout::draw(Bitmap* surface, int x0, int y0) const { +void Layout::appendLayout(Layout* src, size_t start) { + // Note: size==1 is by far most common, should have specialized vector for this + std::vector fontMap; + for (size_t i = 0; i < src->mFaces.size(); i++) { + int font_ix = findFace(src->mFaces[i], NULL); + fontMap.push_back(font_ix); + } + int x0 = mAdvance; + for (size_t i = 0; i < src->mGlyphs.size(); i++) { + LayoutGlyph& srcGlyph = src->mGlyphs[i]; + int font_ix = fontMap[srcGlyph.font_ix]; + unsigned int glyph_id = srcGlyph.glyph_id; + float x = x0 + srcGlyph.x; + float y = srcGlyph.y; + LayoutGlyph glyph = {font_ix, glyph_id, x, y}; + mGlyphs.push_back(glyph); + } + for (size_t i = 0; i < src->mAdvances.size(); i++) { + mAdvances[i + start] = src->mAdvances[i]; + } + MinikinRect srcBounds(src->mBounds); + srcBounds.offset(x0, 0); + mBounds.join(srcBounds); + mAdvance += src->mAdvance; +} + +void Layout::draw(Bitmap* surface, int x0, int y0, float size) const { /* TODO: redo as MinikinPaint settings if (mProps.hasTag(minikinHinting)) { @@ -449,11 +707,11 @@ void Layout::draw(Bitmap* surface, int x0, int y0) const { */ for (size_t i = 0; i < mGlyphs.size(); i++) { const LayoutGlyph& glyph = mGlyphs[i]; - MinikinFont *mf = mFaces[glyph.font_ix]; - MinikinFontFreeType *face = static_cast(mf); + MinikinFont* mf = mFaces[glyph.font_ix]; + MinikinFontFreeType* face = static_cast(mf); GlyphBitmap glyphBitmap; MinikinPaint paint; - paint.size = mProps.value(fontSize).getFloatValue(); + paint.size = size; bool ok = face->Render(glyph.glyph_id, paint, &glyphBitmap); printf("glyphBitmap.width=%d, glyphBitmap.height=%d (%d, %d) x=%f, y=%f, ok=%d\n", glyphBitmap.width, glyphBitmap.height, glyphBitmap.left, glyphBitmap.top, glyph.x, glyph.y, ok); @@ -464,15 +722,15 @@ void Layout::draw(Bitmap* surface, int x0, int y0) const { } } -void Layout::setProperties(string css) { - mProps.parse(css); +void Layout::setProperties(const string& css) { + mCssString = css; } size_t Layout::nGlyphs() const { return mGlyphs.size(); } -MinikinFont *Layout::getFont(int i) const { +MinikinFont* Layout::getFont(int i) const { const LayoutGlyph& glyph = mGlyphs[i]; return mFaces[glyph.font_ix]; } diff --git a/engine/src/flutter/sample/example.cpp b/engine/src/flutter/sample/example.cpp index 9b012ef0866..b8bd66f4be5 100644 --- a/engine/src/flutter/sample/example.cpp +++ b/engine/src/flutter/sample/example.cpp @@ -89,7 +89,7 @@ int runMinikinTest() { layout.doLayout(icuText.getBuffer(), icuText.length()); layout.dump(); Bitmap bitmap(250, 50); - layout.draw(&bitmap, 10, 40); + layout.draw(&bitmap, 10, 40, 32); std::ofstream o; o.open("/data/local/tmp/foo.pgm", std::ios::out | std::ios::binary); bitmap.writePnm(o); From 9c5d659d5fdfb149f786335f39b20e55c71d949b Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 26 May 2014 08:24:36 -0700 Subject: [PATCH 021/364] Fix for bug 15252902 native crash in Minikin This is a fix for bug 15252902 "Crash observed on keep launch or existing youtube app after playing video". It was doing the test for a null font after trying to resolve the font in a cache, which caused a crash when there was no font for the run. This patch just tests before cache lookup. Change-Id: Iee41f7ce6b69cb09438462b6aaa916f242da7b77 --- engine/src/flutter/libs/minikin/Layout.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 886b7d1f1c4..3935eb761c5 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -615,13 +615,13 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t float y = 0; for (size_t run_ix = 0; run_ix < items.size(); run_ix++) { FontCollection::Run &run = items[run_ix]; + if (run.font == NULL) { + ALOGE("no font for run starting u+%04x length %d", buf[run.start], run.end - run.start); + continue; + } int font_ix = findFace(run.font, ctx); ctx->paint.font = mFaces[font_ix]; hb_font_t* hbFont = ctx->hbFonts[font_ix]; - if (ctx->paint.font == NULL) { - // TODO: should log what went wrong - continue; - } #ifdef VERBOSE std::cout << "Run " << run_ix << ", font " << font_ix << " [" << run.start << ":" << run.end << "]" << std::endl; From e1a0422aae785f6ed213ba0bb0139edc30502d7a Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 29 May 2014 14:01:18 -0700 Subject: [PATCH 022/364] Fix for Minikin native crash The context start offset wasn't being taken into account for accumulating the advance values, leading in some cases to array index overflow. This is a fix for bug 15327918 "SIGSEGV in android::MinikinFontSkia::GetSkTypeface()" Change-Id: I9b646785724c9b72d862b822cd84661c106fbe52 --- engine/src/flutter/libs/minikin/Layout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 3935eb761c5..aba8a1c7abe 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -661,7 +661,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t ctx->paint.font->GetBounds(&glyphBounds, glyph_ix, ctx->paint); glyphBounds.offset(x + xoff, y + yoff); mBounds.join(glyphBounds); - size_t cluster = info[i].cluster; + size_t cluster = info[i].cluster - start; mAdvances[cluster] += xAdvance; x += xAdvance; } From 7d4090fbe937014d79bb996c03e763d2557d238d Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 27 May 2014 08:05:51 -0700 Subject: [PATCH 023/364] Language and variant selection This patch adds a "lang" pseudo-CSS property and uses it both to select an appropriate font and control the "locl" OpenType feature to get the most appropriate rendering for the langauge and script. In addition, the "-minikin-variant" property selects between "compact" and "elegant" variants of a font, as the former is needed for vertically cramped spaces. This is part of the fix for bug 15179652 "Japanese font isn't shown on LMP". Change-Id: I7fab23c12d4c797a6d339a16e497b79a3afe9df1 --- engine/src/flutter/include/minikin/CssParse.h | 23 +++++-- .../flutter/include/minikin/FontCollection.h | 3 +- .../src/flutter/include/minikin/FontFamily.h | 61 ++++++++++++++++++- engine/src/flutter/libs/minikin/CssParse.cpp | 53 ++++++++++++++-- .../flutter/libs/minikin/FontCollection.cpp | 37 +++++++++-- .../src/flutter/libs/minikin/FontFamily.cpp | 41 +++++++++++++ engine/src/flutter/libs/minikin/Layout.cpp | 18 +++++- 7 files changed, 214 insertions(+), 22 deletions(-) diff --git a/engine/src/flutter/include/minikin/CssParse.h b/engine/src/flutter/include/minikin/CssParse.h index 2dceb4ac26c..519056df572 100644 --- a/engine/src/flutter/include/minikin/CssParse.h +++ b/engine/src/flutter/include/minikin/CssParse.h @@ -25,26 +25,31 @@ namespace android { enum CssTag { unknown, fontSize, - fontWeight, fontStyle, - minikinHinting, + fontWeight, + cssLang, minikinBidi, + minikinHinting, + minikinVariant, }; const std::string cssTagNames[] = { "unknown", "font-size", - "font-weight", "font-style", - "-minikin-hinting", + "font-weight", + "lang", "-minikin-bidi", + "-minikin-hinting", + "-minikin-variant", }; class CssValue { public: enum Type { UNKNOWN, - FLOAT + FLOAT, + STRING }; enum Units { SCALAR, @@ -58,14 +63,20 @@ public: Type getType() const { return mType; } double getFloatValue() const { return floatValue; } int getIntValue() const { return floatValue; } + std::string getStringValue() const { return stringValue; } std::string toString(CssTag tag) const; void setFloatValue(double v) { mType = FLOAT; floatValue = v; } + void setStringValue(const std::string& v) { + mType = STRING; + stringValue = v; + } private: Type mType; double floatValue; + std::string stringValue; Units mUnits; }; @@ -85,4 +96,4 @@ private: } // namespace android -#endif // MINIKIN_CSS_PARSE_H \ No newline at end of file +#endif // MINIKIN_CSS_PARSE_H diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index c6c2ed05b0e..a350237a3ef 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -32,7 +32,8 @@ public: ~FontCollection(); - const FontFamily* getFamilyForChar(uint32_t ch) const; + const FontFamily* getFamilyForChar(uint32_t ch, FontLanguage lang, int variant) const; + class Run { public: // Do copy constructor, assignment, destructor so it can be used in vectors diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index a4fe9cb9e40..6bdf5d6376d 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -25,6 +25,36 @@ namespace android { +class MinikinFont; + +// FontLanguage is a compact representation of a bcp-47 language tag. It +// does not capture all possible information, only what directly affects +// font rendering. +class FontLanguage { + friend class FontStyle; +public: + FontLanguage() : mBits(0) { } + + // Parse from string + FontLanguage(const char* buf, size_t size); + + bool operator==(const FontLanguage other) const { return mBits == other.mBits; } + + // 0 = no match, 1 = language matches, 2 = language and script match + int match(const FontLanguage other) const; + +private: + explicit FontLanguage(uint32_t bits) : mBits(bits) { } + + uint32_t bits() const { return mBits; } + + static const uint32_t kBaseLangMask = 0xffff; + static const uint32_t kScriptMask = (1 << 18) - (1 << 16); + static const uint32_t kHansFlag = 1 << 16; + static const uint32_t kHantFlag = 1 << 17; + uint32_t mBits; +}; + // FontStyle represents all style information needed to select an actual font // from a collection. The implementation is packed into a single 32-bit word // so it can be efficiently copied, embedded in other objects, etc. @@ -33,24 +63,44 @@ public: FontStyle(int weight = 4, bool italic = false) { bits = (weight & kWeightMask) | (italic ? kItalicMask : 0); } + FontStyle(FontLanguage lang, int variant = 0, int weight = 4, bool italic = false) { + bits = (weight & kWeightMask) | (italic ? kItalicMask : 0) + | (variant << kVariantShift) | (lang.bits() << kLangShift); + } int getWeight() const { return bits & kWeightMask; } bool getItalic() const { return (bits & kItalicMask) != 0; } + int getVariant() const { return (bits >> kVariantShift) & kVariantMask; } + FontLanguage getLanguage() const { return FontLanguage(bits >> kLangShift); } + bool operator==(const FontStyle other) const { return bits == other.bits; } - // TODO: language, variant hash_t hash() const { return bits; } private: - static const int kWeightMask = 0xf; - static const int kItalicMask = 16; + static const uint32_t kWeightMask = (1 << 4) - 1; + static const uint32_t kItalicMask = 1 << 4; + static const int kVariantShift = 5; + static const uint32_t kVariantMask = (1 << 2) - 1; + static const int kLangShift = 7; uint32_t bits; }; +enum FontVariant { + VARIANT_DEFAULT = 0, + VARIANT_COMPACT = 1, + VARIANT_ELEGANT = 2, +}; + inline hash_t hash_type(const FontStyle &style) { return style.hash(); } class FontFamily : public MinikinRefCounted { public: + FontFamily() { } + + FontFamily(FontLanguage lang, int variant) : mLang(lang), mVariant(variant) { + } + ~FontFamily(); // Add font to family, extracting style information from the font @@ -59,6 +109,9 @@ public: void addFont(MinikinFont* typeface, FontStyle style); MinikinFont* getClosestMatch(FontStyle style) const; + FontLanguage lang() const { return mLang; } + int variant() const { return mVariant; } + // API's for enumerating the fonts in a family. These don't guarantee any particular order size_t getNumFonts() const; MinikinFont* getFont(size_t index) const; @@ -73,6 +126,8 @@ private: MinikinFont* typeface; FontStyle style; }; + FontLanguage mLang; + int mVariant; std::vector mFonts; }; diff --git a/engine/src/flutter/libs/minikin/CssParse.cpp b/engine/src/flutter/libs/minikin/CssParse.cpp index 5bb6949b9a2..5e96007c4ea 100644 --- a/engine/src/flutter/libs/minikin/CssParse.cpp +++ b/engine/src/flutter/libs/minikin/CssParse.cpp @@ -20,6 +20,7 @@ #include // for sprintf - for debugging #include +#include using std::map; using std::pair; @@ -27,27 +28,58 @@ using std::string; namespace android { -bool strEqC(const string str, size_t off, size_t len, const char* str2) { +static bool strEqC(const string str, size_t off, size_t len, const char* str2) { if (len != strlen(str2)) return false; return !memcmp(str.data() + off, str2, len); } -CssTag parseTag(const string str, size_t off, size_t len) { +static CssTag parseTag(const string str, size_t off, size_t len) { if (len == 0) return unknown; char c = str[off]; if (c == 'f') { if (strEqC(str, off, len, "font-size")) return fontSize; if (strEqC(str, off, len, "font-weight")) return fontWeight; if (strEqC(str, off, len, "font-style")) return fontStyle; + } else if (c == 'l') { + if (strEqC(str, off, len, "lang")) return cssLang; } else if (c == '-') { - if (strEqC(str, off, len, "-minikin-hinting")) return minikinHinting; if (strEqC(str, off, len, "-minikin-bidi")) return minikinBidi; + if (strEqC(str, off, len, "-minikin-hinting")) return minikinHinting; + if (strEqC(str, off, len, "-minikin-variant")) return minikinVariant; } return unknown; } -bool parseValue(const string str, size_t *off, size_t len, CssTag tag, - CssValue* v) { +static bool parseStringValue(const string& str, size_t* off, size_t len, CssTag tag, CssValue* v) { + const char* data = str.data(); + size_t beg = *off; + if (beg == len) return false; + char first = data[beg]; + bool quoted = false; + if (first == '\'' || first == '\"') { + quoted = true; + beg++; + } + size_t end; + for (end = beg; end < len; end++) { + char c = data[end]; + if (quoted && c == first) { + v->setStringValue(std::string(str, beg, end - beg)); + *off = end + 1; + return true; + } else if (!quoted && (c == ';' || c == ' ')) { + break; + } // TODO: deal with backslash escape, but only important for real strings + } + v->setStringValue(std::string(str, beg, end - beg)); + *off = end; + return true; +} + +static bool parseValue(const string& str, size_t* off, size_t len, CssTag tag, CssValue* v) { + if (tag == cssLang) { + return parseStringValue(str, off, len, tag, v); + } const char* data = str.data(); char* endptr; double fv = strtod(data + *off, &endptr); @@ -78,6 +110,12 @@ bool parseValue(const string str, size_t *off, size_t len, CssTag tag, } else { return false; } + } else if (tag == minikinVariant) { + if (strEqC(str, *off, taglen, "compact")) { + fv = VARIANT_COMPACT; + } else if (strEqC(str, *off, taglen, "elegant")) { + fv = VARIANT_ELEGANT; + } } else { return false; } @@ -91,10 +129,15 @@ string CssValue::toString(CssTag tag) const { if (mType == FLOAT) { if (tag == fontStyle) { return floatValue ? "italic" : "normal"; + } else if (tag == minikinVariant) { + if (floatValue == VARIANT_COMPACT) return "compact"; + if (floatValue == VARIANT_ELEGANT) return "elegant"; } char buf[64]; sprintf(buf, "%g", floatValue); return string(buf); + } else if (mType == STRING) { + return stringValue; // should probably quote } return ""; } diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index e6ff117ad74..89086ee41c2 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -108,7 +108,19 @@ FontCollection::~FontCollection() { } } -const FontFamily* FontCollection::getFamilyForChar(uint32_t ch) const { +// Implement heuristic for choosing best-match font. Here are the rules: +// 1. If first font in the collection has the character, it wins. +// 2. If a font matches both language and script, it gets a score of 4. +// 3. If a font matches just language, it gets a score of 2. +// 4. Matching the "compact" or "elegant" variant adds one to the score. +// 5. Highest score wins, with ties resolved to the first font. + +// Note that we may want to make the selection more dependent on +// context, so for example a sequence of Devanagari, ZWJ, Devanagari +// would get itemized as one run, even though by the rules the ZWJ +// would go to the Latin font. +const FontFamily* FontCollection::getFamilyForChar(uint32_t ch, FontLanguage lang, + int variant) const { if (ch >= mMaxChar) { return NULL; } @@ -116,17 +128,33 @@ const FontFamily* FontCollection::getFamilyForChar(uint32_t ch) const { #ifdef VERBOSE_DEBUG ALOGD("querying range %d:%d\n", range.start, range.end); #endif + FontFamily* bestFamily = NULL; + int bestScore = -1; for (size_t i = range.start; i < range.end; i++) { const FontInstance* instance = mInstanceVec[i]; if (instance->mCoverage->get(ch)) { - return instance->mFamily; + FontFamily* family = instance->mFamily; + // First font family in collection always matches + if (mInstances[0].mFamily == family) { + return family; + } + int score = lang.match(family->lang()) * 2; + if (variant != 0 && variant == family->variant()) { + score++; + } + if (score > bestScore) { + bestScore = score; + bestFamily = family; + } } } - return NULL; + return bestFamily; } void FontCollection::itemize(const uint16_t *string, size_t string_size, FontStyle style, vector* result) const { + FontLanguage lang = style.getLanguage(); + int variant = style.getVariant(); const FontFamily* lastFamily = NULL; Run* run = NULL; int nShorts; @@ -140,7 +168,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty nShorts = 2; } } - const FontFamily* family = getFamilyForChar(ch); + const FontFamily* family = getFamilyForChar(ch, lang, variant); if (i == 0 || family != lastFamily) { Run dummy; result->push_back(dummy); @@ -149,6 +177,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty run->font = NULL; // maybe we should do something different here } else { run->font = family->getClosestMatch(style); + // TODO: simplify refcounting (FontCollection lifetime dominates) run->font->RefLocked(); } lastFamily = family; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index d818f77eec2..0fb98ae4e71 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -30,6 +30,47 @@ using std::vector; namespace android { +// Parse bcp-47 language identifier into internal structure +FontLanguage::FontLanguage(const char* buf, size_t size) { + uint32_t bits = 0; + size_t i; + for (i = 0; i < size && buf[i] != '-' && buf[i] != '_'; i++) { + uint16_t c = buf[i]; + if (c == '-' || c == '_') break; + } + if (i == 2) { + bits = (uint8_t(buf[0]) << 8) | uint8_t(buf[1]); + } + size_t next; + for (i++; i < size; i = next + 1) { + for (next = i; next < size; next++) { + uint16_t c = buf[next]; + if (c == '-' || c == '_') break; + } + if (next - i == 4 && buf[i] == 'H' && buf[i+1] == 'a' && buf[i+2] == 'n') { + if (buf[i+3] == 's') { + bits |= kHansFlag; + } else if (buf[i+3] == 't') { + bits |= kHantFlag; + } + } + // TODO: this might be a good place to infer script from country (zh_TW -> Hant), + // but perhaps it's up to the client to do that, before passing a string. + } + mBits = bits; +} + +int FontLanguage::match(const FontLanguage other) const { + int result = 0; + if ((mBits & kBaseLangMask) == (other.mBits & kBaseLangMask)) { + result++; + if ((mBits & kScriptMask) != 0 && (mBits & kScriptMask) == (other.mBits & kScriptMask)) { + result++; + } + } + return result; +} + FontFamily::~FontFamily() { for (size_t i = 0; i < mFonts.size(); i++) { mFonts[i].typeface->UnrefLocked(); diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index aba8a1c7abe..4028d9e4207 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -344,7 +344,16 @@ static FontStyle styleFromCss(const CssProperties &props) { if (props.hasTag(fontStyle)) { italic = props.value(fontStyle).getIntValue() != 0; } - return FontStyle(weight, italic); + FontLanguage lang; + if (props.hasTag(cssLang)) { + string langStr = props.value(cssLang).getStringValue(); + lang = FontLanguage(langStr.c_str(), langStr.size()); + } + int variant = 0; + if (props.hasTag(minikinVariant)) { + variant = props.value(minikinVariant).getIntValue(); + } + return FontStyle(lang, variant, weight, italic); } static hb_script_t codePointToScript(hb_codepoint_t codepoint) { @@ -486,7 +495,7 @@ static void clearHbFonts(LayoutContext* ctx) { // TODO: API should probably take context void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - const std::string& css) { + const string& css) { AutoMutex _l(gMinikinLock); LayoutContext ctx; @@ -599,7 +608,6 @@ void Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_ } appendLayout(value, bufStart); cache.mCache.put(key, value); - } void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, @@ -641,6 +649,10 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t hb_buffer_reset(buffer); hb_buffer_set_script(buffer, script); hb_buffer_set_direction(buffer, isRtl? HB_DIRECTION_RTL : HB_DIRECTION_LTR); + if (ctx->props.hasTag(cssLang)) { + string lang = ctx->props.value(cssLang).getStringValue(); + hb_buffer_set_language(buffer, hb_language_from_string(lang.c_str(), -1)); + } hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart); hb_shape(hbFont, buffer, NULL, 0); unsigned int numGlyphs; From 1391c37ea908bff79222109f4351d361c2910372 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 28 May 2014 15:38:35 -0700 Subject: [PATCH 024/364] Fix ZWJ not working for Indic fonts This is a fix for bug 15185229 ZWJ not working in Sinhala and Kannada. Indic fonts (unlike Arabic) require the entire string, including ZWJ, to be passed to Harfbuzz; it's not enough for the ZWJ to be present in the context. The solution is to be "sticky" in font itemization, continuing to use the same font as long as it has Unicode coverage. Change-Id: I7673bc56fbda09f1e1a4582e8d88342343b706f1 --- .../flutter/include/minikin/FontCollection.h | 4 +- .../flutter/libs/minikin/FontCollection.cpp | 48 +++++++++---------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index a350237a3ef..78ab2aae7b9 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -32,8 +32,6 @@ public: ~FontCollection(); - const FontFamily* getFamilyForChar(uint32_t ch, FontLanguage lang, int variant) const; - class Run { public: // Do copy constructor, assignment, destructor so it can be used in vectors @@ -74,6 +72,8 @@ private: size_t end; }; + const FontInstance* getInstanceForChar(uint32_t ch, FontLanguage lang, int variant) const; + // static for allocating unique id's static uint32_t sNextId; diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 89086ee41c2..1713b476e0b 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -114,13 +114,8 @@ FontCollection::~FontCollection() { // 3. If a font matches just language, it gets a score of 2. // 4. Matching the "compact" or "elegant" variant adds one to the score. // 5. Highest score wins, with ties resolved to the first font. - -// Note that we may want to make the selection more dependent on -// context, so for example a sequence of Devanagari, ZWJ, Devanagari -// would get itemized as one run, even though by the rules the ZWJ -// would go to the Latin font. -const FontFamily* FontCollection::getFamilyForChar(uint32_t ch, FontLanguage lang, - int variant) const { +const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t ch, + FontLanguage lang, int variant) const { if (ch >= mMaxChar) { return NULL; } @@ -128,7 +123,7 @@ const FontFamily* FontCollection::getFamilyForChar(uint32_t ch, FontLanguage lan #ifdef VERBOSE_DEBUG ALOGD("querying range %d:%d\n", range.start, range.end); #endif - FontFamily* bestFamily = NULL; + const FontInstance* bestInstance = NULL; int bestScore = -1; for (size_t i = range.start; i < range.end; i++) { const FontInstance* instance = mInstanceVec[i]; @@ -136,7 +131,7 @@ const FontFamily* FontCollection::getFamilyForChar(uint32_t ch, FontLanguage lan FontFamily* family = instance->mFamily; // First font family in collection always matches if (mInstances[0].mFamily == family) { - return family; + return instance; } int score = lang.match(family->lang()) * 2; if (variant != 0 && variant == family->variant()) { @@ -144,18 +139,18 @@ const FontFamily* FontCollection::getFamilyForChar(uint32_t ch, FontLanguage lan } if (score > bestScore) { bestScore = score; - bestFamily = family; + bestInstance = instance; } } } - return bestFamily; + return bestInstance; } void FontCollection::itemize(const uint16_t *string, size_t string_size, FontStyle style, vector* result) const { FontLanguage lang = style.getLanguage(); int variant = style.getVariant(); - const FontFamily* lastFamily = NULL; + const FontInstance* lastInstance = NULL; Run* run = NULL; int nShorts; for (size_t i = 0; i < string_size; i += nShorts) { @@ -168,20 +163,23 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty nShorts = 2; } } - const FontFamily* family = getFamilyForChar(ch, lang, variant); - if (i == 0 || family != lastFamily) { - Run dummy; - result->push_back(dummy); - run = &result->back(); - if (family == NULL) { - run->font = NULL; // maybe we should do something different here - } else { - run->font = family->getClosestMatch(style); - // TODO: simplify refcounting (FontCollection lifetime dominates) - run->font->RefLocked(); + // Continue using existing font as long as it has coverage. + if (lastInstance == NULL || !lastInstance->mCoverage->get(ch)) { + const FontInstance* instance = getInstanceForChar(ch, lang, variant); + if (i == 0 || instance != lastInstance) { + Run dummy; + result->push_back(dummy); + run = &result->back(); + if (instance == NULL) { + run->font = NULL; // maybe we should do something different here + } else { + run->font = instance->mFamily->getClosestMatch(style); + // TODO: simplify refcounting (FontCollection lifetime dominates) + run->font->RefLocked(); + } + lastInstance = instance; + run->start = i; } - lastFamily = family; - run->start = i; } run->end = i + nShorts; } From 23801bf449e5bfa467729b1a61af324a7afbee19 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 30 May 2014 23:38:56 -0700 Subject: [PATCH 025/364] Support for scaleX and skewX Adds pseudo-css properties for scaleX and skewX, as well as paint flags, and plumb them through to the MinikinPaint abstraction and to Harfbuzz, to support nontrivial scale and stretch of text. This is the Minikin part of the fix for bug 15186705 "Usability of the suggestion strip in recent OTA's is severely reduced" Change-Id: Ifa60355e086e4691ff92c5d50d84eb7cea0fea95 --- engine/src/flutter/include/minikin/CssParse.h | 8 +++- .../src/flutter/include/minikin/MinikinFont.h | 4 +- engine/src/flutter/libs/minikin/CssParse.cpp | 3 ++ engine/src/flutter/libs/minikin/Layout.cpp | 43 +++++++++++++------ 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/engine/src/flutter/include/minikin/CssParse.h b/engine/src/flutter/include/minikin/CssParse.h index 519056df572..ae2aac607ad 100644 --- a/engine/src/flutter/include/minikin/CssParse.h +++ b/engine/src/flutter/include/minikin/CssParse.h @@ -24,24 +24,30 @@ namespace android { enum CssTag { unknown, + fontScaleX, fontSize, + fontSkewX, fontStyle, fontWeight, cssLang, minikinBidi, minikinHinting, minikinVariant, + paintFlags, }; const std::string cssTagNames[] = { "unknown", + "font-scale-x", "font-size", + "font-skew-x", "font-style", "font-weight", "lang", "-minikin-bidi", "-minikin-hinting", "-minikin-variant", + "-paint-flags", }; class CssValue { @@ -62,7 +68,7 @@ public: mType(FLOAT), floatValue(v), mUnits(SCALAR) { } Type getType() const { return mType; } double getFloatValue() const { return floatValue; } - int getIntValue() const { return floatValue; } + int32_t getIntValue() const { return floatValue; } std::string getStringValue() const { return stringValue; } std::string toString(CssTag tag) const; void setFloatValue(double v) { diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index dbb89f83312..1f6894cb643 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -31,7 +31,9 @@ class MinikinFont; struct MinikinPaint { MinikinFont *font; float size; - // todo: skew, stretch, hinting + float scaleX; + float skewX; + int32_t paintFlags; }; struct MinikinRect { diff --git a/engine/src/flutter/libs/minikin/CssParse.cpp b/engine/src/flutter/libs/minikin/CssParse.cpp index 5e96007c4ea..147f3304bbb 100644 --- a/engine/src/flutter/libs/minikin/CssParse.cpp +++ b/engine/src/flutter/libs/minikin/CssParse.cpp @@ -37,7 +37,9 @@ static CssTag parseTag(const string str, size_t off, size_t len) { if (len == 0) return unknown; char c = str[off]; if (c == 'f') { + if (strEqC(str, off, len, "font-scale-x")) return fontScaleX; if (strEqC(str, off, len, "font-size")) return fontSize; + if (strEqC(str, off, len, "font-skew-x")) return fontSkewX; if (strEqC(str, off, len, "font-weight")) return fontWeight; if (strEqC(str, off, len, "font-style")) return fontStyle; } else if (c == 'l') { @@ -46,6 +48,7 @@ static CssTag parseTag(const string str, size_t off, size_t len) { if (strEqC(str, off, len, "-minikin-bidi")) return minikinBidi; if (strEqC(str, off, len, "-minikin-hinting")) return minikinHinting; if (strEqC(str, off, len, "-minikin-variant")) return minikinVariant; + if (strEqC(str, off, len, "-paint-flags")) return paintFlags; } return unknown; } diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 4028d9e4207..c13aed8ef26 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -63,7 +63,8 @@ public: LayoutCacheKey(const FontCollection* collection, const MinikinPaint& paint, FontStyle style, const uint16_t* chars, size_t start, size_t count, size_t nchars, bool dir) : mStart(start), mCount(count), mId(collection->getId()), mStyle(style), - mSize(paint.size), mIsRtl(dir) { + mSize(paint.size), mScaleX(paint.scaleX), mSkewX(paint.skewX), + mPaintFlags(paint.paintFlags), mIsRtl(dir) { mText.setTo(chars, nchars); } bool operator==(const LayoutCacheKey &other) const; @@ -78,6 +79,9 @@ private: uint32_t mId; // for the font collection FontStyle mStyle; float mSize; + float mScaleX; + float mSkewX; + int mPaintFlags; bool mIsRtl; // Note: any fields added to MinikinPaint must also be reflected here. // TODO: language matching (possibly integrate into style) @@ -133,13 +137,16 @@ public: ANDROID_SINGLETON_STATIC_INSTANCE(LayoutEngine); bool LayoutCacheKey::operator==(const LayoutCacheKey& other) const { - return mId == other.mId && - mStart == other.mStart && - mCount == other.mCount && - mStyle == other.mStyle && - mSize == other.mSize && - mIsRtl == other.mIsRtl && - mText == other.mText; + return mId == other.mId + && mStart == other.mStart + && mCount == other.mCount + && mStyle == other.mStyle + && mSize == other.mSize + && mScaleX == other.mScaleX + && mSkewX == other.mSkewX + && mPaintFlags == other.mPaintFlags + && mIsRtl == other.mIsRtl + && mText == other.mText; } hash_t LayoutCacheKey::hash() const { @@ -148,6 +155,9 @@ hash_t LayoutCacheKey::hash() const { hash = JenkinsHashMix(hash, mCount); hash = JenkinsHashMix(hash, hash_type(mStyle)); hash = JenkinsHashMix(hash, hash_type(mSize)); + hash = JenkinsHashMix(hash, hash_type(mScaleX)); + hash = JenkinsHashMix(hash, hash_type(mSkewX)); + hash = JenkinsHashMix(hash, hash_type(mPaintFlags)); hash = JenkinsHashMix(hash, hash_type(mIsRtl)); hash = JenkinsHashMixShorts(hash, mText.string(), mText.size()); return JenkinsHashWhiten(hash); @@ -502,8 +512,13 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu ctx.props.parse(css); ctx.style = styleFromCss(ctx.props); - double size = ctx.props.value(fontSize).getFloatValue(); - ctx.paint.size = size; + ctx.paint.size = ctx.props.value(fontSize).getFloatValue(); + ctx.paint.scaleX = ctx.props.hasTag(fontScaleX) + ? ctx.props.value(fontScaleX).getFloatValue() : 1; + ctx.paint.skewX = ctx.props.hasTag(fontSkewX) + ? ctx.props.value(fontSkewX).getFloatValue() : 0; + ctx.paint.paintFlags = ctx.props.hasTag(paintFlags) + ?ctx.props.value(paintFlags).getIntValue() : 0; int bidiFlags = ctx.props.hasTag(minikinBidi) ? ctx.props.value(minikinBidi).getIntValue() : 0; bool isRtl = (bidiFlags & kDirection_Mask) != 0; bool doSingleRun = true; @@ -635,8 +650,9 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t " [" << run.start << ":" << run.end << "]" << std::endl; #endif double size = ctx->paint.size; - hb_font_set_ppem(hbFont, size, size); - hb_font_set_scale(hbFont, HBFloatToFixed(size), HBFloatToFixed(size)); + double scaleX = ctx->paint.scaleX; + hb_font_set_ppem(hbFont, size * scaleX, size); + hb_font_set_scale(hbFont, HBFloatToFixed(size * scaleX), HBFloatToFixed(size)); // TODO: if there are multiple scripts within a font in an RTL run, // we need to reorder those runs. This is unlikely with our current @@ -665,7 +681,8 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t #endif hb_codepoint_t glyph_ix = info[i].codepoint; float xoff = HBFixedToFloat(positions[i].x_offset); - float yoff = HBFixedToFloat(positions[i].y_offset); + float yoff = -HBFixedToFloat(positions[i].y_offset); + xoff += yoff * ctx->paint.skewX; LayoutGlyph glyph = {font_ix, glyph_ix, x + xoff, y + yoff}; mGlyphs.push_back(glyph); float xAdvance = HBFixedToFloat(positions[i].x_advance); From 014498ae2ab29399a632c548b8dc94cbf215b861 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 4 Jun 2014 11:15:28 -0700 Subject: [PATCH 026/364] Fix unmatching type Missed a slightly mismatched type (int vs int32_t) from a previous code review. Change-Id: Ib56775a3a1a6ec3763da7f7432186954251cc048 --- engine/src/flutter/libs/minikin/Layout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index c13aed8ef26..5471b38bdfe 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -81,7 +81,7 @@ private: float mSize; float mScaleX; float mSkewX; - int mPaintFlags; + int32_t mPaintFlags; bool mIsRtl; // Note: any fields added to MinikinPaint must also be reflected here. // TODO: language matching (possibly integrate into style) From ddcdc08c7c14059df0494776161c7887967965e4 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 4 Jun 2014 15:25:30 -0700 Subject: [PATCH 027/364] Make paint flags consistently uint32_t Change internal plumbing of paint flags (including CssParse) to uint32_t consistently, to match the type used in the client. This will probably prevent compiler warnings. Also renames "float" to "double" to avoid confusion about precision. Change-Id: I80374712c4067ca9e7711cc2d4ec33c440ab9c7c --- engine/src/flutter/include/minikin/CssParse.h | 17 +++++++++-------- .../src/flutter/include/minikin/MinikinFont.h | 2 +- engine/src/flutter/libs/minikin/CssParse.cpp | 12 ++++++------ engine/src/flutter/libs/minikin/Layout.cpp | 8 ++++---- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/engine/src/flutter/include/minikin/CssParse.h b/engine/src/flutter/include/minikin/CssParse.h index ae2aac607ad..ea28b81ad9a 100644 --- a/engine/src/flutter/include/minikin/CssParse.h +++ b/engine/src/flutter/include/minikin/CssParse.h @@ -54,7 +54,7 @@ class CssValue { public: enum Type { UNKNOWN, - FLOAT, + DOUBLE, STRING }; enum Units { @@ -65,15 +65,16 @@ public: }; CssValue() : mType(UNKNOWN) { } explicit CssValue(double v) : - mType(FLOAT), floatValue(v), mUnits(SCALAR) { } + mType(DOUBLE), doubleValue(v), mUnits(SCALAR) { } Type getType() const { return mType; } - double getFloatValue() const { return floatValue; } - int32_t getIntValue() const { return floatValue; } + double getDoubleValue() const { return doubleValue; } + int32_t getIntValue() const { return doubleValue; } + uint32_t getUintValue() const { return doubleValue; } std::string getStringValue() const { return stringValue; } std::string toString(CssTag tag) const; - void setFloatValue(double v) { - mType = FLOAT; - floatValue = v; + void setDoubleValue(double v) { + mType = DOUBLE; + doubleValue = v; } void setStringValue(const std::string& v) { mType = STRING; @@ -81,7 +82,7 @@ public: } private: Type mType; - double floatValue; + double doubleValue; std::string stringValue; Units mUnits; }; diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 1f6894cb643..9ff08a95f09 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -33,7 +33,7 @@ struct MinikinPaint { float size; float scaleX; float skewX; - int32_t paintFlags; + uint32_t paintFlags; }; struct MinikinRect { diff --git a/engine/src/flutter/libs/minikin/CssParse.cpp b/engine/src/flutter/libs/minikin/CssParse.cpp index 147f3304bbb..8168a748d29 100644 --- a/engine/src/flutter/libs/minikin/CssParse.cpp +++ b/engine/src/flutter/libs/minikin/CssParse.cpp @@ -123,21 +123,21 @@ static bool parseValue(const string& str, size_t* off, size_t len, CssTag tag, C return false; } } - v->setFloatValue(fv); + v->setDoubleValue(fv); *off = endptr - data; return true; } string CssValue::toString(CssTag tag) const { - if (mType == FLOAT) { + if (mType == DOUBLE) { if (tag == fontStyle) { - return floatValue ? "italic" : "normal"; + return doubleValue ? "italic" : "normal"; } else if (tag == minikinVariant) { - if (floatValue == VARIANT_COMPACT) return "compact"; - if (floatValue == VARIANT_ELEGANT) return "elegant"; + if (doubleValue == VARIANT_COMPACT) return "compact"; + if (doubleValue == VARIANT_ELEGANT) return "elegant"; } char buf[64]; - sprintf(buf, "%g", floatValue); + sprintf(buf, "%g", doubleValue); return string(buf); } else if (mType == STRING) { return stringValue; // should probably quote diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 5471b38bdfe..c66559ac5bb 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -512,13 +512,13 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu ctx.props.parse(css); ctx.style = styleFromCss(ctx.props); - ctx.paint.size = ctx.props.value(fontSize).getFloatValue(); + ctx.paint.size = ctx.props.value(fontSize).getDoubleValue(); ctx.paint.scaleX = ctx.props.hasTag(fontScaleX) - ? ctx.props.value(fontScaleX).getFloatValue() : 1; + ? ctx.props.value(fontScaleX).getDoubleValue() : 1; ctx.paint.skewX = ctx.props.hasTag(fontSkewX) - ? ctx.props.value(fontSkewX).getFloatValue() : 0; + ? ctx.props.value(fontSkewX).getDoubleValue() : 0; ctx.paint.paintFlags = ctx.props.hasTag(paintFlags) - ?ctx.props.value(paintFlags).getIntValue() : 0; + ? ctx.props.value(paintFlags).getUintValue() : 0; int bidiFlags = ctx.props.hasTag(minikinBidi) ? ctx.props.value(minikinBidi).getIntValue() : 0; bool isRtl = (bidiFlags & kDirection_Mask) != 0; bool doSingleRun = true; From 06dec08ca290f24b4e85e6c2108371045602d4ff Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 4 Jun 2014 15:20:37 -0700 Subject: [PATCH 028/364] Support for context in API This patch completes support for adding context for complex script layout, for example when a string with joins straddles two spans. Part of the fix for 15431028: "Properly support context for joining scripts (Minikin)" Change-Id: I65b0833be92eb477aa531bbef0ac6eddeb3a962a --- engine/src/flutter/include/minikin/Layout.h | 2 +- engine/src/flutter/libs/minikin/Layout.cpp | 35 +++++++++------------ 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index a1ef0c13b8f..91b8ef6fd13 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -105,7 +105,7 @@ private: // Lay out a single bidi run void doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - bool isRtl, LayoutContext* ctx); + bool isRtl, LayoutContext* ctx, size_t dstStart); // Lay out a single word void doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_t bufSize, diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index c66559ac5bb..3cab6735774 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -485,17 +485,6 @@ void Layout::doLayout(const uint16_t* buf, size_t nchars) { doLayout(buf, 0, nchars, nchars, mCssString); } -// TODO: use some standard implementation -template -static T mymin(const T& a, const T& b) { - return a < b ? a : b; -} - -template -static T mymax(const T& a, const T& b) { - return a > b ? a : b; -} - static void clearHbFonts(LayoutContext* ctx) { for (size_t i = 0; i < ctx->hbFonts.size(); i++) { hb_font_destroy(ctx->hbFonts[i]); @@ -503,7 +492,6 @@ static void clearHbFonts(LayoutContext* ctx) { ctx->hbFonts.clear(); } -// TODO: API should probably take context void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, const string& css) { AutoMutex _l(gMinikinLock); @@ -560,9 +548,14 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu // skip the invalid run continue; } - isRtl = (runDir == UBIDI_RTL); - // TODO: min/max with context - doLayoutRunCached(buf, startRun, lengthRun, bufSize, isRtl, &ctx); + int32_t endRun = std::min(startRun + lengthRun, int32_t(start + count)); + startRun = std::max(startRun, int32_t(start)); + lengthRun = endRun - startRun; + if (lengthRun > 0) { + isRtl = (runDir == UBIDI_RTL); + doLayoutRunCached(buf, startRun, lengthRun, bufSize, isRtl, &ctx, + start); + } } } } else { @@ -574,22 +567,22 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu } } if (doSingleRun) { - doLayoutRunCached(buf, start, count, bufSize, isRtl, &ctx); + doLayoutRunCached(buf, start, count, bufSize, isRtl, &ctx, start); } clearHbFonts(&ctx); } void Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - bool isRtl, LayoutContext* ctx) { + bool isRtl, LayoutContext* ctx, size_t dstStart) { if (!isRtl) { // left to right size_t wordstart = start == bufSize ? start : getPrevWordBreak(buf, start + 1); size_t wordend; for (size_t iter = start; iter < start + count; iter = wordend) { wordend = getNextWordBreak(buf, iter, bufSize); - size_t wordcount = mymin(start + count, wordend) - iter; + size_t wordcount = std::min(start + count, wordend) - iter; doLayoutWord(buf + wordstart, iter - wordstart, wordcount, wordend - wordstart, - isRtl, ctx, iter); + isRtl, ctx, iter - dstStart); wordstart = wordend; } } else { @@ -599,9 +592,9 @@ void Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t wordend = end == 0 ? 0 : getNextWordBreak(buf, end - 1, bufSize); for (size_t iter = end; iter > start; iter = wordstart) { wordstart = getPrevWordBreak(buf, iter); - size_t bufStart = mymax(start, wordstart); + size_t bufStart = std::max(start, wordstart); doLayoutWord(buf + wordstart, bufStart - wordstart, iter - bufStart, - wordend - wordstart, isRtl, ctx, bufStart); + wordend - wordstart, isRtl, ctx, bufStart - dstStart); wordend = wordstart; } } From 13b22fd2434e3b7f5d707de20617812c5dbc2b5b Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 5 Jun 2014 22:40:15 -0700 Subject: [PATCH 029/364] Add baseFont method to FontCollection This patch adds a method to retrieve the base font from a FontCollection, which is useful when querying global font metrics. Part of the fix for bug 15467288 "Inconsistent line heights on Minikin builds" Change-Id: I268ae5128d0852a020d746bc22af81fc1a623228 --- engine/src/flutter/include/minikin/FontCollection.h | 3 +++ engine/src/flutter/libs/minikin/FontCollection.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 78ab2aae7b9..508a129a99f 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -57,6 +57,9 @@ public: void itemize(const uint16_t *string, size_t string_length, FontStyle style, std::vector* result) const; + // Get the base font for the given style, useful for font-wide metrics. + MinikinFont* baseFont(FontStyle style); + uint32_t getId() const; private: static const int kLogCharsPerPage = 8; diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 1713b476e0b..c13670e74a8 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -185,6 +185,14 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } } +MinikinFont* FontCollection::baseFont(FontStyle style) { + if (mInstances.empty()) { + return NULL; + } + return mInstances[0].mFamily->getClosestMatch(style); +} + + uint32_t FontCollection::getId() const { return mId; } From faadb4243eef234e41d8ab21a7e80a5794d76579 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Sat, 7 Jun 2014 08:14:07 -0700 Subject: [PATCH 030/364] Provisionally enable "palt" OpenType feature We want to test configurations where the Noto Japanese font will have its "palt" feature (to select tighter spacing in kana) will be enabled for framework but not WebView or Chrome rendering of Japanese text. This patch simply hardcodes this feature on. This is also a first step towards more general setting of OpenType features. The hardcoded feature list will grow into one set by parameters which will eventually be plumbed up to Java. Change-Id: Ie284e0487a1434155c8ac1cb68ddc4fc4b3c018a --- engine/src/flutter/libs/minikin/Layout.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 3cab6735774..2fdf853696d 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -618,6 +618,12 @@ void Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_ cache.mCache.put(key, value); } +static void addFeatures(vector* features) { + // hardcoded features, to be repaced with more flexible configuration + static hb_feature_t palt = { HB_TAG('p', 'a', 'l', 't'), 1, 0, ~0u }; + features->push_back(palt); +} + void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, bool isRtl, LayoutContext* ctx) { hb_buffer_t* buffer = LayoutEngine::getInstance().hbBuffer; @@ -627,6 +633,9 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t std::reverse(items.begin(), items.end()); } + vector features; + addFeatures(&features); + float x = mAdvance; float y = 0; for (size_t run_ix = 0; run_ix < items.size(); run_ix++) { @@ -663,7 +672,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t hb_buffer_set_language(buffer, hb_language_from_string(lang.c_str(), -1)); } hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart); - hb_shape(hbFont, buffer, NULL, 0); + hb_shape(hbFont, buffer, features.empty() ? NULL : &features[0], features.size()); unsigned int numGlyphs; hb_glyph_info_t* info = hb_buffer_get_glyph_infos(buffer, &numGlyphs); hb_glyph_position_t* positions = hb_buffer_get_glyph_positions(buffer, NULL); From 2b7da7bc2b8db79664cfe3855fe1c8d8b6f31f74 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 6 Jun 2014 17:56:41 -0700 Subject: [PATCH 031/364] Support for fake bold and italics This patch adds support for computing when fake bold and fake italics are needed (because the styles are requested but not provided by the matching FontFamily), and providing them as part of the layout result. Part of the fix for bug 15436379 Fake bold doesn't fully work (Minikin) Change-Id: I180c034b559837943673b5c272c8e890178dff0d --- .../flutter/include/minikin/FontCollection.h | 23 ++++--------------- .../src/flutter/include/minikin/FontFamily.h | 21 ++++++++++++++++- engine/src/flutter/include/minikin/Layout.h | 5 ++-- .../src/flutter/include/minikin/MinikinFont.h | 2 ++ .../flutter/libs/minikin/FontCollection.cpp | 15 ++++++------ .../src/flutter/libs/minikin/FontFamily.cpp | 21 ++++++++++++++--- engine/src/flutter/libs/minikin/Layout.cpp | 22 +++++++++++------- 7 files changed, 70 insertions(+), 39 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 508a129a99f..12700c6ebe2 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -32,24 +32,8 @@ public: ~FontCollection(); - class Run { - public: - // Do copy constructor, assignment, destructor so it can be used in vectors - Run() : font(NULL) { } - Run(const Run& other): font(other.font), start(other.start), end(other.end) { - if (font) font->RefLocked(); - } - Run& operator=(const Run& other) { - if (other.font) other.font->RefLocked(); - if (font) font->UnrefLocked(); - font = other.font; - start = other.start; - end = other.end; - return *this; - } - ~Run() { if (font) font->UnrefLocked(); } - - MinikinFont* font; + struct Run { + FakedFont fakedFont; int start; int end; }; @@ -60,6 +44,9 @@ public: // Get the base font for the given style, useful for font-wide metrics. MinikinFont* baseFont(FontStyle style); + // Get base font with fakery information (fake bold could affect metrics) + FakedFont baseFontFaked(FontStyle style); + uint32_t getId() const; private: static const int kLogCharsPerPage = 8; diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 6bdf5d6376d..060d1678c3d 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -94,6 +94,25 @@ inline hash_t hash_type(const FontStyle &style) { return style.hash(); } +// attributes representing transforms (fake bold, fake italic) to match styles +class FontFakery { +public: + FontFakery() : mFakeBold(false), mFakeItalic(false) { } + FontFakery(bool fakeBold, bool fakeItalic) : mFakeBold(fakeBold), mFakeItalic(fakeItalic) { } + // TODO: want to support graded fake bolding + bool isFakeBold() { return mFakeBold; } + bool isFakeItalic() { return mFakeItalic; } +private: + bool mFakeBold; + bool mFakeItalic; +}; + +struct FakedFont { + // ownership is the enclosing FontCollection + MinikinFont* font; + FontFakery fakery; +}; + class FontFamily : public MinikinRefCounted { public: FontFamily() { } @@ -107,7 +126,7 @@ public: bool addFont(MinikinFont* typeface); void addFont(MinikinFont* typeface, FontStyle style); - MinikinFont* getClosestMatch(FontStyle style) const; + FakedFont getClosestMatch(FontStyle style) const; FontLanguage lang() const { return mLang; } int variant() const { return mVariant; } diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 91b8ef6fd13..1b91ad87fe0 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -87,6 +87,7 @@ public: size_t nGlyphs() const; // Does not bump reference; ownership is still layout MinikinFont *getFont(int i) const; + FontFakery getFakery(int i) const; unsigned int getGlyphId(int i) const; float getX(int i) const; float getY(int i) const; @@ -101,7 +102,7 @@ public: private: // Find a face in the mFaces vector, or create a new entry - int findFace(MinikinFont* face, LayoutContext* ctx); + int findFace(FakedFont face, LayoutContext* ctx); // Lay out a single bidi run void doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, @@ -125,7 +126,7 @@ private: std::vector mAdvances; const FontCollection* mCollection; - std::vector mFaces; + std::vector mFaces; float mAdvance; MinikinRect mBounds; }; diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 9ff08a95f09..7915ef2e0a8 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -18,6 +18,7 @@ #define MINIKIN_FONT_H #include +#include // An abstraction for platform fonts, allowing Minikin to be used with // multiple actual implementations of fonts. @@ -34,6 +35,7 @@ struct MinikinPaint { float scaleX; float skewX; uint32_t paintFlags; + FontFakery fakery; }; struct MinikinRect { diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index c13670e74a8..6115ecc3b43 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -52,7 +52,7 @@ FontCollection::FontCollection(const vector& typefaces) : FontInstance* instance = &mInstances.back(); instance->mFamily = family; instance->mCoverage = new SparseBitSet; - MinikinFont* typeface = family->getClosestMatch(defaultStyle); + MinikinFont* typeface = family->getClosestMatch(defaultStyle).font; if (typeface == NULL) { ALOGE("FontCollection: closest match was null"); // TODO: we shouldn't hit this, as there should be more robust @@ -171,11 +171,9 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty result->push_back(dummy); run = &result->back(); if (instance == NULL) { - run->font = NULL; // maybe we should do something different here + run->fakedFont.font = NULL; } else { - run->font = instance->mFamily->getClosestMatch(style); - // TODO: simplify refcounting (FontCollection lifetime dominates) - run->font->RefLocked(); + run->fakedFont = instance->mFamily->getClosestMatch(style); } lastInstance = instance; run->start = i; @@ -186,13 +184,16 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } MinikinFont* FontCollection::baseFont(FontStyle style) { + return baseFontFaked(style).font; +} + +FakedFont FontCollection::baseFontFaked(FontStyle style) { if (mInstances.empty()) { - return NULL; + return FakedFont(); } return mInstances[0].mFamily->getClosestMatch(style); } - uint32_t FontCollection::getId() const { return mId; } diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 0fb98ae4e71..9106f63c3e9 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -109,7 +109,7 @@ void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { type } // Compute a matching metric between two styles - 0 is an exact match -int computeMatch(FontStyle style1, FontStyle style2) { +static int computeMatch(FontStyle style1, FontStyle style2) { if (style1 == style2) return 0; int score = abs(style1.getWeight() - style2.getWeight()); if (style1.getItalic() != style2.getItalic()) { @@ -118,7 +118,15 @@ int computeMatch(FontStyle style1, FontStyle style2) { return score; } -MinikinFont* FontFamily::getClosestMatch(FontStyle style) const { +static FontFakery computeFakery(FontStyle wanted, FontStyle actual) { + // If desired weight is 2 or more grades higher than actual + // (for example, medium 500 -> bold 700), then select fake bold. + bool isFakeBold = (wanted.getWeight() - actual.getWeight()) >= 2; + bool isFakeItalic = wanted.getItalic() && !actual.getItalic(); + return FontFakery(isFakeBold, isFakeItalic); +} + +FakedFont FontFamily::getClosestMatch(FontStyle style) const { const Font* bestFont = NULL; int bestMatch = 0; for (size_t i = 0; i < mFonts.size(); i++) { @@ -129,7 +137,14 @@ MinikinFont* FontFamily::getClosestMatch(FontStyle style) const { bestMatch = match; } } - return bestFont == NULL ? NULL : bestFont->typeface; + FakedFont result; + if (bestFont == NULL) { + result.font = NULL; + } else { + result.font = bestFont->typeface; + result.fakery = computeFakery(style, bestFont->style); + } + return result; } size_t FontFamily::getNumFonts() const { diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 3cab6735774..709393dc310 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -328,10 +328,10 @@ void Layout::dump() const { } } -int Layout::findFace(MinikinFont* face, LayoutContext* ctx) { +int Layout::findFace(FakedFont face, LayoutContext* ctx) { unsigned int ix; for (ix = 0; ix < mFaces.size(); ix++) { - if (mFaces[ix] == face) { + if (mFaces[ix].font == face.font) { return ix; } } @@ -339,7 +339,7 @@ int Layout::findFace(MinikinFont* face, LayoutContext* ctx) { // Note: ctx == NULL means we're copying from the cache, no need to create // corresponding hb_font object. if (ctx != NULL) { - hb_font_t* font = create_hb_font(face, &ctx->paint); + hb_font_t* font = create_hb_font(face.font, &ctx->paint); ctx->hbFonts.push_back(font); } return ix; @@ -631,12 +631,13 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t float y = 0; for (size_t run_ix = 0; run_ix < items.size(); run_ix++) { FontCollection::Run &run = items[run_ix]; - if (run.font == NULL) { + if (run.fakedFont.font == NULL) { ALOGE("no font for run starting u+%04x length %d", buf[run.start], run.end - run.start); continue; } - int font_ix = findFace(run.font, ctx); - ctx->paint.font = mFaces[font_ix]; + int font_ix = findFace(run.fakedFont, ctx); + ctx->paint.font = mFaces[font_ix].font; + ctx->paint.fakery = mFaces[font_ix].fakery; hb_font_t* hbFont = ctx->hbFonts[font_ix]; #ifdef VERBOSE std::cout << "Run " << run_ix << ", font " << font_ix << @@ -729,7 +730,7 @@ void Layout::draw(Bitmap* surface, int x0, int y0, float size) const { */ for (size_t i = 0; i < mGlyphs.size(); i++) { const LayoutGlyph& glyph = mGlyphs[i]; - MinikinFont* mf = mFaces[glyph.font_ix]; + MinikinFont* mf = mFaces[glyph.font_ix].font; MinikinFontFreeType* face = static_cast(mf); GlyphBitmap glyphBitmap; MinikinPaint paint; @@ -754,7 +755,12 @@ size_t Layout::nGlyphs() const { MinikinFont* Layout::getFont(int i) const { const LayoutGlyph& glyph = mGlyphs[i]; - return mFaces[glyph.font_ix]; + return mFaces[glyph.font_ix].font; +} + +FontFakery Layout::getFakery(int i) const { + const LayoutGlyph& glyph = mGlyphs[i]; + return mFaces[glyph.font_ix].fakery; } unsigned int Layout::getGlyphId(int i) const { From 1e35d09df19bbb9bef5c29673106975d96aeb74d Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 5 Jun 2014 22:40:15 -0700 Subject: [PATCH 032/364] Add baseFont method to FontCollection This patch adds a method to retrieve the base font from a FontCollection, which is useful when querying global font metrics. Part of the fix for bug 15467288 "Inconsistent line heights on Minikin builds" Change-Id: I268ae5128d0852a020d746bc22af81fc1a623228 --- engine/src/flutter/include/minikin/FontCollection.h | 3 +++ engine/src/flutter/libs/minikin/FontCollection.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 78ab2aae7b9..508a129a99f 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -57,6 +57,9 @@ public: void itemize(const uint16_t *string, size_t string_length, FontStyle style, std::vector* result) const; + // Get the base font for the given style, useful for font-wide metrics. + MinikinFont* baseFont(FontStyle style); + uint32_t getId() const; private: static const int kLogCharsPerPage = 8; diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 1713b476e0b..c13670e74a8 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -185,6 +185,14 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } } +MinikinFont* FontCollection::baseFont(FontStyle style) { + if (mInstances.empty()) { + return NULL; + } + return mInstances[0].mFamily->getClosestMatch(style); +} + + uint32_t FontCollection::getId() const { return mId; } From 1f8de3019ded454358e56a9f0f9b233e372acba8 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 6 Jun 2014 17:56:41 -0700 Subject: [PATCH 033/364] Support for fake bold and italics This patch adds support for computing when fake bold and fake italics are needed (because the styles are requested but not provided by the matching FontFamily), and providing them as part of the layout result. Part of the fix for bug 15436379 Fake bold doesn't fully work (Minikin) Change-Id: I180c034b559837943673b5c272c8e890178dff0d --- .../flutter/include/minikin/FontCollection.h | 23 ++++--------------- .../src/flutter/include/minikin/FontFamily.h | 21 ++++++++++++++++- engine/src/flutter/include/minikin/Layout.h | 5 ++-- .../src/flutter/include/minikin/MinikinFont.h | 2 ++ .../flutter/libs/minikin/FontCollection.cpp | 15 ++++++------ .../src/flutter/libs/minikin/FontFamily.cpp | 21 ++++++++++++++--- engine/src/flutter/libs/minikin/Layout.cpp | 22 +++++++++++------- 7 files changed, 70 insertions(+), 39 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 508a129a99f..12700c6ebe2 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -32,24 +32,8 @@ public: ~FontCollection(); - class Run { - public: - // Do copy constructor, assignment, destructor so it can be used in vectors - Run() : font(NULL) { } - Run(const Run& other): font(other.font), start(other.start), end(other.end) { - if (font) font->RefLocked(); - } - Run& operator=(const Run& other) { - if (other.font) other.font->RefLocked(); - if (font) font->UnrefLocked(); - font = other.font; - start = other.start; - end = other.end; - return *this; - } - ~Run() { if (font) font->UnrefLocked(); } - - MinikinFont* font; + struct Run { + FakedFont fakedFont; int start; int end; }; @@ -60,6 +44,9 @@ public: // Get the base font for the given style, useful for font-wide metrics. MinikinFont* baseFont(FontStyle style); + // Get base font with fakery information (fake bold could affect metrics) + FakedFont baseFontFaked(FontStyle style); + uint32_t getId() const; private: static const int kLogCharsPerPage = 8; diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 6bdf5d6376d..060d1678c3d 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -94,6 +94,25 @@ inline hash_t hash_type(const FontStyle &style) { return style.hash(); } +// attributes representing transforms (fake bold, fake italic) to match styles +class FontFakery { +public: + FontFakery() : mFakeBold(false), mFakeItalic(false) { } + FontFakery(bool fakeBold, bool fakeItalic) : mFakeBold(fakeBold), mFakeItalic(fakeItalic) { } + // TODO: want to support graded fake bolding + bool isFakeBold() { return mFakeBold; } + bool isFakeItalic() { return mFakeItalic; } +private: + bool mFakeBold; + bool mFakeItalic; +}; + +struct FakedFont { + // ownership is the enclosing FontCollection + MinikinFont* font; + FontFakery fakery; +}; + class FontFamily : public MinikinRefCounted { public: FontFamily() { } @@ -107,7 +126,7 @@ public: bool addFont(MinikinFont* typeface); void addFont(MinikinFont* typeface, FontStyle style); - MinikinFont* getClosestMatch(FontStyle style) const; + FakedFont getClosestMatch(FontStyle style) const; FontLanguage lang() const { return mLang; } int variant() const { return mVariant; } diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 91b8ef6fd13..1b91ad87fe0 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -87,6 +87,7 @@ public: size_t nGlyphs() const; // Does not bump reference; ownership is still layout MinikinFont *getFont(int i) const; + FontFakery getFakery(int i) const; unsigned int getGlyphId(int i) const; float getX(int i) const; float getY(int i) const; @@ -101,7 +102,7 @@ public: private: // Find a face in the mFaces vector, or create a new entry - int findFace(MinikinFont* face, LayoutContext* ctx); + int findFace(FakedFont face, LayoutContext* ctx); // Lay out a single bidi run void doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, @@ -125,7 +126,7 @@ private: std::vector mAdvances; const FontCollection* mCollection; - std::vector mFaces; + std::vector mFaces; float mAdvance; MinikinRect mBounds; }; diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 9ff08a95f09..7915ef2e0a8 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -18,6 +18,7 @@ #define MINIKIN_FONT_H #include +#include // An abstraction for platform fonts, allowing Minikin to be used with // multiple actual implementations of fonts. @@ -34,6 +35,7 @@ struct MinikinPaint { float scaleX; float skewX; uint32_t paintFlags; + FontFakery fakery; }; struct MinikinRect { diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index c13670e74a8..6115ecc3b43 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -52,7 +52,7 @@ FontCollection::FontCollection(const vector& typefaces) : FontInstance* instance = &mInstances.back(); instance->mFamily = family; instance->mCoverage = new SparseBitSet; - MinikinFont* typeface = family->getClosestMatch(defaultStyle); + MinikinFont* typeface = family->getClosestMatch(defaultStyle).font; if (typeface == NULL) { ALOGE("FontCollection: closest match was null"); // TODO: we shouldn't hit this, as there should be more robust @@ -171,11 +171,9 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty result->push_back(dummy); run = &result->back(); if (instance == NULL) { - run->font = NULL; // maybe we should do something different here + run->fakedFont.font = NULL; } else { - run->font = instance->mFamily->getClosestMatch(style); - // TODO: simplify refcounting (FontCollection lifetime dominates) - run->font->RefLocked(); + run->fakedFont = instance->mFamily->getClosestMatch(style); } lastInstance = instance; run->start = i; @@ -186,13 +184,16 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } MinikinFont* FontCollection::baseFont(FontStyle style) { + return baseFontFaked(style).font; +} + +FakedFont FontCollection::baseFontFaked(FontStyle style) { if (mInstances.empty()) { - return NULL; + return FakedFont(); } return mInstances[0].mFamily->getClosestMatch(style); } - uint32_t FontCollection::getId() const { return mId; } diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 0fb98ae4e71..9106f63c3e9 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -109,7 +109,7 @@ void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { type } // Compute a matching metric between two styles - 0 is an exact match -int computeMatch(FontStyle style1, FontStyle style2) { +static int computeMatch(FontStyle style1, FontStyle style2) { if (style1 == style2) return 0; int score = abs(style1.getWeight() - style2.getWeight()); if (style1.getItalic() != style2.getItalic()) { @@ -118,7 +118,15 @@ int computeMatch(FontStyle style1, FontStyle style2) { return score; } -MinikinFont* FontFamily::getClosestMatch(FontStyle style) const { +static FontFakery computeFakery(FontStyle wanted, FontStyle actual) { + // If desired weight is 2 or more grades higher than actual + // (for example, medium 500 -> bold 700), then select fake bold. + bool isFakeBold = (wanted.getWeight() - actual.getWeight()) >= 2; + bool isFakeItalic = wanted.getItalic() && !actual.getItalic(); + return FontFakery(isFakeBold, isFakeItalic); +} + +FakedFont FontFamily::getClosestMatch(FontStyle style) const { const Font* bestFont = NULL; int bestMatch = 0; for (size_t i = 0; i < mFonts.size(); i++) { @@ -129,7 +137,14 @@ MinikinFont* FontFamily::getClosestMatch(FontStyle style) const { bestMatch = match; } } - return bestFont == NULL ? NULL : bestFont->typeface; + FakedFont result; + if (bestFont == NULL) { + result.font = NULL; + } else { + result.font = bestFont->typeface; + result.fakery = computeFakery(style, bestFont->style); + } + return result; } size_t FontFamily::getNumFonts() const { diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 3cab6735774..709393dc310 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -328,10 +328,10 @@ void Layout::dump() const { } } -int Layout::findFace(MinikinFont* face, LayoutContext* ctx) { +int Layout::findFace(FakedFont face, LayoutContext* ctx) { unsigned int ix; for (ix = 0; ix < mFaces.size(); ix++) { - if (mFaces[ix] == face) { + if (mFaces[ix].font == face.font) { return ix; } } @@ -339,7 +339,7 @@ int Layout::findFace(MinikinFont* face, LayoutContext* ctx) { // Note: ctx == NULL means we're copying from the cache, no need to create // corresponding hb_font object. if (ctx != NULL) { - hb_font_t* font = create_hb_font(face, &ctx->paint); + hb_font_t* font = create_hb_font(face.font, &ctx->paint); ctx->hbFonts.push_back(font); } return ix; @@ -631,12 +631,13 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t float y = 0; for (size_t run_ix = 0; run_ix < items.size(); run_ix++) { FontCollection::Run &run = items[run_ix]; - if (run.font == NULL) { + if (run.fakedFont.font == NULL) { ALOGE("no font for run starting u+%04x length %d", buf[run.start], run.end - run.start); continue; } - int font_ix = findFace(run.font, ctx); - ctx->paint.font = mFaces[font_ix]; + int font_ix = findFace(run.fakedFont, ctx); + ctx->paint.font = mFaces[font_ix].font; + ctx->paint.fakery = mFaces[font_ix].fakery; hb_font_t* hbFont = ctx->hbFonts[font_ix]; #ifdef VERBOSE std::cout << "Run " << run_ix << ", font " << font_ix << @@ -729,7 +730,7 @@ void Layout::draw(Bitmap* surface, int x0, int y0, float size) const { */ for (size_t i = 0; i < mGlyphs.size(); i++) { const LayoutGlyph& glyph = mGlyphs[i]; - MinikinFont* mf = mFaces[glyph.font_ix]; + MinikinFont* mf = mFaces[glyph.font_ix].font; MinikinFontFreeType* face = static_cast(mf); GlyphBitmap glyphBitmap; MinikinPaint paint; @@ -754,7 +755,12 @@ size_t Layout::nGlyphs() const { MinikinFont* Layout::getFont(int i) const { const LayoutGlyph& glyph = mGlyphs[i]; - return mFaces[glyph.font_ix]; + return mFaces[glyph.font_ix].font; +} + +FontFakery Layout::getFakery(int i) const { + const LayoutGlyph& glyph = mGlyphs[i]; + return mFaces[glyph.font_ix].fakery; } unsigned int Layout::getGlyphId(int i) const { From 43e8943dfd9812fdf1f62e05f61ef85a2a0868f6 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 11 Jun 2014 15:02:11 -0700 Subject: [PATCH 034/364] Fix missing text on nonexistent font file Fix for bug 15570313 "Missing text on nonexistent font file" This patch makes sure that the lastChar and mInstances arrays are in sync with each other even when a FontFamily being added has no valid fonts in it. Previously, when they got out of sync, unicode coverage calculation would be wrong, resulting in missing text. Change-Id: I69c727ef69e2c61e2b2d6b81d5a28c806327f865 --- engine/src/flutter/libs/minikin/FontCollection.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 6115ecc3b43..45e5d060325 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -46,12 +46,6 @@ FontCollection::FontCollection(const vector& typefaces) : const FontStyle defaultStyle; for (size_t i = 0; i < nTypefaces; i++) { FontFamily* family = typefaces[i]; - family->RefLocked(); - FontInstance dummy; - mInstances.push_back(dummy); // emplace_back would be better - FontInstance* instance = &mInstances.back(); - instance->mFamily = family; - instance->mCoverage = new SparseBitSet; MinikinFont* typeface = family->getClosestMatch(defaultStyle).font; if (typeface == NULL) { ALOGE("FontCollection: closest match was null"); @@ -59,6 +53,12 @@ FontCollection::FontCollection(const vector& typefaces) : // checks upstream to prevent empty/invalid FontFamily objects continue; } + family->RefLocked(); + FontInstance dummy; + mInstances.push_back(dummy); // emplace_back would be better + FontInstance* instance = &mInstances.back(); + instance->mFamily = family; + instance->mCoverage = new SparseBitSet; #ifdef VERBOSE_DEBUG ALOGD("closest match = %p, family size = %d\n", typeface, family->getNumFonts()); #endif @@ -75,6 +75,7 @@ FontCollection::FontCollection(const vector& typefaces) : mMaxChar = max(mMaxChar, instance->mCoverage->length()); lastChar.push_back(instance->mCoverage->nextSetBit(0)); } + nTypefaces = mInstances.size(); size_t nPages = (mMaxChar + kPageMask) >> kLogCharsPerPage; size_t offset = 0; for (size_t i = 0; i < nPages; i++) { From 0f8e4702a5aa8c43f3efa3643680dca9f45a1edd Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 12 Jun 2014 09:19:03 -0700 Subject: [PATCH 035/364] Tighten requirements for fake bold The simple predicate for fake bold (2 or more grades darker than requested) was applying it to thin (100 weight) when normal was requested. This patch tightens the predicate to also require that the requested weight be in the bold range. Fix for bug 15588352 "sans-serif-thin doesn't work on lockscreen" Change-Id: Id9988bd149a9c8a7c943e3b221f7fb4b37fb6ddb --- engine/src/flutter/libs/minikin/FontFamily.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 9106f63c3e9..ad8120f752a 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -119,9 +119,11 @@ static int computeMatch(FontStyle style1, FontStyle style2) { } static FontFakery computeFakery(FontStyle wanted, FontStyle actual) { - // If desired weight is 2 or more grades higher than actual - // (for example, medium 500 -> bold 700), then select fake bold. - bool isFakeBold = (wanted.getWeight() - actual.getWeight()) >= 2; + // If desired weight is bold or darker, and 2 or more grades higher + // than actual (for example, medium 500 -> bold 700), then select + // fake bold. + int wantedWeight = wanted.getWeight(); + bool isFakeBold = wantedWeight >= 7 && (wantedWeight - actual.getWeight()) >= 2; bool isFakeItalic = wanted.getItalic() && !actual.getItalic(); return FontFakery(isFakeBold, isFakeItalic); } From e88f8c37c740a317f11d407d48aaacdfdad56395 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 12 Jun 2014 09:19:03 -0700 Subject: [PATCH 036/364] Tighten requirements for fake bold The simple predicate for fake bold (2 or more grades darker than requested) was applying it to thin (100 weight) when normal was requested. This patch tightens the predicate to also require that the requested weight be in the bold range. Fix for bug 15588352 "sans-serif-thin doesn't work on lockscreen" Change-Id: Id9988bd149a9c8a7c943e3b221f7fb4b37fb6ddb (cherry picked from commit 0f8e4702a5aa8c43f3efa3643680dca9f45a1edd) --- engine/src/flutter/libs/minikin/FontFamily.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 9106f63c3e9..ad8120f752a 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -119,9 +119,11 @@ static int computeMatch(FontStyle style1, FontStyle style2) { } static FontFakery computeFakery(FontStyle wanted, FontStyle actual) { - // If desired weight is 2 or more grades higher than actual - // (for example, medium 500 -> bold 700), then select fake bold. - bool isFakeBold = (wanted.getWeight() - actual.getWeight()) >= 2; + // If desired weight is bold or darker, and 2 or more grades higher + // than actual (for example, medium 500 -> bold 700), then select + // fake bold. + int wantedWeight = wanted.getWeight(); + bool isFakeBold = wantedWeight >= 7 && (wantedWeight - actual.getWeight()) >= 2; bool isFakeItalic = wanted.getItalic() && !actual.getItalic(); return FontFakery(isFakeBold, isFakeItalic); } From ba5dbb6f240993b6dd957d7ecfe9a6f984665c9a Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 19 Jun 2014 01:51:47 -0700 Subject: [PATCH 037/364] Make font runs less sticky Fixes b/15734816 In the text "Wi-Fi", "-Fi" appears bolder than "Wi" The problem was caused by "stickiness" in choosing fonts, where layout would prefer using a font used for preceding characters as long as it mapped the following characters in a run, in favor of the "best match" rules. This patch adds a whitelist for making the stickiness more conservative, only applying it for characters necessary for correct shaping (ZWJ and ZWNJ in particular) and basic punctuation, where it is desirable to match the style of the preceding text. Change-Id: I1cf116879f074a5a71c351846707bfdd07b0d320 --- .../flutter/libs/minikin/FontCollection.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 45e5d060325..348c5dc2739 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -147,6 +147,20 @@ const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t return bestInstance; } +const uint32_t NBSP = 0xa0; +const uint32_t ZWJ = 0x200c; +const uint32_t ZWNJ = 0x200d; +// Characters where we want to continue using existing font run instead of +// recomputing the best match in the fallback list. +static const uint32_t stickyWhitelist[] = { '!', ',', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ }; + +static bool isStickyWhitelisted(uint32_t c) { + for (size_t i = 0; i < sizeof(stickyWhitelist) / sizeof(stickyWhitelist[0]); i++) { + if (stickyWhitelist[i] == c) return true; + } + return false; +} + void FontCollection::itemize(const uint16_t *string, size_t string_size, FontStyle style, vector* result) const { FontLanguage lang = style.getLanguage(); @@ -164,8 +178,9 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty nShorts = 2; } } - // Continue using existing font as long as it has coverage. - if (lastInstance == NULL || !lastInstance->mCoverage->get(ch)) { + // Continue using existing font as long as it has coverage and is whitelisted + if (lastInstance == NULL + || !(isStickyWhitelisted(ch) && lastInstance->mCoverage->get(ch))) { const FontInstance* instance = getInstanceForChar(ch, lang, variant); if (i == 0 || instance != lastInstance) { Run dummy; From e8bed5d3cc78d61cbbdf63b6439cee68613a908b Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Sun, 15 Jun 2014 17:33:29 -0700 Subject: [PATCH 038/364] Implement grapheme cluster breaking This patch includes an implementation of grapheme cluster breaking, which is especially useful for repositioning the cursor for left and right arrow key presses. The implementation is closely based on Unicode TR29, and uses the ICU grapheme cluster break property, but is tailored to more closely match the existing implementation and expected behavior. Part of a fix for b/15653110 Improve behavior of arrow keys in EditText Change-Id: I8eb742f77039c9ab7b2838285018cf8a8fc88343 --- .../flutter/include/minikin/GraphemeBreak.h | 47 +++++++ engine/src/flutter/libs/minikin/Android.mk | 1 + .../flutter/libs/minikin/GraphemeBreak.cpp | 132 ++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 engine/src/flutter/include/minikin/GraphemeBreak.h create mode 100644 engine/src/flutter/libs/minikin/GraphemeBreak.cpp diff --git a/engine/src/flutter/include/minikin/GraphemeBreak.h b/engine/src/flutter/include/minikin/GraphemeBreak.h new file mode 100644 index 00000000000..31201015855 --- /dev/null +++ b/engine/src/flutter/include/minikin/GraphemeBreak.h @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2014 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_GRAPHEME_BREAK_H +#define MINIKIN_GRAPHEME_BREAK_H + +namespace android { + +class GraphemeBreak { +public: + // These values must be kept in sync with CURSOR_AFTER etc in Paint.java + enum MoveOpt { + AFTER = 0, + AT_OR_AFTER = 1, + BEFORE = 2, + AT_OR_BEFORE = 3, + AT = 4 + }; + + // Determine whether the given offset is a grapheme break. + // This implementation generally follows Unicode TR29 extended + // grapheme break, but with some tweaks to more closely match + // existing implementations. + static bool isGraphemeBreak(const uint16_t* buf, size_t start, size_t count, size_t offset); + + // Matches Android's Java API. Note, return (size_t)-1 for AT to + // signal non-break because unsigned return type. + static size_t getTextRunCursor(const uint16_t* buf, size_t start, size_t count, + size_t offset, MoveOpt opt); +}; + +} // namespace android + +#endif // MINIKIN_GRAPHEME_BREAK_H \ No newline at end of file diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index a1d88c29e55..fd949c2a90f 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -23,6 +23,7 @@ LOCAL_SRC_FILES := \ CssParse.cpp \ FontCollection.cpp \ FontFamily.cpp \ + GraphemeBreak.cpp \ Layout.cpp \ MinikinInternal.cpp \ MinikinRefCounted.cpp \ diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp new file mode 100644 index 00000000000..5d8978d66f1 --- /dev/null +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2014 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 +#include +#include + +#include + +namespace android { + +bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t count, + size_t offset) { + // This implementation closely follows Unicode Standard Annex #29 on + // Unicode Text Segmentation (http://www.unicode.org/reports/tr29/), + // implementing a tailored version of extended grapheme clusters. + // The GB rules refer to section 3.1.1, Grapheme Cluster Boundary Rules. + + // Rule GB1, sot /; Rule GB2, / eot + if (offset <= start || offset >= start + count) { + return true; + } + if (U16_IS_TRAIL(buf[offset])) { + // Don't break a surrogate pair + return false; + } + uint32_t c1 = 0; + uint32_t c2 = 0; + size_t offset_back = offset; + U16_PREV(buf, start, offset_back, c1); + U16_NEXT(buf, offset, count, c2); + int32_t p1 = u_getIntPropertyValue(c1, UCHAR_GRAPHEME_CLUSTER_BREAK); + int32_t p2 = u_getIntPropertyValue(c2, UCHAR_GRAPHEME_CLUSTER_BREAK); + // Rule GB3, CR x LF + if (p1 == U_GCB_CR && p2 == U_GCB_LF) { + return false; + } + // Rule GB4, (Control | CR | LF) / + if (p1 == U_GCB_CONTROL || p1 == U_GCB_CR || p1 == U_GCB_LF) { + return true; + } + // Rule GB5, / (Control | CR | LF) + if (p2 == U_GCB_CONTROL || p2 == U_GCB_CR || p2 == U_GCB_LF) { + // exclude zero-width control characters from breaking (tailoring of TR29) + if (c2 == 0x00ad + || (c2 >= 0x200b && c2 <= 0x200f) + || (c2 >= 0x2028 && c2 <= 0x202e) + || (c2 >= 0x2060 && c2 <= 0x206f)) { + return false; + } + return true; + } + // Rule GB6, L x ( L | V | LV | LVT ) + if (p1 == U_GCB_L && (p2 == U_GCB_L || p2 == U_GCB_V || p2 == U_GCB_LV || p2 == U_GCB_LVT)) { + return false; + } + // Rule GB7, ( LV | V ) x ( V | T ) + if ((p1 == U_GCB_LV || p1 == U_GCB_V) && (p2 == U_GCB_V || p2 == U_GCB_T)) { + return false; + } + // Rule GB8, ( LVT | T ) x T + if ((p1 == U_GCB_L || p1 == U_GCB_T) && p2 == U_GCB_T) { + return false; + } + // Rule GB8a, Regional_Indicator x Regional_Indicator + if (p1 == U_GCB_REGIONAL_INDICATOR && p2 == U_GCB_REGIONAL_INDICATOR) { + return false; + } + // Rule GB9, x Extend; Rule GB9a, x SpacingMark + if (p2 == U_GCB_EXTEND || p2 == U_GCB_SPACING_MARK) { + if (c2 == 0xe33) { + // most other implementations break THAI CHARACTER SARA AM + // (tailoring of TR29) + return true; + } + return false; + } + // Cluster indic syllables togeter (tailoring of TR29) + if (u_getIntPropertyValue(c1, UCHAR_CANONICAL_COMBINING_CLASS) == 9 // virama + && u_getIntPropertyValue(c2, UCHAR_GENERAL_CATEGORY) == U_OTHER_LETTER) { + return false; + } + // Rule GB10, Any / Any + return true; +} + +size_t GraphemeBreak::getTextRunCursor(const uint16_t* buf, size_t start, size_t count, + size_t offset, MoveOpt opt) { + switch (opt) { + case AFTER: + if (offset < start + count) { + offset++; + } + // fall through + case AT_OR_AFTER: + while (!isGraphemeBreak(buf, start, count, offset)) { + offset++; + } + break; + case BEFORE: + if (offset > start) { + offset--; + } + // fall through + case AT_OR_BEFORE: + while (!isGraphemeBreak(buf, start, count, offset)) { + offset--; + } + break; + case AT: + if (!isGraphemeBreak(buf, start, count, offset)) { + offset = (size_t)-1; + } + break; + } + return offset; +} + +} // namespace android From 69f3585cf6f6ceac263e10b4d06bb0eb05a5ddbc Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 25 Jun 2014 15:58:24 -0700 Subject: [PATCH 039/364] Add purgeCaches() method Expose a method to purge caches used for TextLayout, useful for low memory conditions. Change-Id: I92f41afe987b7be4af5ca0a0c50fb51be35a2758 --- engine/src/flutter/include/minikin/Layout.h | 3 +++ engine/src/flutter/libs/minikin/Layout.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 1b91ad87fe0..e30f2f24968 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -100,6 +100,9 @@ public: void getBounds(MinikinRect* rect); + // Purge all caches, useful in low memory conditions + static void purgeCaches(); + private: // Find a face in the mFaces vector, or create a new entry int findFace(FakedFont face, LayoutContext* ctx); diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 762a7dbbfa0..48db129cf77 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -799,4 +799,12 @@ void Layout::getBounds(MinikinRect* bounds) { bounds->set(mBounds); } +void Layout::purgeCaches() { + AutoMutex _l(gMinikinLock); + LayoutCache& layoutCache = LayoutEngine::getInstance().layoutCache; + layoutCache.mCache.clear(); + HbFaceCache& hbCache = LayoutEngine::getInstance().hbFaceCache; + hbCache.mCache.clear(); +} + } // namespace android From 05d59ee4621458fc2e9d6ce227e1ae39bd101d3b Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 26 Jun 2014 14:00:43 -0700 Subject: [PATCH 040/364] Disable "palt" OpenType feature Proper Japanese layout requires sophisticated rules for spacing punctuation, not just turning on the "palt" (proportional alternate) feature. Until we can support the whole set, roll back palt. Change-Id: If2359c529b70b1dd45dddc00e5f4aa1c91f8b0e9 --- engine/src/flutter/libs/minikin/Layout.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 48db129cf77..01b6599628f 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -621,7 +621,13 @@ void Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_ static void addFeatures(vector* features) { // hardcoded features, to be repaced with more flexible configuration static hb_feature_t palt = { HB_TAG('p', 'a', 'l', 't'), 1, 0, ~0u }; + + // Don't enable "palt" for now, pending implementation of more of the + // W3C Japanese layout recommendations. See: + // http://www.w3.org/TR/2012/NOTE-jlreq-20120403/ +#if 0 features->push_back(palt); +#endif } void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, From f9490880cc5f4363360ec02b8e818d245346b97f Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Mon, 7 Jul 2014 10:59:40 -0400 Subject: [PATCH 041/364] setConfig is deprecated Change-Id: Iffad3ef724b565d5d8fed17722630fd74cda9234 --- engine/src/flutter/sample/example_skia.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/sample/example_skia.cpp b/engine/src/flutter/sample/example_skia.cpp index e686621c345..1a6aa2362f0 100644 --- a/engine/src/flutter/sample/example_skia.cpp +++ b/engine/src/flutter/sample/example_skia.cpp @@ -125,11 +125,10 @@ int runMinikinTest() { SkAutoGraphics ag; - SkScalar width = 800; - SkScalar height = 600; + int width = 800; + int height = 600; SkBitmap bitmap; - bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); - bitmap.allocPixels(); + bitmap.allocN32Pixels(width, height); SkCanvas canvas(bitmap); SkPaint paint; paint.setARGB(255, 0, 0, 128); From 293208bda839a5726e294a22c85b1c9e1c4b9844 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 7 Jul 2014 14:59:04 -0700 Subject: [PATCH 042/364] Assign non-coverage font runs to base font When a run has no cmap coverage in any font, use the base font. Most of the time, this will cause rendering of the .notdef glyph, which is preferable to displaying nothing. In some cases, Harfbuzz may be able to decompose the characters (not in the cmap) to ones that are, in which case we'll render those, as long as they're in the base font. Bug: 6629748 Bug: 15816880 Change-Id: Ibb1b9242c83626e0c7db363ad65ce44a967a005e --- engine/src/flutter/libs/minikin/FontCollection.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 348c5dc2739..a6977fd6c6c 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -48,9 +48,6 @@ FontCollection::FontCollection(const vector& typefaces) : FontFamily* family = typefaces[i]; MinikinFont* typeface = family->getClosestMatch(defaultStyle).font; if (typeface == NULL) { - ALOGE("FontCollection: closest match was null"); - // TODO: we shouldn't hit this, as there should be more robust - // checks upstream to prevent empty/invalid FontFamily objects continue; } family->RefLocked(); @@ -76,6 +73,8 @@ FontCollection::FontCollection(const vector& typefaces) : lastChar.push_back(instance->mCoverage->nextSetBit(0)); } nTypefaces = mInstances.size(); + LOG_ALWAYS_FATAL_IF(nTypefaces == 0, + "Font collection must have at least one valid typeface"); size_t nPages = (mMaxChar + kPageMask) >> kLogCharsPerPage; size_t offset = 0; for (size_t i = 0; i < nPages; i++) { @@ -144,6 +143,9 @@ const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t } } } + if (bestInstance == NULL) { + bestInstance = &mInstances[0]; + } return bestInstance; } From b6138e6653b4fd735044b9e27496d4cb7a273900 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 10 Jul 2014 10:39:07 -0700 Subject: [PATCH 043/364] Switch minikin to the new icu. Change-Id: I29a59edfe6102257c9f308aac1b4348ef7a18db7 --- engine/src/flutter/libs/minikin/Android.mk | 2 +- engine/src/flutter/sample/Android.mk | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index fd949c2a90f..fde2cbbbf4d 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -35,7 +35,7 @@ LOCAL_MODULE := libminikin LOCAL_C_INCLUDES += \ external/harfbuzz_ng/src \ external/freetype/include \ - external/icu4c/common \ + external/icu/icu4c/source/common \ frameworks/minikin/include LOCAL_SHARED_LIBRARIES := \ diff --git a/engine/src/flutter/sample/Android.mk b/engine/src/flutter/sample/Android.mk index a19019ad829..ec06e3852ae 100644 --- a/engine/src/flutter/sample/Android.mk +++ b/engine/src/flutter/sample/Android.mk @@ -22,7 +22,7 @@ LOCAL_MODULE_TAGS := tests LOCAL_C_INCLUDES += \ external/harfbuzz_ng/src \ external/freetype/include \ - external/icu4c/common \ + external/icu/icu4c/source/common \ frameworks/minikin/include LOCAL_SRC_FILES:= example.cpp @@ -52,7 +52,7 @@ LOCAL_MODULE_TAG := tests LOCAL_C_INCLUDES += \ external/harfbuzz_ng/src \ external/freetype/include \ - external/icu4c/common \ + external/icu/icu4c/source/common \ frameworks/minikin/include \ external/skia/src/core From da0c3511e311a406e2c804f498449afc098a2a98 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 10 Jul 2014 17:48:37 -0400 Subject: [PATCH 044/364] Use __builtin_clzl if element is long Change-Id: I50a112739847fa826088854f6d172a188ff4cfb3 --- engine/src/flutter/libs/minikin/SparseBitSet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/SparseBitSet.cpp b/engine/src/flutter/libs/minikin/SparseBitSet.cpp index e0b3c1d5a7e..7acb7ba345b 100644 --- a/engine/src/flutter/libs/minikin/SparseBitSet.cpp +++ b/engine/src/flutter/libs/minikin/SparseBitSet.cpp @@ -105,9 +105,9 @@ void SparseBitSet::initFromRanges(const uint32_t* ranges, size_t nRanges) { } } -// Note: this implementation depends on GCC builtin, and also assumes 32-bit elements. int SparseBitSet::CountLeadingZeros(element x) { - return __builtin_clz(x); + // Note: GCC / clang builtin + return sizeof(element) <= sizeof(int) ? __builtin_clz(x) : __builtin_clzl(x); } uint32_t SparseBitSet::nextSetBit(uint32_t fromIndex) const { From 29eb45e667be81d37f29fcce2adccb8c5e6d5ada Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 11 Jul 2014 11:30:06 -0400 Subject: [PATCH 045/364] Don't pass invalid Unicode codepoint to Skia Bug: 15849380 Change-Id: Ib5285e57c5806bd399600fadd56e8bc809da323f --- engine/src/flutter/libs/minikin/Layout.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 01b6599628f..21b83622603 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -258,6 +258,12 @@ static hb_bool_t harfbuzzGetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoin MinikinPaint* paint = reinterpret_cast(fontData); MinikinFont* font = paint->font; uint32_t glyph_id; + /* HarfBuzz replaces broken input codepoints with (unsigned int) -1. + * Skia expects valid Unicode. + * Replace invalid codepoints with U+FFFD REPLACEMENT CHARACTER. + */ + if (unicode > 0x10FFFF) + unicode = 0xFFFD; bool ok = font->GetGlyph(unicode, &glyph_id); if (ok) { *glyph = glyph_id; From 7043f8f1fc2476e5b9bf076fe434cd5f1283a5db Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 17 Jul 2014 19:47:01 -0400 Subject: [PATCH 046/364] Add letter-spacing support Bug: 15594400 Change-Id: Ied94d7674be4097b0f44c9b0770d3294dc6433c1 --- engine/src/flutter/include/minikin/CssParse.h | 2 + .../src/flutter/include/minikin/MinikinFont.h | 1 + engine/src/flutter/libs/minikin/CssParse.cpp | 1 + engine/src/flutter/libs/minikin/Layout.cpp | 45 +++++++++++++++++-- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/include/minikin/CssParse.h b/engine/src/flutter/include/minikin/CssParse.h index ea28b81ad9a..259b933a54a 100644 --- a/engine/src/flutter/include/minikin/CssParse.h +++ b/engine/src/flutter/include/minikin/CssParse.h @@ -30,6 +30,7 @@ enum CssTag { fontStyle, fontWeight, cssLang, + letterSpacing, minikinBidi, minikinHinting, minikinVariant, @@ -44,6 +45,7 @@ const std::string cssTagNames[] = { "font-style", "font-weight", "lang", + "letter-spacing", "-minikin-bidi", "-minikin-hinting", "-minikin-variant", diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 7915ef2e0a8..935d4bb0b38 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -34,6 +34,7 @@ struct MinikinPaint { float size; float scaleX; float skewX; + float letterSpacing; uint32_t paintFlags; FontFakery fakery; }; diff --git a/engine/src/flutter/libs/minikin/CssParse.cpp b/engine/src/flutter/libs/minikin/CssParse.cpp index 8168a748d29..057dab7e82f 100644 --- a/engine/src/flutter/libs/minikin/CssParse.cpp +++ b/engine/src/flutter/libs/minikin/CssParse.cpp @@ -44,6 +44,7 @@ static CssTag parseTag(const string str, size_t off, size_t len) { if (strEqC(str, off, len, "font-style")) return fontStyle; } else if (c == 'l') { if (strEqC(str, off, len, "lang")) return cssLang; + if (strEqC(str, off, len, "letter-spacing")) return letterSpacing; } else if (c == '-') { if (strEqC(str, off, len, "-minikin-bidi")) return minikinBidi; if (strEqC(str, off, len, "-minikin-hinting")) return minikinHinting; diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 21b83622603..5125a32f9bc 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -64,6 +64,7 @@ public: const uint16_t* chars, size_t start, size_t count, size_t nchars, bool dir) : mStart(start), mCount(count), mId(collection->getId()), mStyle(style), mSize(paint.size), mScaleX(paint.scaleX), mSkewX(paint.skewX), + mLetterSpacing(paint.letterSpacing), mPaintFlags(paint.paintFlags), mIsRtl(dir) { mText.setTo(chars, nchars); } @@ -81,6 +82,7 @@ private: float mSize; float mScaleX; float mSkewX; + float mLetterSpacing; int32_t mPaintFlags; bool mIsRtl; // Note: any fields added to MinikinPaint must also be reflected here. @@ -144,6 +146,7 @@ bool LayoutCacheKey::operator==(const LayoutCacheKey& other) const { && mSize == other.mSize && mScaleX == other.mScaleX && mSkewX == other.mSkewX + && mLetterSpacing == other.mLetterSpacing && mPaintFlags == other.mPaintFlags && mIsRtl == other.mIsRtl && mText == other.mText; @@ -157,6 +160,7 @@ hash_t LayoutCacheKey::hash() const { hash = JenkinsHashMix(hash, hash_type(mSize)); hash = JenkinsHashMix(hash, hash_type(mScaleX)); hash = JenkinsHashMix(hash, hash_type(mSkewX)); + hash = JenkinsHashMix(hash, hash_type(mLetterSpacing)); hash = JenkinsHashMix(hash, hash_type(mPaintFlags)); hash = JenkinsHashMix(hash, hash_type(mIsRtl)); hash = JenkinsHashMixShorts(hash, mText.string(), mText.size()); @@ -511,6 +515,8 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu ? ctx.props.value(fontScaleX).getDoubleValue() : 1; ctx.paint.skewX = ctx.props.hasTag(fontSkewX) ? ctx.props.value(fontSkewX).getDoubleValue() : 0; + ctx.paint.letterSpacing = ctx.props.hasTag(letterSpacing) + ? ctx.props.value(letterSpacing).getDoubleValue() : 0; ctx.paint.paintFlags = ctx.props.hasTag(paintFlags) ? ctx.props.value(paintFlags).getUintValue() : 0; int bidiFlags = ctx.props.hasTag(minikinBidi) ? ctx.props.value(minikinBidi).getIntValue() : 0; @@ -646,8 +652,25 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t } vector features; + // Disable default-on non-required ligature features if letter-spacing + // See http://dev.w3.org/csswg/css-text-3/#letter-spacing-property + // "When the effective spacing between two characters is not zero (due to + // either justification or a non-zero value of letter-spacing), user agents + // should not apply optional ligatures." + if (fabs(ctx->paint.letterSpacing) > 0.03) + { + static const hb_feature_t no_liga = { HB_TAG('l', 'i', 'g', 'a'), 0, 0, ~0u }; + static const hb_feature_t no_clig = { HB_TAG('c', 'l', 'i', 'g'), 0, 0, ~0u }; + features.push_back(no_liga); + features.push_back(no_clig); + } addFeatures(&features); + double size = ctx->paint.size; + double scaleX = ctx->paint.scaleX; + double letterSpace = ctx->paint.letterSpacing * size * scaleX; + double letterSpaceHalf = letterSpace * .5; + float x = mAdvance; float y = 0; for (size_t run_ix = 0; run_ix < items.size(); run_ix++) { @@ -664,8 +687,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t std::cout << "Run " << run_ix << ", font " << font_ix << " [" << run.start << ":" << run.end << "]" << std::endl; #endif - double size = ctx->paint.size; - double scaleX = ctx->paint.scaleX; + hb_font_set_ppem(hbFont, size * scaleX, size); hb_font_set_scale(hbFont, HBFloatToFixed(size * scaleX), HBFloatToFixed(size)); @@ -689,11 +711,22 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t unsigned int numGlyphs; hb_glyph_info_t* info = hb_buffer_get_glyph_infos(buffer, &numGlyphs); hb_glyph_position_t* positions = hb_buffer_get_glyph_positions(buffer, NULL); + if (numGlyphs) + { + mAdvances[info[0].cluster - start] += letterSpaceHalf; + x += letterSpaceHalf; + } for (unsigned int i = 0; i < numGlyphs; i++) { #ifdef VERBOSE std::cout << positions[i].x_advance << " " << positions[i].y_advance << " " << positions[i].x_offset << " " << positions[i].y_offset << std::endl; std::cout << "DoLayout " << info[i].codepoint << ": " << HBFixedToFloat(positions[i].x_advance) << "; " << positions[i].x_offset << ", " << positions[i].y_offset << std::endl; #endif + if (i > 0 && info[i - 1].cluster != info[i].cluster) { + mAdvances[info[i - 1].cluster - start] += letterSpaceHalf; + mAdvances[info[i].cluster - start] += letterSpaceHalf; + x += letterSpaceHalf; + } + hb_codepoint_t glyph_ix = info[i].codepoint; float xoff = HBFixedToFloat(positions[i].x_offset); float yoff = -HBFixedToFloat(positions[i].y_offset); @@ -705,10 +738,14 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t ctx->paint.font->GetBounds(&glyphBounds, glyph_ix, ctx->paint); glyphBounds.offset(x + xoff, y + yoff); mBounds.join(glyphBounds); - size_t cluster = info[i].cluster - start; - mAdvances[cluster] += xAdvance; + mAdvances[info[i].cluster - start] += xAdvance; x += xAdvance; } + if (numGlyphs) + { + mAdvances[info[numGlyphs - 1].cluster - start] += letterSpaceHalf; + x += letterSpaceHalf; + } } } mAdvance = x; From ca5b3e16760ba111efbe43324801dc2b1a74e115 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 25 Jul 2014 17:31:46 +0000 Subject: [PATCH 047/364] Revert "Don't pass invalid Unicode codepoint to Skia" After update to HarfBuzz 0.9.33 we don't need this anymore. HarfBuzz takes care of invalid input and passes U+FFFD to us. This reverts commit 29eb45e667be81d37f29fcce2adccb8c5e6d5ada. Change-Id: Icfd0dc836a8d684fb1723fc215aa01f99639ff59 --- engine/src/flutter/libs/minikin/Layout.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 21b83622603..01b6599628f 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -258,12 +258,6 @@ static hb_bool_t harfbuzzGetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoin MinikinPaint* paint = reinterpret_cast(fontData); MinikinFont* font = paint->font; uint32_t glyph_id; - /* HarfBuzz replaces broken input codepoints with (unsigned int) -1. - * Skia expects valid Unicode. - * Replace invalid codepoints with U+FFFD REPLACEMENT CHARACTER. - */ - if (unicode > 0x10FFFF) - unicode = 0xFFFD; bool ok = font->GetGlyph(unicode, &glyph_id); if (ok) { *glyph = glyph_id; From ded72d1e4a2bd01048319e44293138a87f95bf28 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 24 Jul 2014 19:18:14 -0400 Subject: [PATCH 048/364] Remove deprecated API It has been unused outside minikin. Change-Id: Iaa2237767d81c77f90d0264e633375e601dd72f1 --- engine/src/flutter/include/minikin/Layout.h | 11 +---------- engine/src/flutter/libs/minikin/Layout.cpp | 9 --------- engine/src/flutter/sample/example.cpp | 4 ++-- engine/src/flutter/sample/example_skia.cpp | 4 ++-- 4 files changed, 5 insertions(+), 23 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index e30f2f24968..11e5819cd11 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -68,19 +68,13 @@ public: void dump() const; void setFontCollection(const FontCollection* collection); - // deprecated - missing functionality - void doLayout(const uint16_t* buf, size_t nchars); - void doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, const std::string& css); void draw(Bitmap*, int x0, int y0, float size) const; - // deprecated - pass as argument to doLayout instead - void setProperties(const std::string& css); - // This must be called before any invocations. - // TODO: probably have a factory instead + // TODO: probably have a factory instead static void init(); // public accessors @@ -122,9 +116,6 @@ private: // Append another layout (for example, cached value) into this one void appendLayout(Layout* src, size_t start); - // deprecated - remove when setProperties is removed - std::string mCssString; - std::vector mGlyphs; std::vector mAdvances; diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 5125a32f9bc..0715c76645e 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -490,11 +490,6 @@ static size_t getNextWordBreak(const uint16_t* chars, size_t offset, size_t len) return len; } -// deprecated API, to avoid breaking client -void Layout::doLayout(const uint16_t* buf, size_t nchars) { - doLayout(buf, 0, nchars, nchars, mCssString); -} - static void clearHbFonts(LayoutContext* ctx) { for (size_t i = 0; i < ctx->hbFonts.size(); i++) { hb_font_destroy(ctx->hbFonts[i]); @@ -803,10 +798,6 @@ void Layout::draw(Bitmap* surface, int x0, int y0, float size) const { } } -void Layout::setProperties(const string& css) { - mCssString = css; -} - size_t Layout::nGlyphs() const { return mGlyphs.size(); } diff --git a/engine/src/flutter/sample/example.cpp b/engine/src/flutter/sample/example.cpp index b8bd66f4be5..124729114fb 100644 --- a/engine/src/flutter/sample/example.cpp +++ b/engine/src/flutter/sample/example.cpp @@ -83,10 +83,10 @@ int runMinikinTest() { FontCollection *collection = makeFontCollection(); Layout layout; layout.setFontCollection(collection); - layout.setProperties("font-size: 32;"); const char *text = "fine world \xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa5\x87"; + const char *style = "font-size: 32;"; icu::UnicodeString icuText = icu::UnicodeString::fromUTF8(text); - layout.doLayout(icuText.getBuffer(), icuText.length()); + layout.doLayout(icuText.getBuffer(), 0, icuText.length(), icuText.length(), style); layout.dump(); Bitmap bitmap(250, 50); layout.draw(&bitmap, 10, 40, 32); diff --git a/engine/src/flutter/sample/example_skia.cpp b/engine/src/flutter/sample/example_skia.cpp index 1a6aa2362f0..4eb0a563bad 100644 --- a/engine/src/flutter/sample/example_skia.cpp +++ b/engine/src/flutter/sample/example_skia.cpp @@ -117,10 +117,10 @@ int runMinikinTest() { FontCollection *collection = makeFontCollection(); Layout layout; layout.setFontCollection(collection); - layout.setProperties("font-size: 32; font-weight: 700;"); const char *text = "fine world \xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa5\x87"; + const char *style = "font-size: 32; font-weight: 700;"; icu::UnicodeString icuText = icu::UnicodeString::fromUTF8(text); - layout.doLayout(icuText.getBuffer(), icuText.length()); + layout.doLayout(icuText.getBuffer(), 0, icuText.length(), icuText.length(), style); layout.dump(); SkAutoGraphics ag; From 675a078bdf6438986f6a153a0c92cf1e76ed976d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 24 Jul 2014 20:26:03 -0400 Subject: [PATCH 049/364] Towards CSS removal Extract language from FontStyle during shaping. Don't attach CSS to LayoutContext. Change-Id: Ie621d3415410178d0d15fa7b810eb8e412342ab6 --- .../src/flutter/include/minikin/FontFamily.h | 4 +++ .../src/flutter/libs/minikin/FontFamily.cpp | 24 +++++++++++++- engine/src/flutter/libs/minikin/Layout.cpp | 32 ++++++++++--------- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 060d1678c3d..bcc2e3a59c0 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -18,6 +18,7 @@ #define MINIKIN_FONT_FAMILY_H #include +#include #include @@ -39,6 +40,9 @@ public: FontLanguage(const char* buf, size_t size); bool operator==(const FontLanguage other) const { return mBits == other.mBits; } + operator bool() const { return mBits != 0; } + + std::string getString() const; // 0 = no match, 1 = language matches, 2 = language and script match int match(const FontLanguage other) const; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index ad8120f752a..ab6ba20b3be 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -34,7 +34,7 @@ namespace android { FontLanguage::FontLanguage(const char* buf, size_t size) { uint32_t bits = 0; size_t i; - for (i = 0; i < size && buf[i] != '-' && buf[i] != '_'; i++) { + for (i = 0; i < size; i++) { uint16_t c = buf[i]; if (c == '-' || c == '_') break; } @@ -60,6 +60,28 @@ FontLanguage::FontLanguage(const char* buf, size_t size) { mBits = bits; } +std::string FontLanguage::getString() const { + char buf[16]; + size_t i = 0; + if (mBits & kBaseLangMask) { + buf[i++] = (mBits >> 8) & 0xFFu; + buf[i++] = mBits & 0xFFu; + } + if (mBits & kScriptMask) { + if (!i) + buf[i++] = 'x'; + buf[i++] = '-'; + buf[i++] = 'H'; + buf[i++] = 'a'; + buf[i++] = 'n'; + if (mBits & kHansFlag) + buf[i++] = 's'; + else + buf[i++] = 't'; + } + return std::string(buf, i); +} + int FontLanguage::match(const FontLanguage other) const { int result = 0; if ((mBits & kBaseLangMask) == (other.mBits & kBaseLangMask)) { diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 0715c76645e..6611f0685ef 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -170,7 +170,6 @@ hash_t LayoutCacheKey::hash() const { struct LayoutContext { MinikinPaint paint; FontStyle style; - CssProperties props; std::vector hbFonts; // parallel to mFaces }; @@ -502,19 +501,21 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu AutoMutex _l(gMinikinLock); LayoutContext ctx; - ctx.props.parse(css); - ctx.style = styleFromCss(ctx.props); + CssProperties props; + props.parse(css); - ctx.paint.size = ctx.props.value(fontSize).getDoubleValue(); - ctx.paint.scaleX = ctx.props.hasTag(fontScaleX) - ? ctx.props.value(fontScaleX).getDoubleValue() : 1; - ctx.paint.skewX = ctx.props.hasTag(fontSkewX) - ? ctx.props.value(fontSkewX).getDoubleValue() : 0; - ctx.paint.letterSpacing = ctx.props.hasTag(letterSpacing) - ? ctx.props.value(letterSpacing).getDoubleValue() : 0; - ctx.paint.paintFlags = ctx.props.hasTag(paintFlags) - ? ctx.props.value(paintFlags).getUintValue() : 0; - int bidiFlags = ctx.props.hasTag(minikinBidi) ? ctx.props.value(minikinBidi).getIntValue() : 0; + ctx.style = styleFromCss(props); + + ctx.paint.size = props.value(fontSize).getDoubleValue(); + ctx.paint.scaleX = props.hasTag(fontScaleX) + ? props.value(fontScaleX).getDoubleValue() : 1; + ctx.paint.skewX = props.hasTag(fontSkewX) + ? props.value(fontSkewX).getDoubleValue() : 0; + ctx.paint.letterSpacing = props.hasTag(letterSpacing) + ? props.value(letterSpacing).getDoubleValue() : 0; + ctx.paint.paintFlags = props.hasTag(paintFlags) + ? props.value(paintFlags).getUintValue() : 0; + int bidiFlags = props.hasTag(minikinBidi) ? props.value(minikinBidi).getIntValue() : 0; bool isRtl = (bidiFlags & kDirection_Mask) != 0; bool doSingleRun = true; @@ -697,8 +698,9 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t hb_buffer_reset(buffer); hb_buffer_set_script(buffer, script); hb_buffer_set_direction(buffer, isRtl? HB_DIRECTION_RTL : HB_DIRECTION_LTR); - if (ctx->props.hasTag(cssLang)) { - string lang = ctx->props.value(cssLang).getStringValue(); + FontLanguage language = ctx->style.getLanguage(); + if (language) { + string lang = language.getString(); hb_buffer_set_language(buffer, hb_language_from_string(lang.c_str(), -1)); } hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart); From abf2e7d050ef0355a6fbb199ddd11a5bc4ce848d Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 25 Jul 2014 14:49:27 -0400 Subject: [PATCH 050/364] Don't get stuck on invalid UTF-16 Replaces invalid unicode with replacement character U+FFFD and always makes forward progress. Bug: 15849380 Change-Id: Ic59ef6c64b0f5c4450bcae61597adcc269d6e7c5 --- engine/src/flutter/libs/minikin/Layout.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 0715c76645e..6b019d401c0 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -397,11 +397,10 @@ static hb_codepoint_t decodeUtf16(const uint16_t* chars, size_t len, ssize_t* it const hb_codepoint_t delta = (0xd800 << 10) + 0xdc00 - 0x10000; return (((hb_codepoint_t)v) << 10) + v2 - delta; } - (*iter) -= 2; - return ~0u; + (*iter) -= 1; + return 0xFFFDu; } else { - (*iter)--; - return ~0u; + return 0xFFFDu; } } else { return v; From bff381b1bedf7d9639a910e0d8d3bd38af28a7c2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 29 Jul 2014 15:51:12 -0400 Subject: [PATCH 051/364] Remove CSS string doLayout entrypoint and supporting code All usage is ported to the new doLayout() API now. Bug: 16651112 Change-Id: I2c959138a69853b5e30098889d771fe5f4cfaa66 --- engine/src/flutter/include/minikin/CssParse.h | 108 --------- engine/src/flutter/include/minikin/Layout.h | 5 - engine/src/flutter/libs/minikin/Android.mk | 1 - engine/src/flutter/libs/minikin/CssParse.cpp | 210 ------------------ engine/src/flutter/libs/minikin/Layout.cpp | 45 ---- 5 files changed, 369 deletions(-) delete mode 100644 engine/src/flutter/include/minikin/CssParse.h delete mode 100644 engine/src/flutter/libs/minikin/CssParse.cpp diff --git a/engine/src/flutter/include/minikin/CssParse.h b/engine/src/flutter/include/minikin/CssParse.h deleted file mode 100644 index 259b933a54a..00000000000 --- a/engine/src/flutter/include/minikin/CssParse.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2013 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_CSS_PARSE_H -#define MINIKIN_CSS_PARSE_H - -#include -#include - -namespace android { - -enum CssTag { - unknown, - fontScaleX, - fontSize, - fontSkewX, - fontStyle, - fontWeight, - cssLang, - letterSpacing, - minikinBidi, - minikinHinting, - minikinVariant, - paintFlags, -}; - -const std::string cssTagNames[] = { - "unknown", - "font-scale-x", - "font-size", - "font-skew-x", - "font-style", - "font-weight", - "lang", - "letter-spacing", - "-minikin-bidi", - "-minikin-hinting", - "-minikin-variant", - "-paint-flags", -}; - -class CssValue { -public: - enum Type { - UNKNOWN, - DOUBLE, - STRING - }; - enum Units { - SCALAR, - PERCENT, - PX, - EM - }; - CssValue() : mType(UNKNOWN) { } - explicit CssValue(double v) : - mType(DOUBLE), doubleValue(v), mUnits(SCALAR) { } - Type getType() const { return mType; } - double getDoubleValue() const { return doubleValue; } - int32_t getIntValue() const { return doubleValue; } - uint32_t getUintValue() const { return doubleValue; } - std::string getStringValue() const { return stringValue; } - std::string toString(CssTag tag) const; - void setDoubleValue(double v) { - mType = DOUBLE; - doubleValue = v; - } - void setStringValue(const std::string& v) { - mType = STRING; - stringValue = v; - } -private: - Type mType; - double doubleValue; - std::string stringValue; - Units mUnits; -}; - -class CssProperties { -public: - bool parse(const std::string& str); - bool hasTag(CssTag tag) const; - CssValue value(CssTag tag) const; - - // primarily for debugging - std::string toString() const; -private: - // We'll use STL map for now but can replace it with something - // more efficient if needed - std::map mMap; -}; - -} // namespace android - -#endif // MINIKIN_CSS_PARSE_H diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index cd08e00283c..1a0df99e671 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -21,7 +21,6 @@ #include -#include #include #include @@ -68,10 +67,6 @@ public: void dump() const; void setFontCollection(const FontCollection* collection); - // Deprecated. Will be removed. - void doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - const std::string& css); - void doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint); diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index fde2cbbbf4d..386dc2bee1c 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -20,7 +20,6 @@ include external/stlport/libstlport.mk LOCAL_SRC_FILES := \ AnalyzeStyle.cpp \ CmapCoverage.cpp \ - CssParse.cpp \ FontCollection.cpp \ FontFamily.cpp \ GraphemeBreak.cpp \ diff --git a/engine/src/flutter/libs/minikin/CssParse.cpp b/engine/src/flutter/libs/minikin/CssParse.cpp deleted file mode 100644 index 057dab7e82f..00000000000 --- a/engine/src/flutter/libs/minikin/CssParse.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (C) 2013 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 -#include -#include -#include // for sprintf - for debugging - -#include -#include - -using std::map; -using std::pair; -using std::string; - -namespace android { - -static bool strEqC(const string str, size_t off, size_t len, const char* str2) { - if (len != strlen(str2)) return false; - return !memcmp(str.data() + off, str2, len); -} - -static CssTag parseTag(const string str, size_t off, size_t len) { - if (len == 0) return unknown; - char c = str[off]; - if (c == 'f') { - if (strEqC(str, off, len, "font-scale-x")) return fontScaleX; - if (strEqC(str, off, len, "font-size")) return fontSize; - if (strEqC(str, off, len, "font-skew-x")) return fontSkewX; - if (strEqC(str, off, len, "font-weight")) return fontWeight; - if (strEqC(str, off, len, "font-style")) return fontStyle; - } else if (c == 'l') { - if (strEqC(str, off, len, "lang")) return cssLang; - if (strEqC(str, off, len, "letter-spacing")) return letterSpacing; - } else if (c == '-') { - if (strEqC(str, off, len, "-minikin-bidi")) return minikinBidi; - if (strEqC(str, off, len, "-minikin-hinting")) return minikinHinting; - if (strEqC(str, off, len, "-minikin-variant")) return minikinVariant; - if (strEqC(str, off, len, "-paint-flags")) return paintFlags; - } - return unknown; -} - -static bool parseStringValue(const string& str, size_t* off, size_t len, CssTag tag, CssValue* v) { - const char* data = str.data(); - size_t beg = *off; - if (beg == len) return false; - char first = data[beg]; - bool quoted = false; - if (first == '\'' || first == '\"') { - quoted = true; - beg++; - } - size_t end; - for (end = beg; end < len; end++) { - char c = data[end]; - if (quoted && c == first) { - v->setStringValue(std::string(str, beg, end - beg)); - *off = end + 1; - return true; - } else if (!quoted && (c == ';' || c == ' ')) { - break; - } // TODO: deal with backslash escape, but only important for real strings - } - v->setStringValue(std::string(str, beg, end - beg)); - *off = end; - return true; -} - -static bool parseValue(const string& str, size_t* off, size_t len, CssTag tag, CssValue* v) { - if (tag == cssLang) { - return parseStringValue(str, off, len, tag, v); - } - const char* data = str.data(); - char* endptr; - double fv = strtod(data + *off, &endptr); - if (endptr == data + *off) { - // No numeric value, try tag-specific idents - size_t end; - for (end = *off; end < len; end++) { - char c = data[end]; - if (c != '-' && !(c >= 'a' && c <= 'z') && - !(c >= '0' && c <= '9')) break; - } - size_t taglen = end - *off; - endptr += taglen; - if (tag == fontStyle) { - if (strEqC(str, *off, taglen, "normal")) { - fv = 0; - } else if (strEqC(str, *off, taglen, "italic")) { - fv = 1; - // TODO: oblique, but who really cares? - } else { - return false; - } - } else if (tag == fontWeight) { - if (strEqC(str, *off, taglen, "normal")) { - fv = 400; - } else if (strEqC(str, *off, taglen, "bold")) { - fv = 700; - } else { - return false; - } - } else if (tag == minikinVariant) { - if (strEqC(str, *off, taglen, "compact")) { - fv = VARIANT_COMPACT; - } else if (strEqC(str, *off, taglen, "elegant")) { - fv = VARIANT_ELEGANT; - } - } else { - return false; - } - } - v->setDoubleValue(fv); - *off = endptr - data; - return true; -} - -string CssValue::toString(CssTag tag) const { - if (mType == DOUBLE) { - if (tag == fontStyle) { - return doubleValue ? "italic" : "normal"; - } else if (tag == minikinVariant) { - if (doubleValue == VARIANT_COMPACT) return "compact"; - if (doubleValue == VARIANT_ELEGANT) return "elegant"; - } - char buf[64]; - sprintf(buf, "%g", doubleValue); - return string(buf); - } else if (mType == STRING) { - return stringValue; // should probably quote - } - return ""; -} - -bool CssProperties::parse(const string& str) { - size_t len = str.size(); - size_t i = 0; - while (true) { - size_t j = i; - while (j < len && str[j] == ' ') j++; - if (j == len) break; - size_t k = str.find_first_of(':', j); - if (k == string::npos) { - return false; // error: junk after end - } - CssTag tag = parseTag(str, j, k - j); -#ifdef VERBOSE - printf("parseTag result %d, ijk %lu %lu %lu\n", tag, i, j, k); -#endif - if (tag == unknown) return false; // error: unknown tag - k++; // skip over colon - while (k < len && str[k] == ' ') k++; - if (k == len) return false; // error: missing value - CssValue v; - if (!parseValue(str, &k, len, tag, &v)) break; -#ifdef VERBOSE - printf("parseValue ok\n"); -#endif - mMap.insert(pair(tag, v)); - while (k < len && str[k] == ' ') k++; - if (k < len) { - if (str[k] != ';') return false; - k++; - } - i = k; - } - return true; -} - -bool CssProperties::hasTag(CssTag tag) const { - return (mMap.find(tag) != mMap.end()); -} - -CssValue CssProperties::value(CssTag tag) const { - map::const_iterator it = mMap.find(tag); - if (it == mMap.end()) { - CssValue unknown; - return unknown; - } else { - return it->second; - } -} - -string CssProperties::toString() const { - string result; - for (map::const_iterator it = mMap.begin(); - it != mMap.end(); it++) { - result += cssTagNames[it->first]; - result += ": "; - result += it->second.toString(it->first); - result += ";\n"; - } - return result; -} - -} // namespace android diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 2a396dcc774..f34d1b9f19b 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -354,27 +354,6 @@ int Layout::findFace(FakedFont face, LayoutContext* ctx) { return ix; } -static FontStyle styleFromCss(const CssProperties &props) { - int weight = 4; - if (props.hasTag(fontWeight)) { - weight = props.value(fontWeight).getIntValue() / 100; - } - bool italic = false; - if (props.hasTag(fontStyle)) { - italic = props.value(fontStyle).getIntValue() != 0; - } - FontLanguage lang; - if (props.hasTag(cssLang)) { - string langStr = props.value(cssLang).getStringValue(); - lang = FontLanguage(langStr.c_str(), langStr.size()); - } - int variant = 0; - if (props.hasTag(minikinVariant)) { - variant = props.value(minikinVariant).getIntValue(); - } - return FontStyle(lang, variant, weight, italic); -} - static hb_script_t codePointToScript(hb_codepoint_t codepoint) { static hb_unicode_funcs_t* u = 0; if (!u) { @@ -495,30 +474,6 @@ static void clearHbFonts(LayoutContext* ctx) { ctx->hbFonts.clear(); } -void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - const string& css) { - - CssProperties props; - props.parse(css); - - FontStyle style = styleFromCss(props); - MinikinPaint paint; - - paint.size = props.value(fontSize).getDoubleValue(); - paint.scaleX = props.hasTag(fontScaleX) - ? props.value(fontScaleX).getDoubleValue() : 1; - paint.skewX = props.hasTag(fontSkewX) - ? props.value(fontSkewX).getDoubleValue() : 0; - paint.letterSpacing = props.hasTag(letterSpacing) - ? props.value(letterSpacing).getDoubleValue() : 0; - paint.paintFlags = props.hasTag(paintFlags) - ? props.value(paintFlags).getUintValue() : 0; - - int bidiFlags = props.hasTag(minikinBidi) ? props.value(minikinBidi).getIntValue() : 0; - - doLayout(buf, start, count, bufSize, bidiFlags, style, paint); -} - void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint) { AutoMutex _l(gMinikinLock); From b501846d80e9a5066e3462222cf4b57f2f748d96 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 29 Jul 2014 12:46:07 -0400 Subject: [PATCH 052/364] Add doLayout variant that does NOT take css string New API removes CSS string and directly takes needed objects. Bug: 16651112 Change-Id: Ie5f7c2ab05be6cbd77cae0a5fd6bb453771ada59 --- engine/src/flutter/include/minikin/Layout.h | 4 +++ engine/src/flutter/libs/minikin/Layout.cpp | 28 +++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 11e5819cd11..cd08e00283c 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -68,9 +68,13 @@ public: void dump() const; void setFontCollection(const FontCollection* collection); + // Deprecated. Will be removed. void doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, const std::string& css); + void doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + int bidiFlags, const FontStyle &style, const MinikinPaint &paint); + void draw(Bitmap*, int x0, int y0, float size) const; // This must be called before any invocations. diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 072cedad2b4..2a396dcc774 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -497,24 +497,36 @@ static void clearHbFonts(LayoutContext* ctx) { void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, const string& css) { - AutoMutex _l(gMinikinLock); - LayoutContext ctx; CssProperties props; props.parse(css); - ctx.style = styleFromCss(props); + FontStyle style = styleFromCss(props); + MinikinPaint paint; - ctx.paint.size = props.value(fontSize).getDoubleValue(); - ctx.paint.scaleX = props.hasTag(fontScaleX) + paint.size = props.value(fontSize).getDoubleValue(); + paint.scaleX = props.hasTag(fontScaleX) ? props.value(fontScaleX).getDoubleValue() : 1; - ctx.paint.skewX = props.hasTag(fontSkewX) + paint.skewX = props.hasTag(fontSkewX) ? props.value(fontSkewX).getDoubleValue() : 0; - ctx.paint.letterSpacing = props.hasTag(letterSpacing) + paint.letterSpacing = props.hasTag(letterSpacing) ? props.value(letterSpacing).getDoubleValue() : 0; - ctx.paint.paintFlags = props.hasTag(paintFlags) + paint.paintFlags = props.hasTag(paintFlags) ? props.value(paintFlags).getUintValue() : 0; + int bidiFlags = props.hasTag(minikinBidi) ? props.value(minikinBidi).getIntValue() : 0; + + doLayout(buf, start, count, bufSize, bidiFlags, style, paint); +} + +void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + int bidiFlags, const FontStyle &style, const MinikinPaint &paint) { + AutoMutex _l(gMinikinLock); + + LayoutContext ctx; + ctx.style = style; + ctx.paint = paint; + bool isRtl = (bidiFlags & kDirection_Mask) != 0; bool doSingleRun = true; From f3879f9b1f5593552e96cd0f3c2cf755c376fb85 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 29 Jul 2014 16:26:49 -0400 Subject: [PATCH 053/364] Initialize MinikinPaint members We are stack-allocating MinikinPaint objects in Minikin clients, and without a constructor adding new members to the struct cannot be done without updating all clients (only one right now!). Change-Id: I4170f16498bb6b07cb795495011aca58087ed0bd --- engine/src/flutter/include/minikin/MinikinFont.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 935d4bb0b38..873a3eaf4a8 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -30,6 +30,8 @@ class MinikinFont; // Possibly move into own .h file? // Note: if you add a field here, also update LayoutCacheKey struct MinikinPaint { + MinikinPaint() : font(0), size(0), scaleX(0), skewX(0), letterSpacing(0), paintFlags(0), + fakery() { } MinikinFont *font; float size; float scaleX; From 8bee8f92e045f5e709dbcbedd9d486b55e73f54e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 29 Jul 2014 16:57:00 -0400 Subject: [PATCH 054/364] Fix examples build Was broken after recent CSS removal. Change-Id: I160fbc73286b21336d6f3943ff92d7d150dff74b --- engine/src/flutter/sample/example.cpp | 7 +++++-- engine/src/flutter/sample/example_skia.cpp | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/sample/example.cpp b/engine/src/flutter/sample/example.cpp index 124729114fb..487357a47bf 100644 --- a/engine/src/flutter/sample/example.cpp +++ b/engine/src/flutter/sample/example.cpp @@ -84,9 +84,12 @@ int runMinikinTest() { Layout layout; layout.setFontCollection(collection); const char *text = "fine world \xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa5\x87"; - const char *style = "font-size: 32;"; + int bidiFlags = 0; + FontStyle fontStyle; + MinikinPaint paint; + paint.size = 32; icu::UnicodeString icuText = icu::UnicodeString::fromUTF8(text); - layout.doLayout(icuText.getBuffer(), 0, icuText.length(), icuText.length(), style); + layout.doLayout(icuText.getBuffer(), 0, icuText.length(), icuText.length(), bidiFlags, fontStyle, paint); layout.dump(); Bitmap bitmap(250, 50); layout.draw(&bitmap, 10, 40, 32); diff --git a/engine/src/flutter/sample/example_skia.cpp b/engine/src/flutter/sample/example_skia.cpp index 4eb0a563bad..51fcf47e58a 100644 --- a/engine/src/flutter/sample/example_skia.cpp +++ b/engine/src/flutter/sample/example_skia.cpp @@ -119,8 +119,12 @@ int runMinikinTest() { layout.setFontCollection(collection); const char *text = "fine world \xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa5\x87"; const char *style = "font-size: 32; font-weight: 700;"; + int bidiFlags = 0; + FontStyle fontStyle(7); + MinikinPaint minikinPaint; + minikinPaint.size = 32; icu::UnicodeString icuText = icu::UnicodeString::fromUTF8(text); - layout.doLayout(icuText.getBuffer(), 0, icuText.length(), icuText.length(), style); + layout.doLayout(icuText.getBuffer(), 0, icuText.length(), icuText.length(), bidiFlags, fontStyle, minikinPaint); layout.dump(); SkAutoGraphics ag; From a944efa7a0e61169f56c0002b95e9d6951b1e86e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 29 Jul 2014 17:19:22 -0400 Subject: [PATCH 055/364] Support fontFeatureSettings Bug: 15246510 Change-Id: I544915d29b2be4fb9f82f1989188a3a918c50fbc --- .../src/flutter/include/minikin/MinikinFont.h | 12 +++++-- engine/src/flutter/libs/minikin/Layout.cpp | 35 ++++++++++++------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 873a3eaf4a8..9b25f9234da 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -17,6 +17,8 @@ #ifndef MINIKIN_FONT_H #define MINIKIN_FONT_H +#include + #include #include @@ -28,10 +30,15 @@ namespace android { class MinikinFont; // Possibly move into own .h file? -// Note: if you add a field here, also update LayoutCacheKey +// Note: if you add a field here, either add it to LayoutCacheKey or to skipCache() struct MinikinPaint { MinikinPaint() : font(0), size(0), scaleX(0), skewX(0), letterSpacing(0), paintFlags(0), - fakery() { } + fakery(), fontFeatureSettings() { } + + bool skipCache() const { + return !fontFeatureSettings.empty(); + } + MinikinFont *font; float size; float scaleX; @@ -39,6 +46,7 @@ struct MinikinPaint { float letterSpacing; uint32_t paintFlags; FontFakery fakery; + std::string fontFeatureSettings; }; struct MinikinRect { diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index f34d1b9f19b..aaac186a489 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -578,7 +578,8 @@ void Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_ bool isRtl, LayoutContext* ctx, size_t bufStart) { LayoutCache& cache = LayoutEngine::getInstance().layoutCache; LayoutCacheKey key(mCollection, ctx->paint, ctx->style, buf, start, count, bufSize, isRtl); - Layout* value = cache.mCache.get(key); + bool skipCache = ctx->paint.skipCache(); + Layout* value = skipCache ? NULL : cache.mCache.get(key); if (value == NULL) { value = new Layout(); value->setFontCollection(mCollection); @@ -589,19 +590,29 @@ void Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_ value->doLayoutRun(key.textBuf(), start, count, bufSize, isRtl, ctx); } appendLayout(value, bufStart); - cache.mCache.put(key, value); + if (!skipCache) + cache.mCache.put(key, value); } -static void addFeatures(vector* features) { - // hardcoded features, to be repaced with more flexible configuration - static hb_feature_t palt = { HB_TAG('p', 'a', 'l', 't'), 1, 0, ~0u }; +static void addFeatures(const string &str, vector* features) { + if (!str.size()) + return; - // Don't enable "palt" for now, pending implementation of more of the - // W3C Japanese layout recommendations. See: - // http://www.w3.org/TR/2012/NOTE-jlreq-20120403/ -#if 0 - features->push_back(palt); -#endif + const char* start = str.c_str(); + const char* end = start + str.size(); + + while (start < end) { + static hb_feature_t feature; + const char* p = strchr(start, ','); + if (!p) + p = end; + /* We do not allow setting features on ranges. As such, reject any + * setting that has non-universal range. */ + if (hb_feature_from_string (start, p - start, &feature) + && feature.start == 0 && feature.end == (unsigned int) -1) + features->push_back(feature); + start = p + 1; + } } void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, @@ -626,7 +637,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t features.push_back(no_liga); features.push_back(no_clig); } - addFeatures(&features); + addFeatures(ctx->paint.fontFeatureSettings, &features); double size = ctx->paint.size; double scaleX = ctx->paint.scaleX; From 2f24599f4a258160854d18096b302ec2c3aa66c9 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 8 Aug 2014 15:25:57 -0400 Subject: [PATCH 056/364] Choose same font for Emoji keycap and its base character The U+20E3 COMBINING KEYCAP is used in our fonts to generate an emoji rendering of ASCII numbers and letters through GSUB. For that to work we need to choose the same (Emoji) font for the character coming *before* the COMBINING KEYCAP character. This is a special-case of a broader need to choose fonts per grapheme cluster as opposed to per character, but for now, special-case U+20E3. Bug: 7557244 Change-Id: I958e5a01068df8495bbb9bc3b9ed871cea1838b6 --- .../flutter/libs/minikin/FontCollection.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index a6977fd6c6c..009584e8a8f 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -152,9 +152,11 @@ const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t const uint32_t NBSP = 0xa0; const uint32_t ZWJ = 0x200c; const uint32_t ZWNJ = 0x200d; +const uint32_t KEYCAP = 0x20e3; + // Characters where we want to continue using existing font run instead of // recomputing the best match in the fallback list. -static const uint32_t stickyWhitelist[] = { '!', ',', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ }; +static const uint32_t stickyWhitelist[] = { '!', ',', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ, KEYCAP }; static bool isStickyWhitelisted(uint32_t c) { for (size_t i = 0; i < sizeof(stickyWhitelist) / sizeof(stickyWhitelist[0]); i++) { @@ -185,6 +187,19 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty || !(isStickyWhitelisted(ch) && lastInstance->mCoverage->get(ch))) { const FontInstance* instance = getInstanceForChar(ch, lang, variant); if (i == 0 || instance != lastInstance) { + size_t start = i; + // Workaround for Emoji keycap until we implement per-cluster font + // selection: if keycap is found in a different font that also + // supports previous char, attach previous char to the new run. + // Only handles non-surrogate characters. + // Bug 7557244. + if (ch == KEYCAP && i && instance && instance->mCoverage->get(string[i - 1])) { + run->end--; + if (run->start == run->end) { + result->pop_back(); + } + start--; + } Run dummy; result->push_back(dummy); run = &result->back(); @@ -194,7 +209,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty run->fakedFont = instance->mFamily->getClosestMatch(style); } lastInstance = instance; - run->start = i; + run->start = start; } } run->end = i + nShorts; From a33151e9c78c5547eeadbaaa9168dad361df05e4 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 20 Aug 2014 17:41:51 -0400 Subject: [PATCH 057/364] Speed up cache lookup Avoid copying the string for cache lookup. Bug: 17111260 Change-Id: Ic220bfc991fc6b3dada197304aabdf72a8941bd7 --- engine/src/flutter/include/minikin/Layout.h | 2 + engine/src/flutter/libs/minikin/Layout.cpp | 99 +++++++++++++-------- 2 files changed, 66 insertions(+), 35 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 1a0df99e671..c88d087c046 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -97,6 +97,8 @@ public: static void purgeCaches(); private: + friend class LayoutCacheKey; + // Find a face in the mFaces vector, or create a new entry int findFace(FakedFont face, LayoutContext* ctx); diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index aaac186a489..e3557302ed1 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -56,6 +56,19 @@ enum { const int kDirection_Mask = 0x1; +struct LayoutContext { + MinikinPaint paint; + FontStyle style; + std::vector hbFonts; // parallel to mFaces + + void clearHbFonts() { + for (size_t i = 0; i < hbFonts.size(); i++) { + hb_font_destroy(hbFonts[i]); + } + hbFonts.clear(); + } +}; + // Layout cache datatypes class LayoutCacheKey { @@ -65,16 +78,32 @@ public: : mStart(start), mCount(count), mId(collection->getId()), mStyle(style), mSize(paint.size), mScaleX(paint.scaleX), mSkewX(paint.skewX), mLetterSpacing(paint.letterSpacing), - mPaintFlags(paint.paintFlags), mIsRtl(dir) { - mText.setTo(chars, nchars); + mPaintFlags(paint.paintFlags), mIsRtl(dir), + mChars(chars), mNchars(nchars) { } bool operator==(const LayoutCacheKey &other) const; hash_t hash() const; - // This is present to avoid having to copy the text more than once. - const uint16_t* textBuf() { return mText.string(); } + void copyText() { + uint16_t* charsCopy = new uint16_t[mNchars]; + memcpy(charsCopy, mChars, mNchars * sizeof(uint16_t)); + mChars = charsCopy; + } + void freeText() { + delete[] mChars; + mChars = NULL; + } + + void doLayout(Layout* layout, LayoutContext* ctx, const FontCollection* collection) const { + layout->setFontCollection(collection); + layout->mAdvances.resize(mCount, 0); + ctx->clearHbFonts(); + layout->doLayoutRun(mChars, mStart, mCount, mNchars, mIsRtl, ctx); + } + private: - String16 mText; + const uint16_t* mChars; + size_t mNchars; size_t mStart; size_t mCount; uint32_t mId; // for the font collection @@ -95,13 +124,30 @@ public: mCache.setOnEntryRemovedListener(this); } + void clear() { + mCache.clear(); + } + + Layout* get(LayoutCacheKey& key, LayoutContext* ctx, const FontCollection* collection) { + Layout* layout = mCache.get(key); + if (layout == NULL) { + key.copyText(); + layout = new Layout(); + key.doLayout(layout, ctx, collection); + mCache.put(key, layout); + } + return layout; + } + +private: // callback for OnEntryRemoved void operator()(LayoutCacheKey& key, Layout*& value) { + key.freeText(); delete value; } LruCache mCache; -private: + //static const size_t kMaxEntries = LruCache::kUnlimitedCapacity; // TODO: eviction based on memory footprint; for now, we just use a constant @@ -149,7 +195,8 @@ bool LayoutCacheKey::operator==(const LayoutCacheKey& other) const { && mLetterSpacing == other.mLetterSpacing && mPaintFlags == other.mPaintFlags && mIsRtl == other.mIsRtl - && mText == other.mText; + && mNchars == other.mNchars + && !memcmp(mChars, other.mChars, mNchars * sizeof(uint16_t)); } hash_t LayoutCacheKey::hash() const { @@ -163,16 +210,10 @@ hash_t LayoutCacheKey::hash() const { hash = JenkinsHashMix(hash, hash_type(mLetterSpacing)); hash = JenkinsHashMix(hash, hash_type(mPaintFlags)); hash = JenkinsHashMix(hash, hash_type(mIsRtl)); - hash = JenkinsHashMixShorts(hash, mText.string(), mText.size()); + hash = JenkinsHashMixShorts(hash, mChars, mNchars); return JenkinsHashWhiten(hash); } -struct LayoutContext { - MinikinPaint paint; - FontStyle style; - std::vector hbFonts; // parallel to mFaces -}; - hash_t hash_type(const LayoutCacheKey& key) { return key.hash(); } @@ -467,13 +508,6 @@ static size_t getNextWordBreak(const uint16_t* chars, size_t offset, size_t len) return len; } -static void clearHbFonts(LayoutContext* ctx) { - for (size_t i = 0; i < ctx->hbFonts.size(); i++) { - hb_font_destroy(ctx->hbFonts[i]); - } - ctx->hbFonts.clear(); -} - void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint) { AutoMutex _l(gMinikinLock); @@ -543,7 +577,7 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu if (doSingleRun) { doLayoutRunCached(buf, start, count, bufSize, isRtl, &ctx, start); } - clearHbFonts(&ctx); + ctx.clearHbFonts(); } void Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, @@ -579,19 +613,14 @@ void Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_ LayoutCache& cache = LayoutEngine::getInstance().layoutCache; LayoutCacheKey key(mCollection, ctx->paint, ctx->style, buf, start, count, bufSize, isRtl); bool skipCache = ctx->paint.skipCache(); - Layout* value = skipCache ? NULL : cache.mCache.get(key); - if (value == NULL) { - value = new Layout(); - value->setFontCollection(mCollection); - value->mAdvances.resize(count, 0); - clearHbFonts(ctx); - // Note: we do the layout from the copy stored in the key, in case a - // badly-behaved client is mutating the buffer in a separate thread. - value->doLayoutRun(key.textBuf(), start, count, bufSize, isRtl, ctx); + if (skipCache) { + Layout layout; + key.doLayout(&layout, ctx, mCollection); + appendLayout(&layout, bufStart); + } else { + Layout* layout = cache.get(key, ctx, mCollection); + appendLayout(layout, bufStart); } - appendLayout(value, bufStart); - if (!skipCache) - cache.mCache.put(key, value); } static void addFeatures(const string &str, vector* features) { @@ -821,7 +850,7 @@ void Layout::getBounds(MinikinRect* bounds) { void Layout::purgeCaches() { AutoMutex _l(gMinikinLock); LayoutCache& layoutCache = LayoutEngine::getInstance().layoutCache; - layoutCache.mCache.clear(); + layoutCache.clear(); HbFaceCache& hbCache = LayoutEngine::getInstance().hbFaceCache; hbCache.mCache.clear(); } From df03550a40706a55ca1bfcb67da62765194cf98f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 21 Aug 2014 16:30:03 -0400 Subject: [PATCH 058/364] Fix Layout initialization in the skipCache path C++ local var initialization always tricks me. Previously, Layout didn't have a constructor, which meant that defining it on the stack left mAdvance uninitialized. This was not an issue when we were doing "new Layout()", since that invokes zero-initialization, but was an issue for the skipCache path that was allocating layout on stack by just "Layout l" instead of "Layout l = Layout()". To avoid surprises, add a constructors that clears everything. Also adds reset() method to reset the layout for reuse. Change-Id: I3e02f00da9dd7d360abe13f63c310f6882292d0a --- engine/src/flutter/include/minikin/Layout.h | 11 +++++++++-- engine/src/flutter/libs/minikin/Layout.cpp | 17 +++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index c88d087c046..9f8759768d1 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -64,6 +64,14 @@ class LayoutContext; // extend through the lifetime of the Layout object. class Layout { public: + + Layout() : mGlyphs(), mAdvances(), mCollection(0), mFaces(), mAdvance(0), mBounds() { + mBounds.setEmpty(); + } + + // Clears layout, ready to be used again + void reset(); + void dump() const; void setFontCollection(const FontCollection* collection); @@ -72,8 +80,7 @@ public: void draw(Bitmap*, int x0, int y0, float size) const; - // This must be called before any invocations. - // TODO: probably have a factory instead + // Deprecated. Nont needed. Remove when callers are removed. static void init(); // public accessors diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index e3557302ed1..46819d64e4d 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -267,10 +267,18 @@ void MinikinRect::join(const MinikinRect& r) { } } -// TODO: the actual initialization is deferred, maybe make this explicit +// Deprecated. Remove when callers are removed. void Layout::init() { } +void Layout::reset() { + mGlyphs.clear(); + mFaces.clear(); + mBounds.setEmpty(); + mAdvances.clear(); + mAdvance = 0; +} + void Layout::setFontCollection(const FontCollection* collection) { mCollection = collection; } @@ -519,12 +527,9 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu bool isRtl = (bidiFlags & kDirection_Mask) != 0; bool doSingleRun = true; - mGlyphs.clear(); - mFaces.clear(); - mBounds.setEmpty(); - mAdvances.clear(); + reset(); mAdvances.resize(count, 0); - mAdvance = 0; + if (!(bidiFlags == kBidi_Force_LTR || bidiFlags == kBidi_Force_RTL)) { UBiDi* bidi = ubidi_open(); if (bidi) { From 11c8920a3fc1c5895e777f71c822501367eef69c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 21 Aug 2014 19:14:14 -0400 Subject: [PATCH 059/364] Allocate font vector on stack This reduces another allocation (last one?) we were doing when fulfilling shaping requests from the cache. Bug: 17111260 Change-Id: Ieb8ae1ccfcaacedb257e1e9263777f10623aaf98 --- engine/src/flutter/libs/minikin/Layout.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 46819d64e4d..c3d4c13e86f 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -760,11 +760,16 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t } void Layout::appendLayout(Layout* src, size_t start) { - // Note: size==1 is by far most common, should have specialized vector for this - std::vector fontMap; + int fontMapStack[16]; + int* fontMap; + if (src->mFaces.size() < sizeof(fontMapStack) / sizeof(fontMapStack[0])) { + fontMap = fontMapStack; + } else { + fontMap = new int[src->mFaces.size()]; + } for (size_t i = 0; i < src->mFaces.size(); i++) { int font_ix = findFace(src->mFaces[i], NULL); - fontMap.push_back(font_ix); + fontMap[i] = font_ix; } int x0 = mAdvance; for (size_t i = 0; i < src->mGlyphs.size(); i++) { @@ -783,6 +788,10 @@ void Layout::appendLayout(Layout* src, size_t start) { srcBounds.offset(x0, 0); mBounds.join(srcBounds); mAdvance += src->mAdvance; + + if (fontMap != fontMapStack) { + delete[] fontMap; + } } void Layout::draw(Bitmap* surface, int x0, int y0, float size) const { From 543c65c80b71e3111314bf429004a10d004e861b Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 26 Aug 2014 22:08:58 -0700 Subject: [PATCH 060/364] Try Unicode decomposition for selecting fallback font This patch finds an appropriate fallback font in the case where no font directly maps the requested character, but a font does exist for the character's canonical decomposition. This yields correct rendering of compatibility characters such as U+FA70. Bug: 15816880 Bug: 16856221 Change-Id: Idff8ed6b942fec992a0815a32028b95af091d0ee --- .../src/flutter/libs/minikin/FontCollection.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 009584e8a8f..ca5b1d1ab36 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -19,6 +19,9 @@ #define LOG_TAG "Minikin" #include +#include "unicode/unistr.h" +#include "unicode/unorm2.h" + #include "MinikinInternal.h" #include #include @@ -143,7 +146,18 @@ const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t } } } - if (bestInstance == NULL) { + if (bestInstance == NULL && !mInstanceVec.empty()) { + UErrorCode errorCode = U_ZERO_ERROR; + const UNormalizer2* normalizer = unorm2_getNFDInstance(&errorCode); + if (U_SUCCESS(errorCode)) { + UChar decomposed[4]; + int len = unorm2_getRawDecomposition(normalizer, ch, decomposed, 4, &errorCode); + if (U_SUCCESS(errorCode) && len > 0) { + int off = 0; + U16_NEXT_UNSAFE(decomposed, off, ch); + return getInstanceForChar(ch, lang, variant); + } + } bestInstance = &mInstances[0]; } return bestInstance; From ff55a581fa07b52f3cffcf3fc825d297cf955ffe Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 3 Sep 2014 10:37:05 -0700 Subject: [PATCH 061/364] Snap advance widths to integers Fractional advance widths were causing subtle problems with text positioning when the same text was drawn with different spans in the hwui renderer. Quantizing the coordinates on layout (as opposed to waiting until the renderer draws the glyphs) solves the problem. This patch also fixes a discrepancy between x position and advance widths when letterspacing. Bug: 17347779 Change-Id: Ia705944047408c2839d5ad078eefd6bbec446872 --- .../src/flutter/include/minikin/MinikinFont.h | 6 +++++ engine/src/flutter/libs/minikin/Layout.cpp | 26 +++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 9b25f9234da..3f075896975 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -49,6 +49,12 @@ struct MinikinPaint { std::string fontFeatureSettings; }; +// Only a few flags affect layout, but those that do should have values +// consistent with Android's paint flags. +enum MinikinPaintFlags { + LinearTextFlag = 0x40, +}; + struct MinikinRect { float mLeft, mTop, mRight, mBottom; bool isEmpty() const { diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index c3d4c13e86f..fcae6cc51df 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -676,7 +676,14 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t double size = ctx->paint.size; double scaleX = ctx->paint.scaleX; double letterSpace = ctx->paint.letterSpacing * size * scaleX; - double letterSpaceHalf = letterSpace * .5; + double letterSpaceHalfLeft; + if ((ctx->paint.paintFlags & LinearTextFlag) == 0) { + letterSpace = round(letterSpace); + letterSpaceHalfLeft = floor(letterSpace * 0.5); + } else { + letterSpaceHalfLeft = letterSpace * 0.5; + } + double letterSpaceHalfRight = letterSpace - letterSpaceHalfLeft; float x = mAdvance; float y = 0; @@ -721,8 +728,8 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t hb_glyph_position_t* positions = hb_buffer_get_glyph_positions(buffer, NULL); if (numGlyphs) { - mAdvances[info[0].cluster - start] += letterSpaceHalf; - x += letterSpaceHalf; + mAdvances[info[0].cluster - start] += letterSpaceHalfLeft; + x += letterSpaceHalfLeft; } for (unsigned int i = 0; i < numGlyphs; i++) { #ifdef VERBOSE @@ -730,9 +737,9 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t ": " << HBFixedToFloat(positions[i].x_advance) << "; " << positions[i].x_offset << ", " << positions[i].y_offset << std::endl; #endif if (i > 0 && info[i - 1].cluster != info[i].cluster) { - mAdvances[info[i - 1].cluster - start] += letterSpaceHalf; - mAdvances[info[i].cluster - start] += letterSpaceHalf; - x += letterSpaceHalf; + mAdvances[info[i - 1].cluster - start] += letterSpaceHalfRight; + mAdvances[info[i].cluster - start] += letterSpaceHalfLeft; + x += letterSpace; } hb_codepoint_t glyph_ix = info[i].codepoint; @@ -742,6 +749,9 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t LayoutGlyph glyph = {font_ix, glyph_ix, x + xoff, y + yoff}; mGlyphs.push_back(glyph); float xAdvance = HBFixedToFloat(positions[i].x_advance); + if ((ctx->paint.paintFlags & LinearTextFlag) == 0) { + xAdvance = roundf(xAdvance); + } MinikinRect glyphBounds; ctx->paint.font->GetBounds(&glyphBounds, glyph_ix, ctx->paint); glyphBounds.offset(x + xoff, y + yoff); @@ -751,8 +761,8 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t } if (numGlyphs) { - mAdvances[info[numGlyphs - 1].cluster - start] += letterSpaceHalf; - x += letterSpaceHalf; + mAdvances[info[numGlyphs - 1].cluster - start] += letterSpaceHalfRight; + x += letterSpaceHalfRight; } } } From 6cba4a1dcae7ce1a359638405c3703b3cbb91277 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 22 Sep 2014 11:16:04 -0700 Subject: [PATCH 062/364] Fine-tune fake-bolding condition The old logic for fake bolding results in no fake bolding for a bold span on a light weight (300) because the target weight (600 in this case) didn't meet the condition. This patch fine-tunes the threshold to enable fake bolding for this. Bug: 17587185 Change-Id: I04abd00a74240cbed79c417f81486aa2158b2806 --- engine/src/flutter/libs/minikin/FontFamily.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index ab6ba20b3be..f688a33962c 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -141,11 +141,11 @@ static int computeMatch(FontStyle style1, FontStyle style2) { } static FontFakery computeFakery(FontStyle wanted, FontStyle actual) { - // If desired weight is bold or darker, and 2 or more grades higher - // than actual (for example, medium 500 -> bold 700), then select - // fake bold. + // If desired weight is semibold or darker, and 2 or more grades + // higher than actual (for example, medium 500 -> bold 700), then + // select fake bold. int wantedWeight = wanted.getWeight(); - bool isFakeBold = wantedWeight >= 7 && (wantedWeight - actual.getWeight()) >= 2; + bool isFakeBold = wantedWeight >= 6 && (wantedWeight - actual.getWeight()) >= 2; bool isFakeItalic = wanted.getItalic() && !actual.getItalic(); return FontFakery(isFakeBold, isFakeItalic); } From 92e8cc7071364e58b3d5642649f7032a63f389f7 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 23 Oct 2014 14:54:42 -0700 Subject: [PATCH 063/364] Silently ignore invalid rangeOffset values Some fonts contain a cmap segment for char 0xffff that contains an invalid rangeOffset. This was rejected by the existing code, which means the font is considered to have empty Unicode coverage. This patch just discards the invalid segment (consistent with OpenType Sanitizer), making the custom font display. Bug: 18106256 Change-Id: Icc8616a3030f80e62db906332be64d434ae72ea2 --- .../src/flutter/libs/minikin/CmapCoverage.cpp | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/engine/src/flutter/libs/minikin/CmapCoverage.cpp b/engine/src/flutter/libs/minikin/CmapCoverage.cpp index 4156d69d5a1..75033729e31 100644 --- a/engine/src/flutter/libs/minikin/CmapCoverage.cpp +++ b/engine/src/flutter/libs/minikin/CmapCoverage.cpp @@ -16,9 +16,8 @@ // Determine coverage of font given its raw "cmap" OpenType table -#ifdef PRINTF_DEBUG -#include -#endif +#define LOG_TAG "Minikin" +#include #include using std::vector; @@ -38,8 +37,8 @@ static uint32_t readU32(const uint8_t* data, size_t offset) { } static void addRange(vector &coverage, uint32_t start, uint32_t end) { -#ifdef PRINTF_DEBUG - printf("adding range %d-%d\n", start, end); +#ifdef VERBOSE_DEBUG + ALOGD("adding range %d-%d\n", start, end); #endif if (coverage.empty() || coverage.back() < start) { coverage.push_back(start); @@ -82,7 +81,8 @@ static bool getCoverageFormat4(vector& coverage, const uint8_t* data, uint32_t actualRangeOffset = kHeaderSize + 6 * segCount + rangeOffset + (i + j - start) * 2; if (actualRangeOffset + 2 > size) { - return false; + // invalid rangeOffset is considered a "warning" by OpenType Sanitizer + continue; } int glyphId = readU16(data, actualRangeOffset); if (glyphId != 0) { @@ -146,8 +146,8 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, bestTable = i; } } -#ifdef PRINTF_DEBUG - printf("best table = %d\n", bestTable); +#ifdef VERBOSE_DEBUG + ALOGD("best table = %d\n", bestTable); #endif if (bestTable < 0) { return false; @@ -168,10 +168,11 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, if (success) { coverage.initFromRanges(&coverageVec.front(), coverageVec.size() >> 1); } -#ifdef PRINTF_DEBUG - for (int i = 0; i < coverageVec.size(); i += 2) { - printf("%x:%x\n", coverageVec[i], coverageVec[i + 1]); +#ifdef VERBOSE_DEBUG + for (size_t i = 0; i < coverageVec.size(); i += 2) { + ALOGD("%x:%x\n", coverageVec[i], coverageVec[i + 1]); } + ALOGD("success = %d", success); #endif return success; } From 474b009ef443dbb82c1f93688613b9853ab1b396 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 29 Oct 2014 11:04:04 -0700 Subject: [PATCH 064/364] Move coverage bitmap from FontCollection to FontFamily This will significantly reduce memory usage and also speed the creation of new font families. In particular, the coverage bitmaps for the fonts in the fallback stack will be computed once in the Zygote, rather than separately in each app process. Bug: 17756900 Change-Id: I66f5706bddd4658d78fe5b709f7251ca9d2ff4f8 --- .../flutter/include/minikin/FontCollection.h | 12 +-- .../src/flutter/include/minikin/FontFamily.h | 7 ++ .../flutter/libs/minikin/FontCollection.cpp | 83 +++++++------------ .../src/flutter/libs/minikin/FontFamily.cpp | 21 +++++ 4 files changed, 63 insertions(+), 60 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 12700c6ebe2..ffdb4d18196 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -21,7 +21,6 @@ #include #include -#include #include namespace android { @@ -52,17 +51,12 @@ private: static const int kLogCharsPerPage = 8; static const int kPageMask = (1 << kLogCharsPerPage) - 1; - struct FontInstance { - SparseBitSet* mCoverage; - FontFamily* mFamily; - }; - struct Range { size_t start; size_t end; }; - const FontInstance* getInstanceForChar(uint32_t ch, FontLanguage lang, int variant) const; + FontFamily* getFamilyForChar(uint32_t ch, FontLanguage lang, int variant) const; // static for allocating unique id's static uint32_t sNextId; @@ -74,10 +68,10 @@ private: uint32_t mMaxChar; // This vector has ownership of the bitsets and typeface objects. - std::vector mInstances; + std::vector mFamilies; // This vector contains pointers into mInstances - std::vector mInstanceVec; + std::vector mFamilyVec; // These are offsets into mInstanceVec, one range per page std::vector mRanges; diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index bcc2e3a59c0..08c7a2c9871 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -23,6 +23,7 @@ #include #include +#include namespace android { @@ -139,6 +140,9 @@ public: size_t getNumFonts() const; MinikinFont* getFont(size_t index) const; FontStyle getStyle(size_t index) const; + + // Get Unicode coverage. Lifetime of returned bitset is same as receiver. + const SparseBitSet* getCoverage(); private: void addFontLocked(MinikinFont* typeface, FontStyle style); @@ -152,6 +156,9 @@ private: FontLanguage mLang; int mVariant; std::vector mFonts; + + SparseBitSet mCoverage; + bool mCoverageValid; }; } // namespace android diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index ca5b1d1ab36..7b6b9507875 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -23,7 +23,6 @@ #include "unicode/unorm2.h" #include "MinikinInternal.h" -#include #include using std::vector; @@ -54,28 +53,12 @@ FontCollection::FontCollection(const vector& typefaces) : continue; } family->RefLocked(); - FontInstance dummy; - mInstances.push_back(dummy); // emplace_back would be better - FontInstance* instance = &mInstances.back(); - instance->mFamily = family; - instance->mCoverage = new SparseBitSet; -#ifdef VERBOSE_DEBUG - ALOGD("closest match = %p, family size = %d\n", typeface, family->getNumFonts()); -#endif - const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); - size_t cmapSize = 0; - bool ok = typeface->GetTable(cmapTag, NULL, &cmapSize); - UniquePtr cmapData(new uint8_t[cmapSize]); - ok = typeface->GetTable(cmapTag, cmapData.get(), &cmapSize); - CmapCoverage::getCoverage(*instance->mCoverage, cmapData.get(), cmapSize); -#ifdef VERBOSE_DEBUG - ALOGD("font coverage length=%d, first ch=%x\n", instance->mCoverage->length(), - instance->mCoverage->nextSetBit(0)); -#endif - mMaxChar = max(mMaxChar, instance->mCoverage->length()); - lastChar.push_back(instance->mCoverage->nextSetBit(0)); + mFamilies.push_back(family); // emplace_back would be better + const SparseBitSet* coverage = family->getCoverage(); + mMaxChar = max(mMaxChar, coverage->length()); + lastChar.push_back(coverage->nextSetBit(0)); } - nTypefaces = mInstances.size(); + nTypefaces = mFamilies.size(); LOG_ALWAYS_FATAL_IF(nTypefaces == 0, "Font collection must have at least one valid typeface"); size_t nPages = (mMaxChar + kPageMask) >> kLogCharsPerPage; @@ -90,10 +73,10 @@ FontCollection::FontCollection(const vector& typefaces) : range->start = offset; for (size_t j = 0; j < nTypefaces; j++) { if (lastChar[j] < (i + 1) << kLogCharsPerPage) { - const FontInstance* instance = &mInstances[j]; - mInstanceVec.push_back(instance); + FontFamily* family = mFamilies[j]; + mFamilyVec.push_back(family); offset++; - uint32_t nextChar = instance->mCoverage->nextSetBit((i + 1) << kLogCharsPerPage); + uint32_t nextChar = family->getCoverage()->nextSetBit((i + 1) << kLogCharsPerPage); #ifdef VERBOSE_DEBUG ALOGD("nextChar = %d (j = %d)\n", nextChar, j); #endif @@ -105,9 +88,8 @@ FontCollection::FontCollection(const vector& typefaces) : } FontCollection::~FontCollection() { - for (size_t i = 0; i < mInstances.size(); i++) { - delete mInstances[i].mCoverage; - mInstances[i].mFamily->UnrefLocked(); + for (size_t i = 0; i < mFamilies.size(); i++) { + mFamilies[i]->UnrefLocked(); } } @@ -117,7 +99,7 @@ FontCollection::~FontCollection() { // 3. If a font matches just language, it gets a score of 2. // 4. Matching the "compact" or "elegant" variant adds one to the score. // 5. Highest score wins, with ties resolved to the first font. -const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t ch, +FontFamily* FontCollection::getFamilyForChar(uint32_t ch, FontLanguage lang, int variant) const { if (ch >= mMaxChar) { return NULL; @@ -126,15 +108,14 @@ const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t #ifdef VERBOSE_DEBUG ALOGD("querying range %d:%d\n", range.start, range.end); #endif - const FontInstance* bestInstance = NULL; + FontFamily* bestFamily = NULL; int bestScore = -1; for (size_t i = range.start; i < range.end; i++) { - const FontInstance* instance = mInstanceVec[i]; - if (instance->mCoverage->get(ch)) { - FontFamily* family = instance->mFamily; + FontFamily* family = mFamilyVec[i]; + if (family->getCoverage()->get(ch)) { // First font family in collection always matches - if (mInstances[0].mFamily == family) { - return instance; + if (mFamilies[0] == family) { + return family; } int score = lang.match(family->lang()) * 2; if (variant != 0 && variant == family->variant()) { @@ -142,11 +123,11 @@ const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t } if (score > bestScore) { bestScore = score; - bestInstance = instance; + bestFamily = family; } } } - if (bestInstance == NULL && !mInstanceVec.empty()) { + if (bestFamily == NULL && !mFamilyVec.empty()) { UErrorCode errorCode = U_ZERO_ERROR; const UNormalizer2* normalizer = unorm2_getNFDInstance(&errorCode); if (U_SUCCESS(errorCode)) { @@ -155,12 +136,12 @@ const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t if (U_SUCCESS(errorCode) && len > 0) { int off = 0; U16_NEXT_UNSAFE(decomposed, off, ch); - return getInstanceForChar(ch, lang, variant); + return getFamilyForChar(ch, lang, variant); } } - bestInstance = &mInstances[0]; + bestFamily = mFamilies[0]; } - return bestInstance; + return bestFamily; } const uint32_t NBSP = 0xa0; @@ -183,7 +164,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty vector* result) const { FontLanguage lang = style.getLanguage(); int variant = style.getVariant(); - const FontInstance* lastInstance = NULL; + FontFamily* lastFamily = NULL; Run* run = NULL; int nShorts; for (size_t i = 0; i < string_size; i += nShorts) { @@ -197,17 +178,17 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } } // Continue using existing font as long as it has coverage and is whitelisted - if (lastInstance == NULL - || !(isStickyWhitelisted(ch) && lastInstance->mCoverage->get(ch))) { - const FontInstance* instance = getInstanceForChar(ch, lang, variant); - if (i == 0 || instance != lastInstance) { + if (lastFamily == NULL + || !(isStickyWhitelisted(ch) && lastFamily->getCoverage()->get(ch))) { + FontFamily* family = getFamilyForChar(ch, lang, variant); + if (i == 0 || family != lastFamily) { size_t start = i; // Workaround for Emoji keycap until we implement per-cluster font // selection: if keycap is found in a different font that also // supports previous char, attach previous char to the new run. // Only handles non-surrogate characters. // Bug 7557244. - if (ch == KEYCAP && i && instance && instance->mCoverage->get(string[i - 1])) { + if (ch == KEYCAP && i && family && family->getCoverage()->get(string[i - 1])) { run->end--; if (run->start == run->end) { result->pop_back(); @@ -217,12 +198,12 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty Run dummy; result->push_back(dummy); run = &result->back(); - if (instance == NULL) { + if (family == NULL) { run->fakedFont.font = NULL; } else { - run->fakedFont = instance->mFamily->getClosestMatch(style); + run->fakedFont = family->getClosestMatch(style); } - lastInstance = instance; + lastFamily = family; run->start = start; } } @@ -235,10 +216,10 @@ MinikinFont* FontCollection::baseFont(FontStyle style) { } FakedFont FontCollection::baseFontFaked(FontStyle style) { - if (mInstances.empty()) { + if (mFamilies.empty()) { return FakedFont(); } - return mInstances[0].mFamily->getClosestMatch(style); + return mFamilies[0]->getClosestMatch(style); } uint32_t FontCollection::getId() const { diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index f688a33962c..d2e5867cdd3 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -23,6 +23,7 @@ #include "MinikinInternal.h" #include #include +#include #include #include @@ -128,6 +129,7 @@ void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { typeface->RefLocked(); mFonts.push_back(Font(typeface, style)); + mCoverageValid = false; } // Compute a matching metric between two styles - 0 is an exact match @@ -183,4 +185,23 @@ FontStyle FontFamily::getStyle(size_t index) const { return mFonts[index].style; } +const SparseBitSet* FontFamily::getCoverage() { + if (!mCoverageValid) { + const FontStyle defaultStyle; + MinikinFont* typeface = getClosestMatch(defaultStyle).font; + const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); + size_t cmapSize = 0; + bool ok = typeface->GetTable(cmapTag, NULL, &cmapSize); + UniquePtr cmapData(new uint8_t[cmapSize]); + ok = typeface->GetTable(cmapTag, cmapData.get(), &cmapSize); + CmapCoverage::getCoverage(mCoverage, cmapData.get(), cmapSize); +#ifdef VERBOSE_DEBUG + ALOGD("font coverage length=%d, first ch=%x\n", mCoverage->length(), + mCoverage->nextSetBit(0)); +#endif + mCoverageValid = true; + } + return &mCoverage; +} + } // namespace android From a4e238f757417c13e688f69f49eed4db168dc6c9 Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Tue, 11 Nov 2014 19:32:48 -0800 Subject: [PATCH 065/364] Move frameworks/minikin over to libc++. Bug: 15193147 Change-Id: I5e15c95415c39515340e2663acd5fd26666db720 --- engine/src/flutter/libs/minikin/Android.mk | 2 -- engine/src/flutter/libs/minikin/Layout.cpp | 8 +++++--- engine/src/flutter/sample/Android.mk | 4 ---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 386dc2bee1c..60a46efcf97 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -15,7 +15,6 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -include external/stlport/libstlport.mk LOCAL_SRC_FILES := \ AnalyzeStyle.cpp \ @@ -43,7 +42,6 @@ LOCAL_SHARED_LIBRARIES := \ liblog \ libpng \ libz \ - libstlport \ libicuuc \ libutils diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index fcae6cc51df..fa7770138c0 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -17,12 +17,14 @@ #define LOG_TAG "Minikin" #include -#include -#include +#include +#include // for debugging + #include #include #include // for debugging -#include // ditto +#include +#include #include #include diff --git a/engine/src/flutter/sample/Android.mk b/engine/src/flutter/sample/Android.mk index ec06e3852ae..101a413cae4 100644 --- a/engine/src/flutter/sample/Android.mk +++ b/engine/src/flutter/sample/Android.mk @@ -15,7 +15,6 @@ LOCAL_PATH:= $(call my-dir) include $(CLEAR_VARS) -include external/stlport/libstlport.mk LOCAL_MODULE_TAGS := tests @@ -31,7 +30,6 @@ LOCAL_SHARED_LIBRARIES += \ libutils \ liblog \ libcutils \ - libstlport \ libharfbuzz_ng \ libicuuc \ libft2 \ @@ -45,7 +43,6 @@ include $(BUILD_EXECUTABLE) include $(CLEAR_VARS) -include external/stlport/libstlport.mk LOCAL_MODULE_TAG := tests @@ -63,7 +60,6 @@ LOCAL_SHARED_LIBRARIES += \ libutils \ liblog \ libcutils \ - libstlport \ libharfbuzz_ng \ libicuuc \ libskia \ From 477b5d2cdbbc7c8115d5fcf441ea25cedc48d08c Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 29 Oct 2014 11:04:04 -0700 Subject: [PATCH 066/364] Move coverage bitmap from FontCollection to FontFamily This will significantly reduce memory usage and also speed the creation of new font families. In particular, the coverage bitmaps for the fonts in the fallback stack will be computed once in the Zygote, rather than separately in each app process. Bug: 17756900 Change-Id: I66f5706bddd4658d78fe5b709f7251ca9d2ff4f8 --- .../flutter/include/minikin/FontCollection.h | 12 +-- .../src/flutter/include/minikin/FontFamily.h | 7 ++ .../flutter/libs/minikin/FontCollection.cpp | 83 +++++++------------ .../src/flutter/libs/minikin/FontFamily.cpp | 21 +++++ 4 files changed, 63 insertions(+), 60 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 12700c6ebe2..ffdb4d18196 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -21,7 +21,6 @@ #include #include -#include #include namespace android { @@ -52,17 +51,12 @@ private: static const int kLogCharsPerPage = 8; static const int kPageMask = (1 << kLogCharsPerPage) - 1; - struct FontInstance { - SparseBitSet* mCoverage; - FontFamily* mFamily; - }; - struct Range { size_t start; size_t end; }; - const FontInstance* getInstanceForChar(uint32_t ch, FontLanguage lang, int variant) const; + FontFamily* getFamilyForChar(uint32_t ch, FontLanguage lang, int variant) const; // static for allocating unique id's static uint32_t sNextId; @@ -74,10 +68,10 @@ private: uint32_t mMaxChar; // This vector has ownership of the bitsets and typeface objects. - std::vector mInstances; + std::vector mFamilies; // This vector contains pointers into mInstances - std::vector mInstanceVec; + std::vector mFamilyVec; // These are offsets into mInstanceVec, one range per page std::vector mRanges; diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index bcc2e3a59c0..08c7a2c9871 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -23,6 +23,7 @@ #include #include +#include namespace android { @@ -139,6 +140,9 @@ public: size_t getNumFonts() const; MinikinFont* getFont(size_t index) const; FontStyle getStyle(size_t index) const; + + // Get Unicode coverage. Lifetime of returned bitset is same as receiver. + const SparseBitSet* getCoverage(); private: void addFontLocked(MinikinFont* typeface, FontStyle style); @@ -152,6 +156,9 @@ private: FontLanguage mLang; int mVariant; std::vector mFonts; + + SparseBitSet mCoverage; + bool mCoverageValid; }; } // namespace android diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index ca5b1d1ab36..7b6b9507875 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -23,7 +23,6 @@ #include "unicode/unorm2.h" #include "MinikinInternal.h" -#include #include using std::vector; @@ -54,28 +53,12 @@ FontCollection::FontCollection(const vector& typefaces) : continue; } family->RefLocked(); - FontInstance dummy; - mInstances.push_back(dummy); // emplace_back would be better - FontInstance* instance = &mInstances.back(); - instance->mFamily = family; - instance->mCoverage = new SparseBitSet; -#ifdef VERBOSE_DEBUG - ALOGD("closest match = %p, family size = %d\n", typeface, family->getNumFonts()); -#endif - const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); - size_t cmapSize = 0; - bool ok = typeface->GetTable(cmapTag, NULL, &cmapSize); - UniquePtr cmapData(new uint8_t[cmapSize]); - ok = typeface->GetTable(cmapTag, cmapData.get(), &cmapSize); - CmapCoverage::getCoverage(*instance->mCoverage, cmapData.get(), cmapSize); -#ifdef VERBOSE_DEBUG - ALOGD("font coverage length=%d, first ch=%x\n", instance->mCoverage->length(), - instance->mCoverage->nextSetBit(0)); -#endif - mMaxChar = max(mMaxChar, instance->mCoverage->length()); - lastChar.push_back(instance->mCoverage->nextSetBit(0)); + mFamilies.push_back(family); // emplace_back would be better + const SparseBitSet* coverage = family->getCoverage(); + mMaxChar = max(mMaxChar, coverage->length()); + lastChar.push_back(coverage->nextSetBit(0)); } - nTypefaces = mInstances.size(); + nTypefaces = mFamilies.size(); LOG_ALWAYS_FATAL_IF(nTypefaces == 0, "Font collection must have at least one valid typeface"); size_t nPages = (mMaxChar + kPageMask) >> kLogCharsPerPage; @@ -90,10 +73,10 @@ FontCollection::FontCollection(const vector& typefaces) : range->start = offset; for (size_t j = 0; j < nTypefaces; j++) { if (lastChar[j] < (i + 1) << kLogCharsPerPage) { - const FontInstance* instance = &mInstances[j]; - mInstanceVec.push_back(instance); + FontFamily* family = mFamilies[j]; + mFamilyVec.push_back(family); offset++; - uint32_t nextChar = instance->mCoverage->nextSetBit((i + 1) << kLogCharsPerPage); + uint32_t nextChar = family->getCoverage()->nextSetBit((i + 1) << kLogCharsPerPage); #ifdef VERBOSE_DEBUG ALOGD("nextChar = %d (j = %d)\n", nextChar, j); #endif @@ -105,9 +88,8 @@ FontCollection::FontCollection(const vector& typefaces) : } FontCollection::~FontCollection() { - for (size_t i = 0; i < mInstances.size(); i++) { - delete mInstances[i].mCoverage; - mInstances[i].mFamily->UnrefLocked(); + for (size_t i = 0; i < mFamilies.size(); i++) { + mFamilies[i]->UnrefLocked(); } } @@ -117,7 +99,7 @@ FontCollection::~FontCollection() { // 3. If a font matches just language, it gets a score of 2. // 4. Matching the "compact" or "elegant" variant adds one to the score. // 5. Highest score wins, with ties resolved to the first font. -const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t ch, +FontFamily* FontCollection::getFamilyForChar(uint32_t ch, FontLanguage lang, int variant) const { if (ch >= mMaxChar) { return NULL; @@ -126,15 +108,14 @@ const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t #ifdef VERBOSE_DEBUG ALOGD("querying range %d:%d\n", range.start, range.end); #endif - const FontInstance* bestInstance = NULL; + FontFamily* bestFamily = NULL; int bestScore = -1; for (size_t i = range.start; i < range.end; i++) { - const FontInstance* instance = mInstanceVec[i]; - if (instance->mCoverage->get(ch)) { - FontFamily* family = instance->mFamily; + FontFamily* family = mFamilyVec[i]; + if (family->getCoverage()->get(ch)) { // First font family in collection always matches - if (mInstances[0].mFamily == family) { - return instance; + if (mFamilies[0] == family) { + return family; } int score = lang.match(family->lang()) * 2; if (variant != 0 && variant == family->variant()) { @@ -142,11 +123,11 @@ const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t } if (score > bestScore) { bestScore = score; - bestInstance = instance; + bestFamily = family; } } } - if (bestInstance == NULL && !mInstanceVec.empty()) { + if (bestFamily == NULL && !mFamilyVec.empty()) { UErrorCode errorCode = U_ZERO_ERROR; const UNormalizer2* normalizer = unorm2_getNFDInstance(&errorCode); if (U_SUCCESS(errorCode)) { @@ -155,12 +136,12 @@ const FontCollection::FontInstance* FontCollection::getInstanceForChar(uint32_t if (U_SUCCESS(errorCode) && len > 0) { int off = 0; U16_NEXT_UNSAFE(decomposed, off, ch); - return getInstanceForChar(ch, lang, variant); + return getFamilyForChar(ch, lang, variant); } } - bestInstance = &mInstances[0]; + bestFamily = mFamilies[0]; } - return bestInstance; + return bestFamily; } const uint32_t NBSP = 0xa0; @@ -183,7 +164,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty vector* result) const { FontLanguage lang = style.getLanguage(); int variant = style.getVariant(); - const FontInstance* lastInstance = NULL; + FontFamily* lastFamily = NULL; Run* run = NULL; int nShorts; for (size_t i = 0; i < string_size; i += nShorts) { @@ -197,17 +178,17 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } } // Continue using existing font as long as it has coverage and is whitelisted - if (lastInstance == NULL - || !(isStickyWhitelisted(ch) && lastInstance->mCoverage->get(ch))) { - const FontInstance* instance = getInstanceForChar(ch, lang, variant); - if (i == 0 || instance != lastInstance) { + if (lastFamily == NULL + || !(isStickyWhitelisted(ch) && lastFamily->getCoverage()->get(ch))) { + FontFamily* family = getFamilyForChar(ch, lang, variant); + if (i == 0 || family != lastFamily) { size_t start = i; // Workaround for Emoji keycap until we implement per-cluster font // selection: if keycap is found in a different font that also // supports previous char, attach previous char to the new run. // Only handles non-surrogate characters. // Bug 7557244. - if (ch == KEYCAP && i && instance && instance->mCoverage->get(string[i - 1])) { + if (ch == KEYCAP && i && family && family->getCoverage()->get(string[i - 1])) { run->end--; if (run->start == run->end) { result->pop_back(); @@ -217,12 +198,12 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty Run dummy; result->push_back(dummy); run = &result->back(); - if (instance == NULL) { + if (family == NULL) { run->fakedFont.font = NULL; } else { - run->fakedFont = instance->mFamily->getClosestMatch(style); + run->fakedFont = family->getClosestMatch(style); } - lastInstance = instance; + lastFamily = family; run->start = start; } } @@ -235,10 +216,10 @@ MinikinFont* FontCollection::baseFont(FontStyle style) { } FakedFont FontCollection::baseFontFaked(FontStyle style) { - if (mInstances.empty()) { + if (mFamilies.empty()) { return FakedFont(); } - return mInstances[0].mFamily->getClosestMatch(style); + return mFamilies[0]->getClosestMatch(style); } uint32_t FontCollection::getId() const { diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index f688a33962c..d2e5867cdd3 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -23,6 +23,7 @@ #include "MinikinInternal.h" #include #include +#include #include #include @@ -128,6 +129,7 @@ void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { typeface->RefLocked(); mFonts.push_back(Font(typeface, style)); + mCoverageValid = false; } // Compute a matching metric between two styles - 0 is an exact match @@ -183,4 +185,23 @@ FontStyle FontFamily::getStyle(size_t index) const { return mFonts[index].style; } +const SparseBitSet* FontFamily::getCoverage() { + if (!mCoverageValid) { + const FontStyle defaultStyle; + MinikinFont* typeface = getClosestMatch(defaultStyle).font; + const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); + size_t cmapSize = 0; + bool ok = typeface->GetTable(cmapTag, NULL, &cmapSize); + UniquePtr cmapData(new uint8_t[cmapSize]); + ok = typeface->GetTable(cmapTag, cmapData.get(), &cmapSize); + CmapCoverage::getCoverage(mCoverage, cmapData.get(), cmapSize); +#ifdef VERBOSE_DEBUG + ALOGD("font coverage length=%d, first ch=%x\n", mCoverage->length(), + mCoverage->nextSetBit(0)); +#endif + mCoverageValid = true; + } + return &mCoverage; +} + } // namespace android From faf26d176f220c5fa00c20085b764346c998405e Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Mon, 24 Nov 2014 18:35:14 -0800 Subject: [PATCH 067/364] Minikin: Remove unused variables, fix init order For build-system CFLAGS clean-up, fix unused variables. Reorder initializer list to initialize in the order of member declarations. Change-Id: I64358b2dcf0e39d0f4e18fdc3473de867f84fcba --- engine/src/flutter/include/minikin/FontFamily.h | 3 ++- engine/src/flutter/libs/minikin/FontCollection.cpp | 6 +++++- engine/src/flutter/libs/minikin/FontFamily.cpp | 14 +++++++++++--- engine/src/flutter/libs/minikin/Layout.cpp | 6 +++--- .../flutter/libs/minikin/MinikinFontFreeType.cpp | 2 +- engine/src/flutter/sample/example_skia.cpp | 3 --- 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 08c7a2c9871..7bdff6eb4ff 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -141,7 +141,8 @@ public: MinikinFont* getFont(size_t index) const; FontStyle getStyle(size_t index) const; - // Get Unicode coverage. Lifetime of returned bitset is same as receiver. + // Get Unicode coverage. Lifetime of returned bitset is same as receiver. May return nullptr on + // error. const SparseBitSet* getCoverage(); private: void addFontLocked(MinikinFont* typeface, FontStyle style); diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 7b6b9507875..e3911c5bd3f 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -53,8 +53,12 @@ FontCollection::FontCollection(const vector& typefaces) : continue; } family->RefLocked(); - mFamilies.push_back(family); // emplace_back would be better const SparseBitSet* coverage = family->getCoverage(); + if (coverage == nullptr) { + family->UnrefLocked(); + continue; + } + mFamilies.push_back(family); // emplace_back would be better mMaxChar = max(mMaxChar, coverage->length()); lastChar.push_back(coverage->nextSetBit(0)); } diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index d2e5867cdd3..da7320bce5d 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -191,10 +191,18 @@ const SparseBitSet* FontFamily::getCoverage() { MinikinFont* typeface = getClosestMatch(defaultStyle).font; const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); size_t cmapSize = 0; - bool ok = typeface->GetTable(cmapTag, NULL, &cmapSize); + if (!typeface->GetTable(cmapTag, NULL, &cmapSize)) { + ALOGE("Could not get cmap table size!\n"); + // Note: This means we will retry on the next call to getCoverage, as we can't store + // the failure. This is fine, as we assume this doesn't really happen in practice. + return nullptr; + } UniquePtr cmapData(new uint8_t[cmapSize]); - ok = typeface->GetTable(cmapTag, cmapData.get(), &cmapSize); - CmapCoverage::getCoverage(mCoverage, cmapData.get(), cmapSize); + if (!typeface->GetTable(cmapTag, cmapData.get(), &cmapSize)) { + ALOGE("Unexpected failure to read cmap table!\n"); + return nullptr; + } + CmapCoverage::getCoverage(mCoverage, cmapData.get(), cmapSize); // TODO: Error check? #ifdef VERBOSE_DEBUG ALOGD("font coverage length=%d, first ch=%x\n", mCoverage->length(), mCoverage->nextSetBit(0)); diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index fa7770138c0..db0667b09aa 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -77,11 +77,11 @@ class LayoutCacheKey { public: LayoutCacheKey(const FontCollection* collection, const MinikinPaint& paint, FontStyle style, const uint16_t* chars, size_t start, size_t count, size_t nchars, bool dir) - : mStart(start), mCount(count), mId(collection->getId()), mStyle(style), + : mChars(chars), mNchars(nchars), + mStart(start), mCount(count), mId(collection->getId()), mStyle(style), mSize(paint.size), mScaleX(paint.scaleX), mSkewX(paint.skewX), mLetterSpacing(paint.letterSpacing), - mPaintFlags(paint.paintFlags), mIsRtl(dir), - mChars(chars), mNchars(nchars) { + mPaintFlags(paint.paintFlags), mIsRtl(dir) { } bool operator==(const LayoutCacheKey &other) const; hash_t hash() const; diff --git a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp index a251ddadbf1..972f3f1d14f 100644 --- a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp @@ -49,7 +49,7 @@ float MinikinFontFreeType::GetHorizontalAdvance(uint32_t glyph_id, FT_Set_Pixel_Sizes(mTypeface, 0, paint.size); FT_UInt32 flags = FT_LOAD_DEFAULT; // TODO: respect hinting settings FT_Fixed advance; - FT_Error error = FT_Get_Advance(mTypeface, glyph_id, flags, &advance); + FT_Get_Advance(mTypeface, glyph_id, flags, &advance); return advance * (1.0 / 65536); } diff --git a/engine/src/flutter/sample/example_skia.cpp b/engine/src/flutter/sample/example_skia.cpp index 51fcf47e58a..f892b8c987a 100644 --- a/engine/src/flutter/sample/example_skia.cpp +++ b/engine/src/flutter/sample/example_skia.cpp @@ -55,8 +55,6 @@ FontCollection *makeFontCollection() { }; FontFamily *family = new FontFamily(); - FT_Face face; - FT_Error error; for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) { const char *fn = fns[i]; SkTypeface *skFace = SkTypeface::CreateFromFile(fn); @@ -118,7 +116,6 @@ int runMinikinTest() { Layout layout; layout.setFontCollection(collection); const char *text = "fine world \xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa5\x87"; - const char *style = "font-size: 32; font-weight: 700;"; int bidiFlags = 0; FontStyle fontStyle(7); MinikinPaint minikinPaint; From 65866430cf310c8711d77b2feff70a25006cb948 Mon Sep 17 00:00:00 2001 From: Narayan Kamath Date: Mon, 5 Jan 2015 11:44:09 +0000 Subject: [PATCH 068/364] Remove hardcoded ICU include paths. ICU exports them using LOCAL_EXPORT_C_INCLUDE_DIRS. bug: 18581021 Change-Id: Ia57b3b4d231966203274b0e7e7b850beb1bd11c0 --- engine/src/flutter/libs/minikin/Android.mk | 1 - engine/src/flutter/sample/Android.mk | 2 -- 2 files changed, 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 60a46efcf97..d9c973d97f4 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -33,7 +33,6 @@ LOCAL_MODULE := libminikin LOCAL_C_INCLUDES += \ external/harfbuzz_ng/src \ external/freetype/include \ - external/icu/icu4c/source/common \ frameworks/minikin/include LOCAL_SHARED_LIBRARIES := \ diff --git a/engine/src/flutter/sample/Android.mk b/engine/src/flutter/sample/Android.mk index 101a413cae4..c4a644d74d5 100644 --- a/engine/src/flutter/sample/Android.mk +++ b/engine/src/flutter/sample/Android.mk @@ -21,7 +21,6 @@ LOCAL_MODULE_TAGS := tests LOCAL_C_INCLUDES += \ external/harfbuzz_ng/src \ external/freetype/include \ - external/icu/icu4c/source/common \ frameworks/minikin/include LOCAL_SRC_FILES:= example.cpp @@ -49,7 +48,6 @@ LOCAL_MODULE_TAG := tests LOCAL_C_INCLUDES += \ external/harfbuzz_ng/src \ external/freetype/include \ - external/icu/icu4c/source/common \ frameworks/minikin/include \ external/skia/src/core From 4c4af7f4dc0723f5340bf3b589805d883ea39df8 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 25 Feb 2015 11:56:34 -0800 Subject: [PATCH 069/364] Disable HarfBuzz's fallback to compatibility decompositions Previously, HarfBuzz's default fallback to compatibility decompositions resulted in Mathematical Alphanumeric Symbols getting rendered as normal letters and digits when there was no font available to render them. This patch disables that fallback, to ensure they are displayed as tofus. Based on a patch by Behdad Esfahbod. Bug: 19202569 Change-Id: I357f172302448d4ab0b24efc86119f1977b5996b --- engine/src/flutter/libs/minikin/Layout.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 344766a5ec4..375f61d54f2 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -173,13 +173,24 @@ private: static const size_t kMaxEntries = 100; }; +static unsigned int disabledDecomposeCompatibility(hb_unicode_funcs_t*, hb_codepoint_t, + hb_codepoint_t*, void*) { + return 0; +} + class LayoutEngine : public Singleton { public: LayoutEngine() { + unicodeFunctions = hb_unicode_funcs_create(hb_icu_get_unicode_funcs()); + /* Disable the function used for compatibility decomposition */ + hb_unicode_funcs_set_decompose_compatibility_func( + unicodeFunctions, disabledDecomposeCompatibility, NULL, NULL); hbBuffer = hb_buffer_create(); + hb_buffer_set_unicode_funcs(hbBuffer, unicodeFunctions); } hb_buffer_t* hbBuffer; + hb_unicode_funcs_t* unicodeFunctions; LayoutCache layoutCache; HbFaceCache hbFaceCache; }; @@ -402,7 +413,7 @@ int Layout::findFace(FakedFont face, LayoutContext* ctx) { static hb_script_t codePointToScript(hb_codepoint_t codepoint) { static hb_unicode_funcs_t* u = 0; if (!u) { - u = hb_icu_get_unicode_funcs(); + u = LayoutEngine::getInstance().unicodeFunctions; } return hb_unicode_script(u, codepoint); } @@ -709,7 +720,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t srunend = srunstart; hb_script_t script = getScriptRun(buf + start, run.end, &srunend); - hb_buffer_reset(buffer); + hb_buffer_clear_contents(buffer); hb_buffer_set_script(buffer, script); hb_buffer_set_direction(buffer, isRtl? HB_DIRECTION_RTL : HB_DIRECTION_LTR); FontLanguage language = ctx->style.getLanguage(); From aa1337a41a1da0d7472240dc04fd6431c1f37a90 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 29 Jan 2015 16:28:37 -0800 Subject: [PATCH 070/364] HyphenEdit in support of hyphenation Adds a "HyphenEdit" field to the Minikin Paint object, which represents an edit to the text to add a hyphen (and, in the future, other edits to support nonstandard hyphenation). Change-Id: Ib4ee690b0fe2137e1d1e2c9251e5526b274ec3a7 --- .../src/flutter/include/minikin/MinikinFont.h | 16 +++++++++++++++- engine/src/flutter/libs/minikin/Layout.cpp | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 3f075896975..ee885f497c4 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -27,6 +27,18 @@ namespace android { +// The hyphen edit represents an edit to the string when a word is +// hyphenated. The most common hyphen edit is adding a "-" at the end +// of a syllable, but nonstandard hyphenation allows for more choices. +class HyphenEdit { +public: + HyphenEdit() : hyphen(0) { } + HyphenEdit(uint32_t hyphenInt) : hyphen(hyphenInt) { } + bool hasHyphen() const { return hyphen != 0; } +private: + uint32_t hyphen; +}; + class MinikinFont; // Possibly move into own .h file? @@ -36,7 +48,8 @@ struct MinikinPaint { fakery(), fontFeatureSettings() { } bool skipCache() const { - return !fontFeatureSettings.empty(); + // TODO: add hyphen to cache + return !fontFeatureSettings.empty() || hyphenEdit.hasHyphen(); } MinikinFont *font; @@ -46,6 +59,7 @@ struct MinikinPaint { float letterSpacing; uint32_t paintFlags; FontFakery fakery; + HyphenEdit hyphenEdit; std::string fontFeatureSettings; }; diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 375f61d54f2..8e5e546283e 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -594,12 +594,15 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu void Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, bool isRtl, LayoutContext* ctx, size_t dstStart) { + HyphenEdit hyphen = ctx->paint.hyphenEdit; if (!isRtl) { // left to right size_t wordstart = start == bufSize ? start : getPrevWordBreak(buf, start + 1); size_t wordend; for (size_t iter = start; iter < start + count; iter = wordend) { wordend = getNextWordBreak(buf, iter, bufSize); + // Only apply hyphen to the last word in the string. + ctx->paint.hyphenEdit = wordend >= start + count ? hyphen : HyphenEdit(); size_t wordcount = std::min(start + count, wordend) - iter; doLayoutWord(buf + wordstart, iter - wordstart, wordcount, wordend - wordstart, isRtl, ctx, iter - dstStart); @@ -612,6 +615,8 @@ void Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t wordend = end == 0 ? 0 : getNextWordBreak(buf, end - 1, bufSize); for (size_t iter = end; iter > start; iter = wordstart) { wordstart = getPrevWordBreak(buf, iter); + // Only apply hyphen to the last (leftmost) word in the string. + ctx->paint.hyphenEdit = iter == end ? hyphen : HyphenEdit(); size_t bufStart = std::max(start, wordstart); doLayoutWord(buf + wordstart, bufStart - wordstart, iter - bufStart, wordend - wordstart, isRtl, ctx, bufStart - dstStart); @@ -729,6 +734,12 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t hb_buffer_set_language(buffer, hb_language_from_string(lang.c_str(), -1)); } hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart); + if (ctx->paint.hyphenEdit.hasHyphen() && srunend > srunstart) { + // TODO: check whether this is really the desired semantics. It could have the + // effect of assigning the hyphen width to a nonspacing mark + unsigned int lastCluster = srunend - 1; + hb_buffer_add(buffer, 0x2010, lastCluster); + } hb_shape(hbFont, buffer, features.empty() ? NULL : &features[0], features.size()); unsigned int numGlyphs; hb_glyph_info_t* info = hb_buffer_get_glyph_infos(buffer, &numGlyphs); @@ -763,7 +774,12 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t ctx->paint.font->GetBounds(&glyphBounds, glyph_ix, ctx->paint); glyphBounds.offset(x + xoff, y + yoff); mBounds.join(glyphBounds); - mAdvances[info[i].cluster - start] += xAdvance; + if (info[i].cluster - start < count) { + mAdvances[info[i].cluster - start] += xAdvance; + } else { + ALOGE("cluster %d (start %d) out of bounds of count %d", + info[i].cluster - start, start, count); + } x += xAdvance; } if (numGlyphs) From e65751d7284391c76fb6a26c03c08d20bdad5a56 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 13 Mar 2015 20:36:53 -0700 Subject: [PATCH 071/364] Add LineBreaker to Minikin This patch adds a LineBreaker class to Minikin, which will be used for computing line breaks in StaticLayout. The version in this patch contains basically the same functionality that existed before, but hopefully better performance and an interface that's suitable for more sophisticated paragraph layout. Note that this version contains a high quality strategy, which mostly works but doesn't respect varying line width. Change-Id: I02485d58b1e52856296a72cdd4efd963bc572933 --- engine/src/flutter/include/minikin/Layout.h | 11 + .../src/flutter/include/minikin/LineBreaker.h | 209 ++++++++++++ engine/src/flutter/libs/minikin/Android.mk | 1 + engine/src/flutter/libs/minikin/Layout.cpp | 13 - .../src/flutter/libs/minikin/LineBreaker.cpp | 301 ++++++++++++++++++ 5 files changed, 522 insertions(+), 13 deletions(-) create mode 100644 engine/src/flutter/include/minikin/LineBreaker.h create mode 100644 engine/src/flutter/libs/minikin/LineBreaker.cpp diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 9f8759768d1..543f553ce10 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -57,6 +57,17 @@ struct LayoutGlyph { // Internal state used during layout operation class LayoutContext; +enum { + kBidi_LTR = 0, + kBidi_RTL = 1, + kBidi_Default_LTR = 2, + kBidi_Default_RTL = 3, + kBidi_Force_LTR = 4, + kBidi_Force_RTL = 5, + + kBidi_Mask = 0x7 +}; + // Lifecycle and threading assumptions for Layout: // The object is assumed to be owned by a single thread; multiple threads // may not mutate it at the same time. diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h new file mode 100644 index 00000000000..29afba0bee9 --- /dev/null +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2015 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. + */ + +/** + * A module for breaking paragraphs into lines, supporting high quality + * hyphenation and justification. + */ + +#ifndef MINIKIN_LINE_BREAKER_H +#define MINIKIN_LINE_BREAKER_H + +#include "unicode/brkiter.h" +#include "unicode/locid.h" +#include +#include + +namespace android { + +enum BreakStrategy { + kBreakStrategy_Greedy = 0, + kBreakStrategy_HighQuality = 1, + kBreakStrategy_Balanced = 2 +}; + +// TODO: want to generalize to be able to handle array of line widths +class LineWidths { + public: + void setWidths(float firstWidth, int firstWidthLineCount, float restWidth) { + mFirstWidth = firstWidth; + mFirstWidthLineCount = firstWidthLineCount; + mRestWidth = restWidth; + } + float getLineWidth(int line) const { + return (line < mFirstWidthLineCount) ? mFirstWidth : mRestWidth; + } + private: + float mFirstWidth; + int mFirstWidthLineCount; + float mRestWidth; +}; + +class TabStops { + public: + void set(const int* stops, size_t nStops, int tabWidth) { + if (stops != nullptr) { + mStops.assign(stops, stops + nStops); + } else { + mStops.clear(); + } + mTabWidth = tabWidth; + } + float nextTab(float widthSoFar) const { + for (size_t i = 0; i < mStops.size(); i++) { + if (mStops[i] > widthSoFar) { + return mStops[i]; + } + } + return floor(widthSoFar / mTabWidth + 1) * mTabWidth; + } + private: + std::vector mStops; + int mTabWidth; +}; + +class LineBreaker { + public: + ~LineBreaker() { + utext_close(&mUText); + delete mBreakIterator; + } + + // Note: Locale persists across multiple invocations (it is not cleaned up by finish()), + // explicitly to avoid the cost of creating ICU BreakIterator objects. It should always + // be set on the first invocation, but callers are encouraged not to call again unless + // locale has actually changed. + // That logic could be here but it's better for performance that it's upstream because of + // the cost of constructing and comparing the ICU Locale object. + void setLocale(const icu::Locale& locale) { + delete mBreakIterator; + UErrorCode status = U_ZERO_ERROR; + mBreakIterator = icu::BreakIterator::createLineInstance(locale, status); + // TODO: check status + // TODO: load hyphenator from locale + } + + void resize(size_t size) { + mTextBuf.resize(size); + mCharWidths.resize(size); + } + + size_t size() const { + return mTextBuf.size(); + } + + uint16_t* buffer() { + return mTextBuf.data(); + } + + float* charWidths() { + return mCharWidths.data(); + } + + // set text to current contents of buffer + void setText(); + + void setLineWidths(float firstWidth, int firstWidthLineCount, float restWidth); + + void setTabStops(const int* stops, size_t nStops, int tabWidth) { + mTabStops.set(stops, nStops, tabWidth); + } + + BreakStrategy getStrategy() const { return mStrategy; } + + void setStrategy(BreakStrategy strategy) { mStrategy = strategy; } + + // TODO: this class is actually fairly close to being general and not tied to using + // Minikin to do the shaping of the strings. The main thing that would need to be changed + // is having some kind of callback (or virtual class, or maybe even template), which could + // easily be instantiated with Minikin's Layout. Future work for when needed. + float addStyleRun(const MinikinPaint* paint, const FontCollection* typeface, + FontStyle style, size_t start, size_t end, bool isRtl); + + void addReplacement(size_t start, size_t end, float width); + + size_t computeBreaks(); + + const int* getBreaks() const { + return mBreaks.data(); + } + + const float* getWidths() const { + return mWidths.data(); + } + + const uint8_t* getFlags() const { + return mFlags.data(); + } + + void finish(); + + private: + // ParaWidth is used to hold cumulative width from beginning of paragraph. Note that for + // very large paragraphs, accuracy could degrade using only 32-bit float. Note however + // that float is used extensively on the Java side for this. This is a typedef so that + // we can easily change it based on performance/accuracy tradeoff. + typedef double ParaWidth; + + // A single candidate break + struct Candidate { + size_t offset; // offset to text buffer, in code units + size_t prev; // index to previous break + ParaWidth preBreak; + ParaWidth postBreak; + float penalty; // penalty of this break (for example, hyphen penalty) + float score; // best score found for this break + }; + + float currentLineWidth() const; + + void addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, float penalty); + + void addCandidate(Candidate cand); + + void computeBreaksGreedy(); + + void computeBreaksOpt(); + + icu::BreakIterator* mBreakIterator = nullptr; + UText mUText = UTEXT_INITIALIZER; + std::vectormTextBuf; + std::vectormCharWidths; + + // layout parameters + BreakStrategy mStrategy = kBreakStrategy_Greedy; + LineWidths mLineWidths; + TabStops mTabStops; + + // result of line breaking + std::vector mBreaks; + std::vector mWidths; + std::vector mFlags; + + ParaWidth mWidth = 0; + std::vector mCandidates; + + // the following are state for greedy breaker (updated while adding style runs) + size_t mLastBreak; + size_t mBestBreak; + float mBestScore; + ParaWidth mPreBreak; // prebreak of last break + int mFirstTabIndex; +}; + +} // namespace android + +#endif // MINIKIN_LINE_BREAKER_H diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index d9c973d97f4..54068243ee2 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -23,6 +23,7 @@ LOCAL_SRC_FILES := \ FontFamily.cpp \ GraphemeBreak.cpp \ Layout.cpp \ + LineBreaker.cpp \ MinikinInternal.cpp \ MinikinRefCounted.cpp \ MinikinFontFreeType.cpp \ diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 8e5e546283e..28dac7f644b 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -43,19 +43,6 @@ using std::vector; namespace android { -// TODO: these should move into the header file, but for now we don't want -// to cause namespace collisions with TextLayout.h -enum { - kBidi_LTR = 0, - kBidi_RTL = 1, - kBidi_Default_LTR = 2, - kBidi_Default_RTL = 3, - kBidi_Force_LTR = 4, - kBidi_Force_RTL = 5, - - kBidi_Mask = 0x7 -}; - const int kDirection_Mask = 0x1; struct LayoutContext { diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp new file mode 100644 index 00000000000..99d7f69de54 --- /dev/null +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -0,0 +1,301 @@ +/* + * Copyright (C) 2015 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. + */ + +#define VERBOSE_DEBUG 0 + +#include + +#define LOG_TAG "Minikin" +#include + +#include +#include + +using std::vector; + +namespace android { + +const int CHAR_TAB = 0x0009; + +// Large scores in a hierarchy; we prefer desperate breaks to an overfull line. All these +// constants are larger than any reasonable actual width score. +const float SCORE_INFTY = std::numeric_limits::max(); +const float SCORE_OVERFULL = 1e12f; +const float SCORE_DESPERATE = 1e10f; + +// When the text buffer is within this limit, capacity of vectors is retained at finish(), +// to avoid allocation. +const size_t MAX_TEXT_BUF_RETAIN = 32678; + +void LineBreaker::setText() { + UErrorCode status = U_ZERO_ERROR; + utext_openUChars(&mUText, mTextBuf.data(), mTextBuf.size(), &status); + mBreakIterator->setText(&mUText, status); + mBreakIterator->first(); + + // handle initial break here because addStyleRun may never be called + mBreakIterator->next(); + mCandidates.clear(); + Candidate cand = {0, 0, 0.0, 0.0, 0.0, 0.0}; + mCandidates.push_back(cand); + + // reset greedy breaker state + mBreaks.clear(); + mWidths.clear(); + mFlags.clear(); + mLastBreak = 0; + mBestBreak = 0; + mBestScore = SCORE_INFTY; + mPreBreak = 0; + mFirstTabIndex = INT_MAX; +} + +void LineBreaker::setLineWidths(float firstWidth, int firstWidthLineCount, float restWidth) { + ALOGD("width %f", firstWidth); + mLineWidths.setWidths(firstWidth, firstWidthLineCount, restWidth); +} + +// This function determines whether a character is a space that disappears at end of line. +// It is the Unicode set: [[:General_Category=Space_Separator:]-[:Line_Break=Glue:]] +// Note: all such characters are in the BMP, so it's ok to use code units for this. +static bool isLineEndSpace(uint16_t c) { + return c == ' ' || c == 0x1680 || (0x2000 <= c && c <= 0x200A && c != 0x2007) || c == 0x205F || + c == 0x3000; +} + +// Ordinarily, this method measures the text in the range given. However, when paint +// is nullptr, it assumes the widths have already been calculated and stored in the +// width buffer. +// This method finds the candidate word breaks (using the ICU break iterator) and sends them +// to addCandidate. +float LineBreaker::addStyleRun(const MinikinPaint* paint, const FontCollection* typeface, + FontStyle style, size_t start, size_t end, bool isRtl) { + Layout layout; // performance TODO: move layout to self object to reduce allocation cost? + float width = 0.0f; + int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR; + + if (paint != nullptr) { + layout.setFontCollection(typeface); + layout.doLayout(mTextBuf.data(), start, end - start, mTextBuf.size(), bidiFlags, style, + *paint); + layout.getAdvances(mCharWidths.data() + start); + width = layout.getAdvance(); + } + + ParaWidth postBreak = mWidth; + size_t current = (size_t)mBreakIterator->current(); + for (size_t i = start; i < end; i++) { + uint16_t c = mTextBuf[i]; + if (c == CHAR_TAB) { + mWidth = mPreBreak + mTabStops.nextTab(mWidth - mPreBreak); + if (mFirstTabIndex == INT_MAX) { + mFirstTabIndex = (int)i; + } + // fall back to greedy; other modes don't know how to deal with tabs + mStrategy = kBreakStrategy_Greedy; + } else { + mWidth += mCharWidths[i]; + if (!isLineEndSpace(c)) { + postBreak = mWidth; + } + } + if (i + 1 == current) { + // TODO: hyphenation goes here + + // Skip break for zero-width characters. + if (current == mTextBuf.size() || mCharWidths[current] > 0) { + addWordBreak(current, mWidth, postBreak, 0); + } + current = (size_t)mBreakIterator->next(); + } + } + + return width; +} + +// add a word break (possibly for a hyphenated fragment), and add desperate breaks if +// needed (ie when word exceeds current line width) +void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, + float penalty) { + Candidate cand; + ParaWidth width = mCandidates.back().preBreak; + if (postBreak - width > currentLineWidth()) { + // Add desperate breaks. + // Note: these breaks are based on the shaping of the (non-broken) original text; they + // are imprecise especially in the presence of kerning, ligatures, and Arabic shaping. + size_t i = mCandidates.back().offset; + width += mCharWidths[i++]; + for (; i < offset; i++) { + float w = mCharWidths[i]; + if (w > 0) { + cand.offset = i; + cand.preBreak = width; + cand.postBreak = width; + cand.penalty = SCORE_DESPERATE; +#if VERBOSE_DEBUG + ALOGD("desperate cand: %d %g:%g", + mCandidates.size(), cand.postBreak, cand.preBreak); +#endif + addCandidate(cand); + width += w; + } + } + } + + cand.offset = offset; + cand.preBreak = preBreak; + cand.postBreak = postBreak; + cand.penalty = penalty; +#if VERBOSE_DEBUG + ALOGD("cand: %d %g:%g", mCandidates.size(), cand.postBreak, cand.preBreak); +#endif + addCandidate(cand); +} + +// TODO performance: could avoid populating mCandidates if greedy only +void LineBreaker::addCandidate(Candidate cand) { + size_t candIndex = mCandidates.size(); + mCandidates.push_back(cand); + if (cand.postBreak - mPreBreak > currentLineWidth()) { + // This break would create an overfull line, pick the best break and break there (greedy) + if (mBestBreak == mLastBreak) { + mBestBreak = candIndex; + } + mBreaks.push_back(mCandidates[mBestBreak].offset); + mWidths.push_back(mCandidates[mBestBreak].postBreak - mPreBreak); + mFlags.push_back(mFirstTabIndex < mBreaks.back()); + mFirstTabIndex = INT_MAX; + mBestScore = SCORE_INFTY; +#if VERBOSE_DEBUG + ALOGD("break: %d %g", mBreaks.back(), mWidths.back()); +#endif + mLastBreak = mBestBreak; + mPreBreak = mCandidates[mBestBreak].preBreak; + } + if (cand.penalty <= mBestScore) { + mBestBreak = candIndex; + mBestScore = cand.penalty; + } +} + +void LineBreaker::addReplacement(size_t start, size_t end, float width) { + mCharWidths[start] = width; + std::fill(&mCharWidths[start + 1], &mCharWidths[end], 0.0f); + addStyleRun(nullptr, nullptr, FontStyle(), start, end, false); +} + +float LineBreaker::currentLineWidth() const { + return mLineWidths.getLineWidth(mBreaks.size()); +} + +void LineBreaker::computeBreaksGreedy() { + // All breaks but the last have been added in addCandidate already. + size_t nCand = mCandidates.size(); + if (nCand == 1 || mLastBreak != nCand - 1) { + mBreaks.push_back(mCandidates[nCand - 1].offset); + mWidths.push_back(mCandidates[nCand - 1].postBreak - mPreBreak); + mFlags.push_back(mFirstTabIndex < mBreaks.back()); + // don't need to update mFirstTabIndex or mBestScore, because we're done +#if VERBOSE_DEBUG + ALOGD("final break: %d %g", mBreaks.back(), mWidths.back()); +#endif + } +} + +void LineBreaker::computeBreaksOpt() { + // clear existing greedy break result + mBreaks.clear(); + mWidths.clear(); + mFlags.clear(); + size_t active = 0; + size_t nCand = mCandidates.size(); + float width = mLineWidths.getLineWidth(0); + // TODO: actually support non-constant width + for (size_t i = 1; i < nCand; i++) { + bool stretchIsFree = mStrategy != kBreakStrategy_Balanced && i == nCand - 1; + float best = SCORE_INFTY; + size_t bestPrev = 0; + + // Width-based component of score increases as line gets shorter, so score will always be + // at least this. + float bestHope = 0; + + ParaWidth leftEdge = mCandidates[i].postBreak - width; + for (size_t j = active; j < i; j++) { + float jScore = mCandidates[j].score; + if (jScore + bestHope >= best) continue; + float delta = mCandidates[j].preBreak - leftEdge; + + // TODO: for justified text, refine with shrink/stretch + float widthScore; + if (delta < 0) { + widthScore = SCORE_OVERFULL; + active = j + 1; + } else { + widthScore = stretchIsFree ? 0 : delta * delta; + bestHope = widthScore; + } + + float score = jScore + widthScore; + if (score <= best) { + best = score; + bestPrev = j; + } + } + mCandidates[i].score = best + mCandidates[i].penalty; + mCandidates[i].prev = bestPrev; + } + size_t prev; + for (size_t i = nCand - 1; i > 0; i = prev) { + prev = mCandidates[i].prev; + mBreaks.push_back(mCandidates[i].offset); + mWidths.push_back(mCandidates[i].postBreak - mCandidates[prev].preBreak); + mFlags.push_back(0); + } + std::reverse(mBreaks.begin(), mBreaks.end()); + std::reverse(mWidths.begin(), mWidths.end()); + std::reverse(mFlags.begin(), mFlags.end()); +} + +size_t LineBreaker::computeBreaks() { + if (mStrategy == kBreakStrategy_Greedy) { + computeBreaksGreedy(); + } else { + computeBreaksOpt(); + } + return mBreaks.size(); +} + +void LineBreaker::finish() { + mWidth = 0; + mCandidates.clear(); + mBreaks.clear(); + mWidths.clear(); + mFlags.clear(); + if (mTextBuf.size() > MAX_TEXT_BUF_RETAIN) { + mTextBuf.clear(); + mTextBuf.shrink_to_fit(); + mCharWidths.clear(); + mCharWidths.shrink_to_fit(); + mCandidates.shrink_to_fit(); + mBreaks.shrink_to_fit(); + mWidths.shrink_to_fit(); + mFlags.shrink_to_fit(); + } + mStrategy = kBreakStrategy_Greedy; +} + +} // namespace android From b038d920c433d8971b179b888220cc2a197bc227 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 18 Mar 2015 23:04:28 -0700 Subject: [PATCH 072/364] Add hyphenation to line breaking This patch adds hyphenation using the Liang hyphenation algorithm, similar to TeX. It also improves the optimized line breaker so that it works correctly and efficiently even when the line width is not constant (there is a specialization for constant width, which is probably worthwhile, but performance TODOs remain). Still to be done: * hyphenator has many shortcuts, only tested with English * interaction between punctuation and hyphenation is problematic Change-Id: I2d94a1668ebc536398b7c43fcf486333eeb7c6aa --- .../src/flutter/include/minikin/Hyphenator.h | 62 ++++++ .../src/flutter/include/minikin/LineBreaker.h | 45 ++-- engine/src/flutter/libs/minikin/Android.mk | 1 + .../src/flutter/libs/minikin/Hyphenator.cpp | 152 ++++++++++++++ .../src/flutter/libs/minikin/LineBreaker.cpp | 194 ++++++++++++++---- 5 files changed, 406 insertions(+), 48 deletions(-) create mode 100644 engine/src/flutter/include/minikin/Hyphenator.h create mode 100644 engine/src/flutter/libs/minikin/Hyphenator.cpp diff --git a/engine/src/flutter/include/minikin/Hyphenator.h b/engine/src/flutter/include/minikin/Hyphenator.h new file mode 100644 index 00000000000..581c657fbe6 --- /dev/null +++ b/engine/src/flutter/include/minikin/Hyphenator.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2015 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. + */ + +/** + * An implementation of Liang's hyphenation algorithm. + */ + +#include +#include + +#ifndef MINIKIN_HYPHENATOR_H +#define MINIKIN_HYPHENATOR_H + +namespace android { + +class Trie { +public: + std::vector result; + std::unordered_map succ; +}; + +class Hyphenator { +public: + // Note: this will also require a locale, for proper case folding behavior + static Hyphenator* load(const uint16_t* patternData, size_t size); + + // Compute the hyphenation of a word, storing the hyphenation in result vector. Each + // entry in the vector is a "hyphen edit" to be applied at the corresponding code unit + // offset in the word. Currently 0 means no hyphen and 1 means insert hyphen and break, + // but this will be expanded to other edits for nonstandard hyphenation. + // Example: word is "hyphen", result is [0 0 1 0 0 0], corresponding to "hy-phen". + void hyphenate(std::vector* result, const uint16_t* word, size_t len); + +private: + void addPattern(const uint16_t* pattern, size_t size); + + void hyphenateSoft(std::vector* result, const uint16_t* word, size_t len); + + // TODO: these should become parameters, as they might vary by locale, screen size, and + // possibly explicit user control. + static const int MIN_PREFIX = 2; + static const int MIN_SUFFIX = 3; + + Trie root; +}; + +} // namespace android + +#endif // MINIKIN_HYPHENATOR_H \ No newline at end of file diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index 29afba0bee9..92e72e249c0 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -26,6 +26,7 @@ #include "unicode/locid.h" #include #include +#include "minikin/Hyphenator.h" namespace android { @@ -43,6 +44,10 @@ class LineWidths { mFirstWidthLineCount = firstWidthLineCount; mRestWidth = restWidth; } + bool isConstant() const { + // technically mFirstWidthLineCount == 0 would count too, but doesn't actually happen + return mRestWidth == mFirstWidth; + } float getLineWidth(int line) const { return (line < mFirstWidthLineCount) ? mFirstWidth : mRestWidth; } @@ -77,6 +82,8 @@ class TabStops { class LineBreaker { public: + const static int kTab_Shift = 29; // keep synchronized with TAB_MASK in StaticLayout.java + ~LineBreaker() { utext_close(&mUText); delete mBreakIterator; @@ -88,13 +95,8 @@ class LineBreaker { // locale has actually changed. // That logic could be here but it's better for performance that it's upstream because of // the cost of constructing and comparing the ICU Locale object. - void setLocale(const icu::Locale& locale) { - delete mBreakIterator; - UErrorCode status = U_ZERO_ERROR; - mBreakIterator = icu::BreakIterator::createLineInstance(locale, status); - // TODO: check status - // TODO: load hyphenator from locale - } + // Note: caller is responsible for managing lifetime of hyphenator + void setLocale(const icu::Locale& locale, Hyphenator* hyphenator); void resize(size_t size) { mTextBuf.resize(size); @@ -130,8 +132,8 @@ class LineBreaker { // Minikin to do the shaping of the strings. The main thing that would need to be changed // is having some kind of callback (or virtual class, or maybe even template), which could // easily be instantiated with Minikin's Layout. Future work for when needed. - float addStyleRun(const MinikinPaint* paint, const FontCollection* typeface, - FontStyle style, size_t start, size_t end, bool isRtl); + float addStyleRun(MinikinPaint* paint, const FontCollection* typeface, FontStyle style, + size_t start, size_t end, bool isRtl); void addReplacement(size_t start, size_t end, float width); @@ -145,7 +147,7 @@ class LineBreaker { return mWidths.data(); } - const uint8_t* getFlags() const { + const int* getFlags() const { return mFlags.data(); } @@ -166,23 +168,40 @@ class LineBreaker { ParaWidth postBreak; float penalty; // penalty of this break (for example, hyphen penalty) float score; // best score found for this break + size_t lineNumber; // only updated for non-constant line widths + uint8_t hyphenEdit; }; float currentLineWidth() const; - void addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, float penalty); + // compute shrink/stretch penalty for line + float computeScore(float delta, bool atEnd); + + void addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, float penalty, + uint8_t hyph); void addCandidate(Candidate cand); + // push an actual break to the output. Takes care of setting flags for tab + void pushBreak(int offset, float width, uint8_t hyph); + void computeBreaksGreedy(); - void computeBreaksOpt(); + void computeBreaksOptimal(); + + // special case when LineWidth is constant (layout is rectangle) + void computeBreaksOptimalRect(); + + void finishBreaksOptimal(); icu::BreakIterator* mBreakIterator = nullptr; UText mUText = UTEXT_INITIALIZER; std::vectormTextBuf; std::vectormCharWidths; + Hyphenator* mHyphenator; + std::vector mHyphBuf; + // layout parameters BreakStrategy mStrategy = kBreakStrategy_Greedy; LineWidths mLineWidths; @@ -191,7 +210,7 @@ class LineBreaker { // result of line breaking std::vector mBreaks; std::vector mWidths; - std::vector mFlags; + std::vector mFlags; ParaWidth mWidth = 0; std::vector mCandidates; diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 54068243ee2..34b535cabd4 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -22,6 +22,7 @@ LOCAL_SRC_FILES := \ FontCollection.cpp \ FontFamily.cpp \ GraphemeBreak.cpp \ + Hyphenator.cpp \ Layout.cpp \ LineBreaker.cpp \ MinikinInternal.cpp \ diff --git a/engine/src/flutter/libs/minikin/Hyphenator.cpp b/engine/src/flutter/libs/minikin/Hyphenator.cpp new file mode 100644 index 00000000000..c50b3861af4 --- /dev/null +++ b/engine/src/flutter/libs/minikin/Hyphenator.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2015 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 +#include +#include +#include +#include + +// HACK: for reading pattern file +#include + +#define LOG_TAG "Minikin" +#include "utils/Log.h" + +#include "minikin/Hyphenator.h" + +using std::vector; + +namespace android { + +static const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; + +void Hyphenator::addPattern(const uint16_t* pattern, size_t size) { + vector word; + vector result; + + // start by parsing the Liang-format pattern into a word and a result vector, the + // vector right-aligned but without leading zeros. Examples: + // a1bc2d -> abcd [1, 0, 2, 0] + // abc1 -> abc [1] + // 1a2b3c4d5 -> abcd [1, 2, 3, 4, 5] + bool lastWasLetter = false; + bool haveSeenNumber = false; + for (size_t i = 0; i < size; i++) { + uint16_t c = pattern[i]; + if (isdigit(c)) { + result.push_back(c - '0'); + lastWasLetter = false; + haveSeenNumber = true; + } else { + word.push_back(c); + if (lastWasLetter && haveSeenNumber) { + result.push_back(0); + } + lastWasLetter = true; + } + } + if (lastWasLetter) { + result.push_back(0); + } + Trie* t = &root; + for (size_t i = 0; i < word.size(); i++) { + t = &t->succ[word[i]]; + } + t->result = result; +} + +// If any soft hyphen is present in the word, use soft hyphens to decide hyphenation, +// as recommended in UAX #14 (Use of Soft Hyphen) +void Hyphenator::hyphenateSoft(vector* result, const uint16_t* word, size_t len) { + (*result)[0] = 0; + for (size_t i = 1; i < len; i++) { + (*result)[i] = word[i - 1] == CHAR_SOFT_HYPHEN; + } +} + +void Hyphenator::hyphenate(vector* result, const uint16_t* word, size_t len) { + result->clear(); + result->resize(len); + if (len < MIN_PREFIX + MIN_SUFFIX) return; + size_t maxOffset = len - MIN_SUFFIX + 1; + for (size_t i = 0; i < len + 1; i++) { + const Trie* node = &root; + for (size_t j = i; j < len + 2; j++) { + uint16_t c; + if (j == 0 || j == len + 1) { + c = '.'; // word boundary character in pattern data files + } else { + c = word[j - 1]; + if (c == CHAR_SOFT_HYPHEN) { + hyphenateSoft(result, word, len); + return; + } + // TODO: use locale-sensitive case folding from ICU. + c = tolower(c); + } + auto search = node->succ.find(c); + if (search != node->succ.end()) { + node = &search->second; + } else { + break; + } + if (!node->result.empty()) { + int resultLen = node->result.size(); + int offset = j + 1 - resultLen; + int start = std::max(MIN_PREFIX - offset, 0); + int end = std::min(resultLen, (int)maxOffset - offset); + // TODO performance: this inner loop can profitably be optimized + for (int k = start; k < end; k++) { + (*result)[offset + k] = std::max((*result)[offset + k], node->result[k]); + } +#if 0 + // debug printing of matched patterns + std::string dbg; + for (size_t k = i; k <= j + 1; k++) { + int off = k - j - 2 + resultLen; + if (off >= 0 && node->result[off] != 0) { + dbg.push_back((char)('0' + node->result[off])); + } + if (k < j + 1) { + uint16_t c = (k == 0 || k == len + 1) ? '.' : word[k - 1]; + dbg.push_back((char)c); + } + } + ALOGD("%d:%d %s", i, j, dbg.c_str()); +#endif + } + } + } + // Since the above calculation does not modify values outside + // [MIN_PREFIX, len - MIN_SUFFIX], they are left as 0. + for (size_t i = MIN_PREFIX; i < maxOffset; i++) { + (*result)[i] &= 1; + } +} + +Hyphenator* Hyphenator::load(const uint16_t *patternData, size_t size) { + Hyphenator* result = new Hyphenator; + for (size_t i = 0; i < size; i++) { + size_t end = i; + while (patternData[end] != '\n') end++; + result->addPattern(patternData + i, end - i); + i = end; + } + return result; +} + +} // namespace android diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 99d7f69de54..f7f3fb3fd0c 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -29,6 +29,7 @@ using std::vector; namespace android { const int CHAR_TAB = 0x0009; +const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; // Large scores in a hierarchy; we prefer desperate breaks to an overfull line. All these // constants are larger than any reasonable actual width score. @@ -40,6 +41,16 @@ const float SCORE_DESPERATE = 1e10f; // to avoid allocation. const size_t MAX_TEXT_BUF_RETAIN = 32678; +void LineBreaker::setLocale(const icu::Locale& locale, Hyphenator* hyphenator) { + delete mBreakIterator; + UErrorCode status = U_ZERO_ERROR; + mBreakIterator = icu::BreakIterator::createLineInstance(locale, status); + // TODO: check status + + // TODO: load actual resource dependent on locale; letting Minikin do it is a hack + mHyphenator = hyphenator; +} + void LineBreaker::setText() { UErrorCode status = U_ZERO_ERROR; utext_openUChars(&mUText, mTextBuf.data(), mTextBuf.size(), &status); @@ -49,7 +60,7 @@ void LineBreaker::setText() { // handle initial break here because addStyleRun may never be called mBreakIterator->next(); mCandidates.clear(); - Candidate cand = {0, 0, 0.0, 0.0, 0.0, 0.0}; + Candidate cand = {0, 0, 0.0, 0.0, 0.0, 0.0, 0, 0}; mCandidates.push_back(cand); // reset greedy breaker state @@ -64,7 +75,6 @@ void LineBreaker::setText() { } void LineBreaker::setLineWidths(float firstWidth, int firstWidthLineCount, float restWidth) { - ALOGD("width %f", firstWidth); mLineWidths.setWidths(firstWidth, firstWidthLineCount, restWidth); } @@ -81,22 +91,29 @@ static bool isLineEndSpace(uint16_t c) { // width buffer. // This method finds the candidate word breaks (using the ICU break iterator) and sends them // to addCandidate. -float LineBreaker::addStyleRun(const MinikinPaint* paint, const FontCollection* typeface, +float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typeface, FontStyle style, size_t start, size_t end, bool isRtl) { Layout layout; // performance TODO: move layout to self object to reduce allocation cost? float width = 0.0f; int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR; + float hyphenPenalty = 0.0; if (paint != nullptr) { layout.setFontCollection(typeface); layout.doLayout(mTextBuf.data(), start, end - start, mTextBuf.size(), bidiFlags, style, *paint); layout.getAdvances(mCharWidths.data() + start); width = layout.getAdvance(); + + // a heuristic that seems to perform well + hyphenPenalty = 0.5 * paint->size * paint->scaleX * mLineWidths.getLineWidth(0); } - ParaWidth postBreak = mWidth; size_t current = (size_t)mBreakIterator->current(); + size_t wordEnd = start; + size_t lastBreak = start; + ParaWidth lastBreakWidth = mWidth; + ParaWidth postBreak = mWidth; for (size_t i = start; i < end; i++) { uint16_t c = mTextBuf[i]; if (c == CHAR_TAB) { @@ -110,14 +127,48 @@ float LineBreaker::addStyleRun(const MinikinPaint* paint, const FontCollection* mWidth += mCharWidths[i]; if (!isLineEndSpace(c)) { postBreak = mWidth; + wordEnd = i + 1; } } if (i + 1 == current) { - // TODO: hyphenation goes here + // Override ICU's treatment of soft hyphen as a break opportunity, because we want it + // to be a hyphen break, with penalty and drawing behavior. + if (c != CHAR_SOFT_HYPHEN) { + if (paint != nullptr && mHyphenator != nullptr && wordEnd > lastBreak) { + mHyphenator->hyphenate(&mHyphBuf, &mTextBuf[lastBreak], wordEnd - lastBreak); + #if VERBOSE_DEBUG + std::string hyphenatedString; + for (size_t j = lastBreak; j < wordEnd; j++) { + if (mHyphBuf[j - lastBreak]) hyphenatedString.push_back('-'); + // Note: only works with ASCII, should do UTF-8 conversion here + hyphenatedString.push_back(buffer()[j]); + } + ALOGD("hyphenated string: %s", hyphenatedString.c_str()); + #endif - // Skip break for zero-width characters. - if (current == mTextBuf.size() || mCharWidths[current] > 0) { - addWordBreak(current, mWidth, postBreak, 0); + // measure hyphenated substrings + for (size_t j = lastBreak; j < wordEnd; j++) { + uint8_t hyph = mHyphBuf[j - lastBreak]; + if (hyph) { + paint->hyphenEdit = hyph; + layout.doLayout(mTextBuf.data(), lastBreak, j - lastBreak, + mTextBuf.size(), bidiFlags, style, *paint); + ParaWidth hyphPostBreak = lastBreakWidth + layout.getAdvance(); + paint->hyphenEdit = 0; + layout.doLayout(mTextBuf.data(), j, wordEnd - j, + mTextBuf.size(), bidiFlags, style, *paint); + ParaWidth hyphPreBreak = postBreak - layout.getAdvance(); + addWordBreak(j, hyphPreBreak, hyphPostBreak, hyphenPenalty, hyph); + } + } + } + + // Skip break for zero-width characters. + if (current == mTextBuf.size() || mCharWidths[current] > 0) { + addWordBreak(current, mWidth, postBreak, 0.0, 0); + } + lastBreak = current; + lastBreakWidth = mWidth; } current = (size_t)mBreakIterator->next(); } @@ -129,7 +180,7 @@ float LineBreaker::addStyleRun(const MinikinPaint* paint, const FontCollection* // add a word break (possibly for a hyphenated fragment), and add desperate breaks if // needed (ie when word exceeds current line width) void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, - float penalty) { + float penalty, uint8_t hyph) { Candidate cand; ParaWidth width = mCandidates.back().preBreak; if (postBreak - width > currentLineWidth()) { @@ -145,6 +196,7 @@ void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth post cand.preBreak = width; cand.postBreak = width; cand.penalty = SCORE_DESPERATE; + cand.hyphenEdit = 0; #if VERBOSE_DEBUG ALOGD("desperate cand: %d %g:%g", mCandidates.size(), cand.postBreak, cand.preBreak); @@ -159,12 +211,24 @@ void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth post cand.preBreak = preBreak; cand.postBreak = postBreak; cand.penalty = penalty; + cand.hyphenEdit = hyph; #if VERBOSE_DEBUG ALOGD("cand: %d %g:%g", mCandidates.size(), cand.postBreak, cand.preBreak); #endif addCandidate(cand); } +// TODO: for justified text, refine with shrink/stretch +float LineBreaker::computeScore(float delta, bool atEnd) { + if (delta < 0) { + return SCORE_OVERFULL; + } else if (atEnd && mStrategy != kBreakStrategy_Balanced) { + return 0.0; + } else { + return delta * delta; + } +} + // TODO performance: could avoid populating mCandidates if greedy only void LineBreaker::addCandidate(Candidate cand) { size_t candIndex = mCandidates.size(); @@ -174,10 +238,8 @@ void LineBreaker::addCandidate(Candidate cand) { if (mBestBreak == mLastBreak) { mBestBreak = candIndex; } - mBreaks.push_back(mCandidates[mBestBreak].offset); - mWidths.push_back(mCandidates[mBestBreak].postBreak - mPreBreak); - mFlags.push_back(mFirstTabIndex < mBreaks.back()); - mFirstTabIndex = INT_MAX; + pushBreak(mCandidates[mBestBreak].offset, mCandidates[mBestBreak].postBreak - mPreBreak, + mCandidates[mBestBreak].hyphenEdit); mBestScore = SCORE_INFTY; #if VERBOSE_DEBUG ALOGD("break: %d %g", mBreaks.back(), mWidths.back()); @@ -191,6 +253,15 @@ void LineBreaker::addCandidate(Candidate cand) { } } +void LineBreaker::pushBreak(int offset, float width, uint8_t hyph) { + mBreaks.push_back(offset); + mWidths.push_back(width); + int flags = (mFirstTabIndex < mBreaks.back()) << kTab_Shift; + flags |= hyph; + mFlags.push_back(flags); + mFirstTabIndex = INT_MAX; +} + void LineBreaker::addReplacement(size_t start, size_t end, float width) { mCharWidths[start] = width; std::fill(&mCharWidths[start + 1], &mCharWidths[end], 0.0f); @@ -205,27 +276,87 @@ void LineBreaker::computeBreaksGreedy() { // All breaks but the last have been added in addCandidate already. size_t nCand = mCandidates.size(); if (nCand == 1 || mLastBreak != nCand - 1) { - mBreaks.push_back(mCandidates[nCand - 1].offset); - mWidths.push_back(mCandidates[nCand - 1].postBreak - mPreBreak); - mFlags.push_back(mFirstTabIndex < mBreaks.back()); - // don't need to update mFirstTabIndex or mBestScore, because we're done + pushBreak(mCandidates[nCand - 1].offset, mCandidates[nCand - 1].postBreak - mPreBreak, 0); + // don't need to update mBestScore, because we're done #if VERBOSE_DEBUG ALOGD("final break: %d %g", mBreaks.back(), mWidths.back()); #endif } } -void LineBreaker::computeBreaksOpt() { +// Follow "prev" links in mCandidates array, and copy to result arrays. +void LineBreaker::finishBreaksOptimal() { // clear existing greedy break result mBreaks.clear(); mWidths.clear(); mFlags.clear(); + size_t nCand = mCandidates.size(); + size_t prev; + for (size_t i = nCand - 1; i > 0; i = prev) { + prev = mCandidates[i].prev; + mBreaks.push_back(mCandidates[i].offset); + mWidths.push_back(mCandidates[i].postBreak - mCandidates[prev].preBreak); + mFlags.push_back(mCandidates[i].hyphenEdit); + } + std::reverse(mBreaks.begin(), mBreaks.end()); + std::reverse(mWidths.begin(), mWidths.end()); + std::reverse(mFlags.begin(), mFlags.end()); +} + +void LineBreaker::computeBreaksOptimal() { + size_t active = 0; + size_t nCand = mCandidates.size(); + for (size_t i = 1; i < nCand; i++) { + bool atEnd = i == nCand - 1; + float best = SCORE_INFTY; + size_t bestPrev = 0; + + size_t lineNumberLast = mCandidates[active].lineNumber; + float width = mLineWidths.getLineWidth(lineNumberLast); + ParaWidth leftEdge = mCandidates[i].postBreak - width; + float bestHope = 0; + + for (size_t j = active; j < i; j++) { + size_t lineNumber = mCandidates[j].lineNumber; + if (lineNumber != lineNumberLast) { + float widthNew = mLineWidths.getLineWidth(lineNumber); + if (widthNew != width) { + leftEdge = mCandidates[i].postBreak - width; + bestHope = 0; + width = widthNew; + } + lineNumberLast = lineNumber; + } + float jScore = mCandidates[j].score; + if (jScore + bestHope >= best) continue; + float delta = mCandidates[j].preBreak - leftEdge; + + float widthScore = computeScore(delta, atEnd); + if (delta < 0) { + active = j + 1; + } else { + bestHope = widthScore; + } + + float score = jScore + widthScore; + if (score <= best) { + best = score; + bestPrev = j; + } + } + mCandidates[i].score = best + mCandidates[i].penalty; + mCandidates[i].prev = bestPrev; + mCandidates[i].lineNumber = mCandidates[bestPrev].lineNumber + 1; + } + finishBreaksOptimal(); +} + +void LineBreaker::computeBreaksOptimalRect() { size_t active = 0; size_t nCand = mCandidates.size(); float width = mLineWidths.getLineWidth(0); - // TODO: actually support non-constant width for (size_t i = 1; i < nCand; i++) { - bool stretchIsFree = mStrategy != kBreakStrategy_Balanced && i == nCand - 1; + bool atEnd = i == nCand - 1; float best = SCORE_INFTY; size_t bestPrev = 0; @@ -235,17 +366,15 @@ void LineBreaker::computeBreaksOpt() { ParaWidth leftEdge = mCandidates[i].postBreak - width; for (size_t j = active; j < i; j++) { + // TODO performance: can break if bestHope >= best; worth it? float jScore = mCandidates[j].score; if (jScore + bestHope >= best) continue; float delta = mCandidates[j].preBreak - leftEdge; - // TODO: for justified text, refine with shrink/stretch - float widthScore; + float widthScore = computeScore(delta, atEnd); if (delta < 0) { - widthScore = SCORE_OVERFULL; active = j + 1; } else { - widthScore = stretchIsFree ? 0 : delta * delta; bestHope = widthScore; } @@ -258,23 +387,16 @@ void LineBreaker::computeBreaksOpt() { mCandidates[i].score = best + mCandidates[i].penalty; mCandidates[i].prev = bestPrev; } - size_t prev; - for (size_t i = nCand - 1; i > 0; i = prev) { - prev = mCandidates[i].prev; - mBreaks.push_back(mCandidates[i].offset); - mWidths.push_back(mCandidates[i].postBreak - mCandidates[prev].preBreak); - mFlags.push_back(0); - } - std::reverse(mBreaks.begin(), mBreaks.end()); - std::reverse(mWidths.begin(), mWidths.end()); - std::reverse(mFlags.begin(), mFlags.end()); + finishBreaksOptimal(); } size_t LineBreaker::computeBreaks() { if (mStrategy == kBreakStrategy_Greedy) { computeBreaksGreedy(); + } else if (mLineWidths.isConstant()) { + computeBreaksOptimalRect(); } else { - computeBreaksOpt(); + computeBreaksOptimal(); } return mBreaks.size(); } @@ -290,6 +412,8 @@ void LineBreaker::finish() { mTextBuf.shrink_to_fit(); mCharWidths.clear(); mCharWidths.shrink_to_fit(); + mHyphBuf.clear(); + mHyphBuf.shrink_to_fit(); mCandidates.shrink_to_fit(); mBreaks.shrink_to_fit(); mWidths.shrink_to_fit(); From f8ed26a065cdb58adfa5df940bd2f0f6ae70d236 Mon Sep 17 00:00:00 2001 From: Ed Heyl Date: Mon, 30 Mar 2015 20:40:33 +0000 Subject: [PATCH 073/364] Fix build: Revert "Add hyphenation to line breaking" This reverts commit b038d920c433d8971b179b888220cc2a197bc227. Change-Id: I3fed65046274d3aeb748f0730585ab89927f5741 --- .../src/flutter/include/minikin/Hyphenator.h | 62 ------ .../src/flutter/include/minikin/LineBreaker.h | 45 ++-- engine/src/flutter/libs/minikin/Android.mk | 1 - .../src/flutter/libs/minikin/Hyphenator.cpp | 152 -------------- .../src/flutter/libs/minikin/LineBreaker.cpp | 194 ++++-------------- 5 files changed, 48 insertions(+), 406 deletions(-) delete mode 100644 engine/src/flutter/include/minikin/Hyphenator.h delete mode 100644 engine/src/flutter/libs/minikin/Hyphenator.cpp diff --git a/engine/src/flutter/include/minikin/Hyphenator.h b/engine/src/flutter/include/minikin/Hyphenator.h deleted file mode 100644 index 581c657fbe6..00000000000 --- a/engine/src/flutter/include/minikin/Hyphenator.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (C) 2015 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. - */ - -/** - * An implementation of Liang's hyphenation algorithm. - */ - -#include -#include - -#ifndef MINIKIN_HYPHENATOR_H -#define MINIKIN_HYPHENATOR_H - -namespace android { - -class Trie { -public: - std::vector result; - std::unordered_map succ; -}; - -class Hyphenator { -public: - // Note: this will also require a locale, for proper case folding behavior - static Hyphenator* load(const uint16_t* patternData, size_t size); - - // Compute the hyphenation of a word, storing the hyphenation in result vector. Each - // entry in the vector is a "hyphen edit" to be applied at the corresponding code unit - // offset in the word. Currently 0 means no hyphen and 1 means insert hyphen and break, - // but this will be expanded to other edits for nonstandard hyphenation. - // Example: word is "hyphen", result is [0 0 1 0 0 0], corresponding to "hy-phen". - void hyphenate(std::vector* result, const uint16_t* word, size_t len); - -private: - void addPattern(const uint16_t* pattern, size_t size); - - void hyphenateSoft(std::vector* result, const uint16_t* word, size_t len); - - // TODO: these should become parameters, as they might vary by locale, screen size, and - // possibly explicit user control. - static const int MIN_PREFIX = 2; - static const int MIN_SUFFIX = 3; - - Trie root; -}; - -} // namespace android - -#endif // MINIKIN_HYPHENATOR_H \ No newline at end of file diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index 92e72e249c0..29afba0bee9 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -26,7 +26,6 @@ #include "unicode/locid.h" #include #include -#include "minikin/Hyphenator.h" namespace android { @@ -44,10 +43,6 @@ class LineWidths { mFirstWidthLineCount = firstWidthLineCount; mRestWidth = restWidth; } - bool isConstant() const { - // technically mFirstWidthLineCount == 0 would count too, but doesn't actually happen - return mRestWidth == mFirstWidth; - } float getLineWidth(int line) const { return (line < mFirstWidthLineCount) ? mFirstWidth : mRestWidth; } @@ -82,8 +77,6 @@ class TabStops { class LineBreaker { public: - const static int kTab_Shift = 29; // keep synchronized with TAB_MASK in StaticLayout.java - ~LineBreaker() { utext_close(&mUText); delete mBreakIterator; @@ -95,8 +88,13 @@ class LineBreaker { // locale has actually changed. // That logic could be here but it's better for performance that it's upstream because of // the cost of constructing and comparing the ICU Locale object. - // Note: caller is responsible for managing lifetime of hyphenator - void setLocale(const icu::Locale& locale, Hyphenator* hyphenator); + void setLocale(const icu::Locale& locale) { + delete mBreakIterator; + UErrorCode status = U_ZERO_ERROR; + mBreakIterator = icu::BreakIterator::createLineInstance(locale, status); + // TODO: check status + // TODO: load hyphenator from locale + } void resize(size_t size) { mTextBuf.resize(size); @@ -132,8 +130,8 @@ class LineBreaker { // Minikin to do the shaping of the strings. The main thing that would need to be changed // is having some kind of callback (or virtual class, or maybe even template), which could // easily be instantiated with Minikin's Layout. Future work for when needed. - float addStyleRun(MinikinPaint* paint, const FontCollection* typeface, FontStyle style, - size_t start, size_t end, bool isRtl); + float addStyleRun(const MinikinPaint* paint, const FontCollection* typeface, + FontStyle style, size_t start, size_t end, bool isRtl); void addReplacement(size_t start, size_t end, float width); @@ -147,7 +145,7 @@ class LineBreaker { return mWidths.data(); } - const int* getFlags() const { + const uint8_t* getFlags() const { return mFlags.data(); } @@ -168,40 +166,23 @@ class LineBreaker { ParaWidth postBreak; float penalty; // penalty of this break (for example, hyphen penalty) float score; // best score found for this break - size_t lineNumber; // only updated for non-constant line widths - uint8_t hyphenEdit; }; float currentLineWidth() const; - // compute shrink/stretch penalty for line - float computeScore(float delta, bool atEnd); - - void addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, float penalty, - uint8_t hyph); + void addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, float penalty); void addCandidate(Candidate cand); - // push an actual break to the output. Takes care of setting flags for tab - void pushBreak(int offset, float width, uint8_t hyph); - void computeBreaksGreedy(); - void computeBreaksOptimal(); - - // special case when LineWidth is constant (layout is rectangle) - void computeBreaksOptimalRect(); - - void finishBreaksOptimal(); + void computeBreaksOpt(); icu::BreakIterator* mBreakIterator = nullptr; UText mUText = UTEXT_INITIALIZER; std::vectormTextBuf; std::vectormCharWidths; - Hyphenator* mHyphenator; - std::vector mHyphBuf; - // layout parameters BreakStrategy mStrategy = kBreakStrategy_Greedy; LineWidths mLineWidths; @@ -210,7 +191,7 @@ class LineBreaker { // result of line breaking std::vector mBreaks; std::vector mWidths; - std::vector mFlags; + std::vector mFlags; ParaWidth mWidth = 0; std::vector mCandidates; diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 34b535cabd4..54068243ee2 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -22,7 +22,6 @@ LOCAL_SRC_FILES := \ FontCollection.cpp \ FontFamily.cpp \ GraphemeBreak.cpp \ - Hyphenator.cpp \ Layout.cpp \ LineBreaker.cpp \ MinikinInternal.cpp \ diff --git a/engine/src/flutter/libs/minikin/Hyphenator.cpp b/engine/src/flutter/libs/minikin/Hyphenator.cpp deleted file mode 100644 index c50b3861af4..00000000000 --- a/engine/src/flutter/libs/minikin/Hyphenator.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2015 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 -#include -#include -#include -#include - -// HACK: for reading pattern file -#include - -#define LOG_TAG "Minikin" -#include "utils/Log.h" - -#include "minikin/Hyphenator.h" - -using std::vector; - -namespace android { - -static const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; - -void Hyphenator::addPattern(const uint16_t* pattern, size_t size) { - vector word; - vector result; - - // start by parsing the Liang-format pattern into a word and a result vector, the - // vector right-aligned but without leading zeros. Examples: - // a1bc2d -> abcd [1, 0, 2, 0] - // abc1 -> abc [1] - // 1a2b3c4d5 -> abcd [1, 2, 3, 4, 5] - bool lastWasLetter = false; - bool haveSeenNumber = false; - for (size_t i = 0; i < size; i++) { - uint16_t c = pattern[i]; - if (isdigit(c)) { - result.push_back(c - '0'); - lastWasLetter = false; - haveSeenNumber = true; - } else { - word.push_back(c); - if (lastWasLetter && haveSeenNumber) { - result.push_back(0); - } - lastWasLetter = true; - } - } - if (lastWasLetter) { - result.push_back(0); - } - Trie* t = &root; - for (size_t i = 0; i < word.size(); i++) { - t = &t->succ[word[i]]; - } - t->result = result; -} - -// If any soft hyphen is present in the word, use soft hyphens to decide hyphenation, -// as recommended in UAX #14 (Use of Soft Hyphen) -void Hyphenator::hyphenateSoft(vector* result, const uint16_t* word, size_t len) { - (*result)[0] = 0; - for (size_t i = 1; i < len; i++) { - (*result)[i] = word[i - 1] == CHAR_SOFT_HYPHEN; - } -} - -void Hyphenator::hyphenate(vector* result, const uint16_t* word, size_t len) { - result->clear(); - result->resize(len); - if (len < MIN_PREFIX + MIN_SUFFIX) return; - size_t maxOffset = len - MIN_SUFFIX + 1; - for (size_t i = 0; i < len + 1; i++) { - const Trie* node = &root; - for (size_t j = i; j < len + 2; j++) { - uint16_t c; - if (j == 0 || j == len + 1) { - c = '.'; // word boundary character in pattern data files - } else { - c = word[j - 1]; - if (c == CHAR_SOFT_HYPHEN) { - hyphenateSoft(result, word, len); - return; - } - // TODO: use locale-sensitive case folding from ICU. - c = tolower(c); - } - auto search = node->succ.find(c); - if (search != node->succ.end()) { - node = &search->second; - } else { - break; - } - if (!node->result.empty()) { - int resultLen = node->result.size(); - int offset = j + 1 - resultLen; - int start = std::max(MIN_PREFIX - offset, 0); - int end = std::min(resultLen, (int)maxOffset - offset); - // TODO performance: this inner loop can profitably be optimized - for (int k = start; k < end; k++) { - (*result)[offset + k] = std::max((*result)[offset + k], node->result[k]); - } -#if 0 - // debug printing of matched patterns - std::string dbg; - for (size_t k = i; k <= j + 1; k++) { - int off = k - j - 2 + resultLen; - if (off >= 0 && node->result[off] != 0) { - dbg.push_back((char)('0' + node->result[off])); - } - if (k < j + 1) { - uint16_t c = (k == 0 || k == len + 1) ? '.' : word[k - 1]; - dbg.push_back((char)c); - } - } - ALOGD("%d:%d %s", i, j, dbg.c_str()); -#endif - } - } - } - // Since the above calculation does not modify values outside - // [MIN_PREFIX, len - MIN_SUFFIX], they are left as 0. - for (size_t i = MIN_PREFIX; i < maxOffset; i++) { - (*result)[i] &= 1; - } -} - -Hyphenator* Hyphenator::load(const uint16_t *patternData, size_t size) { - Hyphenator* result = new Hyphenator; - for (size_t i = 0; i < size; i++) { - size_t end = i; - while (patternData[end] != '\n') end++; - result->addPattern(patternData + i, end - i); - i = end; - } - return result; -} - -} // namespace android diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index f7f3fb3fd0c..99d7f69de54 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -29,7 +29,6 @@ using std::vector; namespace android { const int CHAR_TAB = 0x0009; -const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; // Large scores in a hierarchy; we prefer desperate breaks to an overfull line. All these // constants are larger than any reasonable actual width score. @@ -41,16 +40,6 @@ const float SCORE_DESPERATE = 1e10f; // to avoid allocation. const size_t MAX_TEXT_BUF_RETAIN = 32678; -void LineBreaker::setLocale(const icu::Locale& locale, Hyphenator* hyphenator) { - delete mBreakIterator; - UErrorCode status = U_ZERO_ERROR; - mBreakIterator = icu::BreakIterator::createLineInstance(locale, status); - // TODO: check status - - // TODO: load actual resource dependent on locale; letting Minikin do it is a hack - mHyphenator = hyphenator; -} - void LineBreaker::setText() { UErrorCode status = U_ZERO_ERROR; utext_openUChars(&mUText, mTextBuf.data(), mTextBuf.size(), &status); @@ -60,7 +49,7 @@ void LineBreaker::setText() { // handle initial break here because addStyleRun may never be called mBreakIterator->next(); mCandidates.clear(); - Candidate cand = {0, 0, 0.0, 0.0, 0.0, 0.0, 0, 0}; + Candidate cand = {0, 0, 0.0, 0.0, 0.0, 0.0}; mCandidates.push_back(cand); // reset greedy breaker state @@ -75,6 +64,7 @@ void LineBreaker::setText() { } void LineBreaker::setLineWidths(float firstWidth, int firstWidthLineCount, float restWidth) { + ALOGD("width %f", firstWidth); mLineWidths.setWidths(firstWidth, firstWidthLineCount, restWidth); } @@ -91,29 +81,22 @@ static bool isLineEndSpace(uint16_t c) { // width buffer. // This method finds the candidate word breaks (using the ICU break iterator) and sends them // to addCandidate. -float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typeface, +float LineBreaker::addStyleRun(const MinikinPaint* paint, const FontCollection* typeface, FontStyle style, size_t start, size_t end, bool isRtl) { Layout layout; // performance TODO: move layout to self object to reduce allocation cost? float width = 0.0f; int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR; - float hyphenPenalty = 0.0; if (paint != nullptr) { layout.setFontCollection(typeface); layout.doLayout(mTextBuf.data(), start, end - start, mTextBuf.size(), bidiFlags, style, *paint); layout.getAdvances(mCharWidths.data() + start); width = layout.getAdvance(); - - // a heuristic that seems to perform well - hyphenPenalty = 0.5 * paint->size * paint->scaleX * mLineWidths.getLineWidth(0); } - size_t current = (size_t)mBreakIterator->current(); - size_t wordEnd = start; - size_t lastBreak = start; - ParaWidth lastBreakWidth = mWidth; ParaWidth postBreak = mWidth; + size_t current = (size_t)mBreakIterator->current(); for (size_t i = start; i < end; i++) { uint16_t c = mTextBuf[i]; if (c == CHAR_TAB) { @@ -127,48 +110,14 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa mWidth += mCharWidths[i]; if (!isLineEndSpace(c)) { postBreak = mWidth; - wordEnd = i + 1; } } if (i + 1 == current) { - // Override ICU's treatment of soft hyphen as a break opportunity, because we want it - // to be a hyphen break, with penalty and drawing behavior. - if (c != CHAR_SOFT_HYPHEN) { - if (paint != nullptr && mHyphenator != nullptr && wordEnd > lastBreak) { - mHyphenator->hyphenate(&mHyphBuf, &mTextBuf[lastBreak], wordEnd - lastBreak); - #if VERBOSE_DEBUG - std::string hyphenatedString; - for (size_t j = lastBreak; j < wordEnd; j++) { - if (mHyphBuf[j - lastBreak]) hyphenatedString.push_back('-'); - // Note: only works with ASCII, should do UTF-8 conversion here - hyphenatedString.push_back(buffer()[j]); - } - ALOGD("hyphenated string: %s", hyphenatedString.c_str()); - #endif + // TODO: hyphenation goes here - // measure hyphenated substrings - for (size_t j = lastBreak; j < wordEnd; j++) { - uint8_t hyph = mHyphBuf[j - lastBreak]; - if (hyph) { - paint->hyphenEdit = hyph; - layout.doLayout(mTextBuf.data(), lastBreak, j - lastBreak, - mTextBuf.size(), bidiFlags, style, *paint); - ParaWidth hyphPostBreak = lastBreakWidth + layout.getAdvance(); - paint->hyphenEdit = 0; - layout.doLayout(mTextBuf.data(), j, wordEnd - j, - mTextBuf.size(), bidiFlags, style, *paint); - ParaWidth hyphPreBreak = postBreak - layout.getAdvance(); - addWordBreak(j, hyphPreBreak, hyphPostBreak, hyphenPenalty, hyph); - } - } - } - - // Skip break for zero-width characters. - if (current == mTextBuf.size() || mCharWidths[current] > 0) { - addWordBreak(current, mWidth, postBreak, 0.0, 0); - } - lastBreak = current; - lastBreakWidth = mWidth; + // Skip break for zero-width characters. + if (current == mTextBuf.size() || mCharWidths[current] > 0) { + addWordBreak(current, mWidth, postBreak, 0); } current = (size_t)mBreakIterator->next(); } @@ -180,7 +129,7 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa // add a word break (possibly for a hyphenated fragment), and add desperate breaks if // needed (ie when word exceeds current line width) void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, - float penalty, uint8_t hyph) { + float penalty) { Candidate cand; ParaWidth width = mCandidates.back().preBreak; if (postBreak - width > currentLineWidth()) { @@ -196,7 +145,6 @@ void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth post cand.preBreak = width; cand.postBreak = width; cand.penalty = SCORE_DESPERATE; - cand.hyphenEdit = 0; #if VERBOSE_DEBUG ALOGD("desperate cand: %d %g:%g", mCandidates.size(), cand.postBreak, cand.preBreak); @@ -211,24 +159,12 @@ void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth post cand.preBreak = preBreak; cand.postBreak = postBreak; cand.penalty = penalty; - cand.hyphenEdit = hyph; #if VERBOSE_DEBUG ALOGD("cand: %d %g:%g", mCandidates.size(), cand.postBreak, cand.preBreak); #endif addCandidate(cand); } -// TODO: for justified text, refine with shrink/stretch -float LineBreaker::computeScore(float delta, bool atEnd) { - if (delta < 0) { - return SCORE_OVERFULL; - } else if (atEnd && mStrategy != kBreakStrategy_Balanced) { - return 0.0; - } else { - return delta * delta; - } -} - // TODO performance: could avoid populating mCandidates if greedy only void LineBreaker::addCandidate(Candidate cand) { size_t candIndex = mCandidates.size(); @@ -238,8 +174,10 @@ void LineBreaker::addCandidate(Candidate cand) { if (mBestBreak == mLastBreak) { mBestBreak = candIndex; } - pushBreak(mCandidates[mBestBreak].offset, mCandidates[mBestBreak].postBreak - mPreBreak, - mCandidates[mBestBreak].hyphenEdit); + mBreaks.push_back(mCandidates[mBestBreak].offset); + mWidths.push_back(mCandidates[mBestBreak].postBreak - mPreBreak); + mFlags.push_back(mFirstTabIndex < mBreaks.back()); + mFirstTabIndex = INT_MAX; mBestScore = SCORE_INFTY; #if VERBOSE_DEBUG ALOGD("break: %d %g", mBreaks.back(), mWidths.back()); @@ -253,15 +191,6 @@ void LineBreaker::addCandidate(Candidate cand) { } } -void LineBreaker::pushBreak(int offset, float width, uint8_t hyph) { - mBreaks.push_back(offset); - mWidths.push_back(width); - int flags = (mFirstTabIndex < mBreaks.back()) << kTab_Shift; - flags |= hyph; - mFlags.push_back(flags); - mFirstTabIndex = INT_MAX; -} - void LineBreaker::addReplacement(size_t start, size_t end, float width) { mCharWidths[start] = width; std::fill(&mCharWidths[start + 1], &mCharWidths[end], 0.0f); @@ -276,87 +205,27 @@ void LineBreaker::computeBreaksGreedy() { // All breaks but the last have been added in addCandidate already. size_t nCand = mCandidates.size(); if (nCand == 1 || mLastBreak != nCand - 1) { - pushBreak(mCandidates[nCand - 1].offset, mCandidates[nCand - 1].postBreak - mPreBreak, 0); - // don't need to update mBestScore, because we're done + mBreaks.push_back(mCandidates[nCand - 1].offset); + mWidths.push_back(mCandidates[nCand - 1].postBreak - mPreBreak); + mFlags.push_back(mFirstTabIndex < mBreaks.back()); + // don't need to update mFirstTabIndex or mBestScore, because we're done #if VERBOSE_DEBUG ALOGD("final break: %d %g", mBreaks.back(), mWidths.back()); #endif } } -// Follow "prev" links in mCandidates array, and copy to result arrays. -void LineBreaker::finishBreaksOptimal() { +void LineBreaker::computeBreaksOpt() { // clear existing greedy break result mBreaks.clear(); mWidths.clear(); mFlags.clear(); - size_t nCand = mCandidates.size(); - size_t prev; - for (size_t i = nCand - 1; i > 0; i = prev) { - prev = mCandidates[i].prev; - mBreaks.push_back(mCandidates[i].offset); - mWidths.push_back(mCandidates[i].postBreak - mCandidates[prev].preBreak); - mFlags.push_back(mCandidates[i].hyphenEdit); - } - std::reverse(mBreaks.begin(), mBreaks.end()); - std::reverse(mWidths.begin(), mWidths.end()); - std::reverse(mFlags.begin(), mFlags.end()); -} - -void LineBreaker::computeBreaksOptimal() { - size_t active = 0; - size_t nCand = mCandidates.size(); - for (size_t i = 1; i < nCand; i++) { - bool atEnd = i == nCand - 1; - float best = SCORE_INFTY; - size_t bestPrev = 0; - - size_t lineNumberLast = mCandidates[active].lineNumber; - float width = mLineWidths.getLineWidth(lineNumberLast); - ParaWidth leftEdge = mCandidates[i].postBreak - width; - float bestHope = 0; - - for (size_t j = active; j < i; j++) { - size_t lineNumber = mCandidates[j].lineNumber; - if (lineNumber != lineNumberLast) { - float widthNew = mLineWidths.getLineWidth(lineNumber); - if (widthNew != width) { - leftEdge = mCandidates[i].postBreak - width; - bestHope = 0; - width = widthNew; - } - lineNumberLast = lineNumber; - } - float jScore = mCandidates[j].score; - if (jScore + bestHope >= best) continue; - float delta = mCandidates[j].preBreak - leftEdge; - - float widthScore = computeScore(delta, atEnd); - if (delta < 0) { - active = j + 1; - } else { - bestHope = widthScore; - } - - float score = jScore + widthScore; - if (score <= best) { - best = score; - bestPrev = j; - } - } - mCandidates[i].score = best + mCandidates[i].penalty; - mCandidates[i].prev = bestPrev; - mCandidates[i].lineNumber = mCandidates[bestPrev].lineNumber + 1; - } - finishBreaksOptimal(); -} - -void LineBreaker::computeBreaksOptimalRect() { size_t active = 0; size_t nCand = mCandidates.size(); float width = mLineWidths.getLineWidth(0); + // TODO: actually support non-constant width for (size_t i = 1; i < nCand; i++) { - bool atEnd = i == nCand - 1; + bool stretchIsFree = mStrategy != kBreakStrategy_Balanced && i == nCand - 1; float best = SCORE_INFTY; size_t bestPrev = 0; @@ -366,15 +235,17 @@ void LineBreaker::computeBreaksOptimalRect() { ParaWidth leftEdge = mCandidates[i].postBreak - width; for (size_t j = active; j < i; j++) { - // TODO performance: can break if bestHope >= best; worth it? float jScore = mCandidates[j].score; if (jScore + bestHope >= best) continue; float delta = mCandidates[j].preBreak - leftEdge; - float widthScore = computeScore(delta, atEnd); + // TODO: for justified text, refine with shrink/stretch + float widthScore; if (delta < 0) { + widthScore = SCORE_OVERFULL; active = j + 1; } else { + widthScore = stretchIsFree ? 0 : delta * delta; bestHope = widthScore; } @@ -387,16 +258,23 @@ void LineBreaker::computeBreaksOptimalRect() { mCandidates[i].score = best + mCandidates[i].penalty; mCandidates[i].prev = bestPrev; } - finishBreaksOptimal(); + size_t prev; + for (size_t i = nCand - 1; i > 0; i = prev) { + prev = mCandidates[i].prev; + mBreaks.push_back(mCandidates[i].offset); + mWidths.push_back(mCandidates[i].postBreak - mCandidates[prev].preBreak); + mFlags.push_back(0); + } + std::reverse(mBreaks.begin(), mBreaks.end()); + std::reverse(mWidths.begin(), mWidths.end()); + std::reverse(mFlags.begin(), mFlags.end()); } size_t LineBreaker::computeBreaks() { if (mStrategy == kBreakStrategy_Greedy) { computeBreaksGreedy(); - } else if (mLineWidths.isConstant()) { - computeBreaksOptimalRect(); } else { - computeBreaksOptimal(); + computeBreaksOpt(); } return mBreaks.size(); } @@ -412,8 +290,6 @@ void LineBreaker::finish() { mTextBuf.shrink_to_fit(); mCharWidths.clear(); mCharWidths.shrink_to_fit(); - mHyphBuf.clear(); - mHyphBuf.shrink_to_fit(); mCandidates.shrink_to_fit(); mBreaks.shrink_to_fit(); mWidths.shrink_to_fit(); From c76f4113d73a9656c8f0565047dba843117c46fc Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 30 Mar 2015 14:20:18 -0700 Subject: [PATCH 074/364] Revert "Fix build: Revert "Add hyphenation to line breaking"" This reverts commit f8ed26a065cdb58adfa5df940bd2f0f6ae70d236. --- .../src/flutter/include/minikin/Hyphenator.h | 62 ++++++ .../src/flutter/include/minikin/LineBreaker.h | 45 ++-- engine/src/flutter/libs/minikin/Android.mk | 1 + .../src/flutter/libs/minikin/Hyphenator.cpp | 152 ++++++++++++++ .../src/flutter/libs/minikin/LineBreaker.cpp | 194 ++++++++++++++---- 5 files changed, 406 insertions(+), 48 deletions(-) create mode 100644 engine/src/flutter/include/minikin/Hyphenator.h create mode 100644 engine/src/flutter/libs/minikin/Hyphenator.cpp diff --git a/engine/src/flutter/include/minikin/Hyphenator.h b/engine/src/flutter/include/minikin/Hyphenator.h new file mode 100644 index 00000000000..581c657fbe6 --- /dev/null +++ b/engine/src/flutter/include/minikin/Hyphenator.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2015 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. + */ + +/** + * An implementation of Liang's hyphenation algorithm. + */ + +#include +#include + +#ifndef MINIKIN_HYPHENATOR_H +#define MINIKIN_HYPHENATOR_H + +namespace android { + +class Trie { +public: + std::vector result; + std::unordered_map succ; +}; + +class Hyphenator { +public: + // Note: this will also require a locale, for proper case folding behavior + static Hyphenator* load(const uint16_t* patternData, size_t size); + + // Compute the hyphenation of a word, storing the hyphenation in result vector. Each + // entry in the vector is a "hyphen edit" to be applied at the corresponding code unit + // offset in the word. Currently 0 means no hyphen and 1 means insert hyphen and break, + // but this will be expanded to other edits for nonstandard hyphenation. + // Example: word is "hyphen", result is [0 0 1 0 0 0], corresponding to "hy-phen". + void hyphenate(std::vector* result, const uint16_t* word, size_t len); + +private: + void addPattern(const uint16_t* pattern, size_t size); + + void hyphenateSoft(std::vector* result, const uint16_t* word, size_t len); + + // TODO: these should become parameters, as they might vary by locale, screen size, and + // possibly explicit user control. + static const int MIN_PREFIX = 2; + static const int MIN_SUFFIX = 3; + + Trie root; +}; + +} // namespace android + +#endif // MINIKIN_HYPHENATOR_H \ No newline at end of file diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index 29afba0bee9..92e72e249c0 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -26,6 +26,7 @@ #include "unicode/locid.h" #include #include +#include "minikin/Hyphenator.h" namespace android { @@ -43,6 +44,10 @@ class LineWidths { mFirstWidthLineCount = firstWidthLineCount; mRestWidth = restWidth; } + bool isConstant() const { + // technically mFirstWidthLineCount == 0 would count too, but doesn't actually happen + return mRestWidth == mFirstWidth; + } float getLineWidth(int line) const { return (line < mFirstWidthLineCount) ? mFirstWidth : mRestWidth; } @@ -77,6 +82,8 @@ class TabStops { class LineBreaker { public: + const static int kTab_Shift = 29; // keep synchronized with TAB_MASK in StaticLayout.java + ~LineBreaker() { utext_close(&mUText); delete mBreakIterator; @@ -88,13 +95,8 @@ class LineBreaker { // locale has actually changed. // That logic could be here but it's better for performance that it's upstream because of // the cost of constructing and comparing the ICU Locale object. - void setLocale(const icu::Locale& locale) { - delete mBreakIterator; - UErrorCode status = U_ZERO_ERROR; - mBreakIterator = icu::BreakIterator::createLineInstance(locale, status); - // TODO: check status - // TODO: load hyphenator from locale - } + // Note: caller is responsible for managing lifetime of hyphenator + void setLocale(const icu::Locale& locale, Hyphenator* hyphenator); void resize(size_t size) { mTextBuf.resize(size); @@ -130,8 +132,8 @@ class LineBreaker { // Minikin to do the shaping of the strings. The main thing that would need to be changed // is having some kind of callback (or virtual class, or maybe even template), which could // easily be instantiated with Minikin's Layout. Future work for when needed. - float addStyleRun(const MinikinPaint* paint, const FontCollection* typeface, - FontStyle style, size_t start, size_t end, bool isRtl); + float addStyleRun(MinikinPaint* paint, const FontCollection* typeface, FontStyle style, + size_t start, size_t end, bool isRtl); void addReplacement(size_t start, size_t end, float width); @@ -145,7 +147,7 @@ class LineBreaker { return mWidths.data(); } - const uint8_t* getFlags() const { + const int* getFlags() const { return mFlags.data(); } @@ -166,23 +168,40 @@ class LineBreaker { ParaWidth postBreak; float penalty; // penalty of this break (for example, hyphen penalty) float score; // best score found for this break + size_t lineNumber; // only updated for non-constant line widths + uint8_t hyphenEdit; }; float currentLineWidth() const; - void addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, float penalty); + // compute shrink/stretch penalty for line + float computeScore(float delta, bool atEnd); + + void addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, float penalty, + uint8_t hyph); void addCandidate(Candidate cand); + // push an actual break to the output. Takes care of setting flags for tab + void pushBreak(int offset, float width, uint8_t hyph); + void computeBreaksGreedy(); - void computeBreaksOpt(); + void computeBreaksOptimal(); + + // special case when LineWidth is constant (layout is rectangle) + void computeBreaksOptimalRect(); + + void finishBreaksOptimal(); icu::BreakIterator* mBreakIterator = nullptr; UText mUText = UTEXT_INITIALIZER; std::vectormTextBuf; std::vectormCharWidths; + Hyphenator* mHyphenator; + std::vector mHyphBuf; + // layout parameters BreakStrategy mStrategy = kBreakStrategy_Greedy; LineWidths mLineWidths; @@ -191,7 +210,7 @@ class LineBreaker { // result of line breaking std::vector mBreaks; std::vector mWidths; - std::vector mFlags; + std::vector mFlags; ParaWidth mWidth = 0; std::vector mCandidates; diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 54068243ee2..34b535cabd4 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -22,6 +22,7 @@ LOCAL_SRC_FILES := \ FontCollection.cpp \ FontFamily.cpp \ GraphemeBreak.cpp \ + Hyphenator.cpp \ Layout.cpp \ LineBreaker.cpp \ MinikinInternal.cpp \ diff --git a/engine/src/flutter/libs/minikin/Hyphenator.cpp b/engine/src/flutter/libs/minikin/Hyphenator.cpp new file mode 100644 index 00000000000..c50b3861af4 --- /dev/null +++ b/engine/src/flutter/libs/minikin/Hyphenator.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2015 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 +#include +#include +#include +#include + +// HACK: for reading pattern file +#include + +#define LOG_TAG "Minikin" +#include "utils/Log.h" + +#include "minikin/Hyphenator.h" + +using std::vector; + +namespace android { + +static const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; + +void Hyphenator::addPattern(const uint16_t* pattern, size_t size) { + vector word; + vector result; + + // start by parsing the Liang-format pattern into a word and a result vector, the + // vector right-aligned but without leading zeros. Examples: + // a1bc2d -> abcd [1, 0, 2, 0] + // abc1 -> abc [1] + // 1a2b3c4d5 -> abcd [1, 2, 3, 4, 5] + bool lastWasLetter = false; + bool haveSeenNumber = false; + for (size_t i = 0; i < size; i++) { + uint16_t c = pattern[i]; + if (isdigit(c)) { + result.push_back(c - '0'); + lastWasLetter = false; + haveSeenNumber = true; + } else { + word.push_back(c); + if (lastWasLetter && haveSeenNumber) { + result.push_back(0); + } + lastWasLetter = true; + } + } + if (lastWasLetter) { + result.push_back(0); + } + Trie* t = &root; + for (size_t i = 0; i < word.size(); i++) { + t = &t->succ[word[i]]; + } + t->result = result; +} + +// If any soft hyphen is present in the word, use soft hyphens to decide hyphenation, +// as recommended in UAX #14 (Use of Soft Hyphen) +void Hyphenator::hyphenateSoft(vector* result, const uint16_t* word, size_t len) { + (*result)[0] = 0; + for (size_t i = 1; i < len; i++) { + (*result)[i] = word[i - 1] == CHAR_SOFT_HYPHEN; + } +} + +void Hyphenator::hyphenate(vector* result, const uint16_t* word, size_t len) { + result->clear(); + result->resize(len); + if (len < MIN_PREFIX + MIN_SUFFIX) return; + size_t maxOffset = len - MIN_SUFFIX + 1; + for (size_t i = 0; i < len + 1; i++) { + const Trie* node = &root; + for (size_t j = i; j < len + 2; j++) { + uint16_t c; + if (j == 0 || j == len + 1) { + c = '.'; // word boundary character in pattern data files + } else { + c = word[j - 1]; + if (c == CHAR_SOFT_HYPHEN) { + hyphenateSoft(result, word, len); + return; + } + // TODO: use locale-sensitive case folding from ICU. + c = tolower(c); + } + auto search = node->succ.find(c); + if (search != node->succ.end()) { + node = &search->second; + } else { + break; + } + if (!node->result.empty()) { + int resultLen = node->result.size(); + int offset = j + 1 - resultLen; + int start = std::max(MIN_PREFIX - offset, 0); + int end = std::min(resultLen, (int)maxOffset - offset); + // TODO performance: this inner loop can profitably be optimized + for (int k = start; k < end; k++) { + (*result)[offset + k] = std::max((*result)[offset + k], node->result[k]); + } +#if 0 + // debug printing of matched patterns + std::string dbg; + for (size_t k = i; k <= j + 1; k++) { + int off = k - j - 2 + resultLen; + if (off >= 0 && node->result[off] != 0) { + dbg.push_back((char)('0' + node->result[off])); + } + if (k < j + 1) { + uint16_t c = (k == 0 || k == len + 1) ? '.' : word[k - 1]; + dbg.push_back((char)c); + } + } + ALOGD("%d:%d %s", i, j, dbg.c_str()); +#endif + } + } + } + // Since the above calculation does not modify values outside + // [MIN_PREFIX, len - MIN_SUFFIX], they are left as 0. + for (size_t i = MIN_PREFIX; i < maxOffset; i++) { + (*result)[i] &= 1; + } +} + +Hyphenator* Hyphenator::load(const uint16_t *patternData, size_t size) { + Hyphenator* result = new Hyphenator; + for (size_t i = 0; i < size; i++) { + size_t end = i; + while (patternData[end] != '\n') end++; + result->addPattern(patternData + i, end - i); + i = end; + } + return result; +} + +} // namespace android diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 99d7f69de54..f7f3fb3fd0c 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -29,6 +29,7 @@ using std::vector; namespace android { const int CHAR_TAB = 0x0009; +const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; // Large scores in a hierarchy; we prefer desperate breaks to an overfull line. All these // constants are larger than any reasonable actual width score. @@ -40,6 +41,16 @@ const float SCORE_DESPERATE = 1e10f; // to avoid allocation. const size_t MAX_TEXT_BUF_RETAIN = 32678; +void LineBreaker::setLocale(const icu::Locale& locale, Hyphenator* hyphenator) { + delete mBreakIterator; + UErrorCode status = U_ZERO_ERROR; + mBreakIterator = icu::BreakIterator::createLineInstance(locale, status); + // TODO: check status + + // TODO: load actual resource dependent on locale; letting Minikin do it is a hack + mHyphenator = hyphenator; +} + void LineBreaker::setText() { UErrorCode status = U_ZERO_ERROR; utext_openUChars(&mUText, mTextBuf.data(), mTextBuf.size(), &status); @@ -49,7 +60,7 @@ void LineBreaker::setText() { // handle initial break here because addStyleRun may never be called mBreakIterator->next(); mCandidates.clear(); - Candidate cand = {0, 0, 0.0, 0.0, 0.0, 0.0}; + Candidate cand = {0, 0, 0.0, 0.0, 0.0, 0.0, 0, 0}; mCandidates.push_back(cand); // reset greedy breaker state @@ -64,7 +75,6 @@ void LineBreaker::setText() { } void LineBreaker::setLineWidths(float firstWidth, int firstWidthLineCount, float restWidth) { - ALOGD("width %f", firstWidth); mLineWidths.setWidths(firstWidth, firstWidthLineCount, restWidth); } @@ -81,22 +91,29 @@ static bool isLineEndSpace(uint16_t c) { // width buffer. // This method finds the candidate word breaks (using the ICU break iterator) and sends them // to addCandidate. -float LineBreaker::addStyleRun(const MinikinPaint* paint, const FontCollection* typeface, +float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typeface, FontStyle style, size_t start, size_t end, bool isRtl) { Layout layout; // performance TODO: move layout to self object to reduce allocation cost? float width = 0.0f; int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR; + float hyphenPenalty = 0.0; if (paint != nullptr) { layout.setFontCollection(typeface); layout.doLayout(mTextBuf.data(), start, end - start, mTextBuf.size(), bidiFlags, style, *paint); layout.getAdvances(mCharWidths.data() + start); width = layout.getAdvance(); + + // a heuristic that seems to perform well + hyphenPenalty = 0.5 * paint->size * paint->scaleX * mLineWidths.getLineWidth(0); } - ParaWidth postBreak = mWidth; size_t current = (size_t)mBreakIterator->current(); + size_t wordEnd = start; + size_t lastBreak = start; + ParaWidth lastBreakWidth = mWidth; + ParaWidth postBreak = mWidth; for (size_t i = start; i < end; i++) { uint16_t c = mTextBuf[i]; if (c == CHAR_TAB) { @@ -110,14 +127,48 @@ float LineBreaker::addStyleRun(const MinikinPaint* paint, const FontCollection* mWidth += mCharWidths[i]; if (!isLineEndSpace(c)) { postBreak = mWidth; + wordEnd = i + 1; } } if (i + 1 == current) { - // TODO: hyphenation goes here + // Override ICU's treatment of soft hyphen as a break opportunity, because we want it + // to be a hyphen break, with penalty and drawing behavior. + if (c != CHAR_SOFT_HYPHEN) { + if (paint != nullptr && mHyphenator != nullptr && wordEnd > lastBreak) { + mHyphenator->hyphenate(&mHyphBuf, &mTextBuf[lastBreak], wordEnd - lastBreak); + #if VERBOSE_DEBUG + std::string hyphenatedString; + for (size_t j = lastBreak; j < wordEnd; j++) { + if (mHyphBuf[j - lastBreak]) hyphenatedString.push_back('-'); + // Note: only works with ASCII, should do UTF-8 conversion here + hyphenatedString.push_back(buffer()[j]); + } + ALOGD("hyphenated string: %s", hyphenatedString.c_str()); + #endif - // Skip break for zero-width characters. - if (current == mTextBuf.size() || mCharWidths[current] > 0) { - addWordBreak(current, mWidth, postBreak, 0); + // measure hyphenated substrings + for (size_t j = lastBreak; j < wordEnd; j++) { + uint8_t hyph = mHyphBuf[j - lastBreak]; + if (hyph) { + paint->hyphenEdit = hyph; + layout.doLayout(mTextBuf.data(), lastBreak, j - lastBreak, + mTextBuf.size(), bidiFlags, style, *paint); + ParaWidth hyphPostBreak = lastBreakWidth + layout.getAdvance(); + paint->hyphenEdit = 0; + layout.doLayout(mTextBuf.data(), j, wordEnd - j, + mTextBuf.size(), bidiFlags, style, *paint); + ParaWidth hyphPreBreak = postBreak - layout.getAdvance(); + addWordBreak(j, hyphPreBreak, hyphPostBreak, hyphenPenalty, hyph); + } + } + } + + // Skip break for zero-width characters. + if (current == mTextBuf.size() || mCharWidths[current] > 0) { + addWordBreak(current, mWidth, postBreak, 0.0, 0); + } + lastBreak = current; + lastBreakWidth = mWidth; } current = (size_t)mBreakIterator->next(); } @@ -129,7 +180,7 @@ float LineBreaker::addStyleRun(const MinikinPaint* paint, const FontCollection* // add a word break (possibly for a hyphenated fragment), and add desperate breaks if // needed (ie when word exceeds current line width) void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, - float penalty) { + float penalty, uint8_t hyph) { Candidate cand; ParaWidth width = mCandidates.back().preBreak; if (postBreak - width > currentLineWidth()) { @@ -145,6 +196,7 @@ void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth post cand.preBreak = width; cand.postBreak = width; cand.penalty = SCORE_DESPERATE; + cand.hyphenEdit = 0; #if VERBOSE_DEBUG ALOGD("desperate cand: %d %g:%g", mCandidates.size(), cand.postBreak, cand.preBreak); @@ -159,12 +211,24 @@ void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth post cand.preBreak = preBreak; cand.postBreak = postBreak; cand.penalty = penalty; + cand.hyphenEdit = hyph; #if VERBOSE_DEBUG ALOGD("cand: %d %g:%g", mCandidates.size(), cand.postBreak, cand.preBreak); #endif addCandidate(cand); } +// TODO: for justified text, refine with shrink/stretch +float LineBreaker::computeScore(float delta, bool atEnd) { + if (delta < 0) { + return SCORE_OVERFULL; + } else if (atEnd && mStrategy != kBreakStrategy_Balanced) { + return 0.0; + } else { + return delta * delta; + } +} + // TODO performance: could avoid populating mCandidates if greedy only void LineBreaker::addCandidate(Candidate cand) { size_t candIndex = mCandidates.size(); @@ -174,10 +238,8 @@ void LineBreaker::addCandidate(Candidate cand) { if (mBestBreak == mLastBreak) { mBestBreak = candIndex; } - mBreaks.push_back(mCandidates[mBestBreak].offset); - mWidths.push_back(mCandidates[mBestBreak].postBreak - mPreBreak); - mFlags.push_back(mFirstTabIndex < mBreaks.back()); - mFirstTabIndex = INT_MAX; + pushBreak(mCandidates[mBestBreak].offset, mCandidates[mBestBreak].postBreak - mPreBreak, + mCandidates[mBestBreak].hyphenEdit); mBestScore = SCORE_INFTY; #if VERBOSE_DEBUG ALOGD("break: %d %g", mBreaks.back(), mWidths.back()); @@ -191,6 +253,15 @@ void LineBreaker::addCandidate(Candidate cand) { } } +void LineBreaker::pushBreak(int offset, float width, uint8_t hyph) { + mBreaks.push_back(offset); + mWidths.push_back(width); + int flags = (mFirstTabIndex < mBreaks.back()) << kTab_Shift; + flags |= hyph; + mFlags.push_back(flags); + mFirstTabIndex = INT_MAX; +} + void LineBreaker::addReplacement(size_t start, size_t end, float width) { mCharWidths[start] = width; std::fill(&mCharWidths[start + 1], &mCharWidths[end], 0.0f); @@ -205,27 +276,87 @@ void LineBreaker::computeBreaksGreedy() { // All breaks but the last have been added in addCandidate already. size_t nCand = mCandidates.size(); if (nCand == 1 || mLastBreak != nCand - 1) { - mBreaks.push_back(mCandidates[nCand - 1].offset); - mWidths.push_back(mCandidates[nCand - 1].postBreak - mPreBreak); - mFlags.push_back(mFirstTabIndex < mBreaks.back()); - // don't need to update mFirstTabIndex or mBestScore, because we're done + pushBreak(mCandidates[nCand - 1].offset, mCandidates[nCand - 1].postBreak - mPreBreak, 0); + // don't need to update mBestScore, because we're done #if VERBOSE_DEBUG ALOGD("final break: %d %g", mBreaks.back(), mWidths.back()); #endif } } -void LineBreaker::computeBreaksOpt() { +// Follow "prev" links in mCandidates array, and copy to result arrays. +void LineBreaker::finishBreaksOptimal() { // clear existing greedy break result mBreaks.clear(); mWidths.clear(); mFlags.clear(); + size_t nCand = mCandidates.size(); + size_t prev; + for (size_t i = nCand - 1; i > 0; i = prev) { + prev = mCandidates[i].prev; + mBreaks.push_back(mCandidates[i].offset); + mWidths.push_back(mCandidates[i].postBreak - mCandidates[prev].preBreak); + mFlags.push_back(mCandidates[i].hyphenEdit); + } + std::reverse(mBreaks.begin(), mBreaks.end()); + std::reverse(mWidths.begin(), mWidths.end()); + std::reverse(mFlags.begin(), mFlags.end()); +} + +void LineBreaker::computeBreaksOptimal() { + size_t active = 0; + size_t nCand = mCandidates.size(); + for (size_t i = 1; i < nCand; i++) { + bool atEnd = i == nCand - 1; + float best = SCORE_INFTY; + size_t bestPrev = 0; + + size_t lineNumberLast = mCandidates[active].lineNumber; + float width = mLineWidths.getLineWidth(lineNumberLast); + ParaWidth leftEdge = mCandidates[i].postBreak - width; + float bestHope = 0; + + for (size_t j = active; j < i; j++) { + size_t lineNumber = mCandidates[j].lineNumber; + if (lineNumber != lineNumberLast) { + float widthNew = mLineWidths.getLineWidth(lineNumber); + if (widthNew != width) { + leftEdge = mCandidates[i].postBreak - width; + bestHope = 0; + width = widthNew; + } + lineNumberLast = lineNumber; + } + float jScore = mCandidates[j].score; + if (jScore + bestHope >= best) continue; + float delta = mCandidates[j].preBreak - leftEdge; + + float widthScore = computeScore(delta, atEnd); + if (delta < 0) { + active = j + 1; + } else { + bestHope = widthScore; + } + + float score = jScore + widthScore; + if (score <= best) { + best = score; + bestPrev = j; + } + } + mCandidates[i].score = best + mCandidates[i].penalty; + mCandidates[i].prev = bestPrev; + mCandidates[i].lineNumber = mCandidates[bestPrev].lineNumber + 1; + } + finishBreaksOptimal(); +} + +void LineBreaker::computeBreaksOptimalRect() { size_t active = 0; size_t nCand = mCandidates.size(); float width = mLineWidths.getLineWidth(0); - // TODO: actually support non-constant width for (size_t i = 1; i < nCand; i++) { - bool stretchIsFree = mStrategy != kBreakStrategy_Balanced && i == nCand - 1; + bool atEnd = i == nCand - 1; float best = SCORE_INFTY; size_t bestPrev = 0; @@ -235,17 +366,15 @@ void LineBreaker::computeBreaksOpt() { ParaWidth leftEdge = mCandidates[i].postBreak - width; for (size_t j = active; j < i; j++) { + // TODO performance: can break if bestHope >= best; worth it? float jScore = mCandidates[j].score; if (jScore + bestHope >= best) continue; float delta = mCandidates[j].preBreak - leftEdge; - // TODO: for justified text, refine with shrink/stretch - float widthScore; + float widthScore = computeScore(delta, atEnd); if (delta < 0) { - widthScore = SCORE_OVERFULL; active = j + 1; } else { - widthScore = stretchIsFree ? 0 : delta * delta; bestHope = widthScore; } @@ -258,23 +387,16 @@ void LineBreaker::computeBreaksOpt() { mCandidates[i].score = best + mCandidates[i].penalty; mCandidates[i].prev = bestPrev; } - size_t prev; - for (size_t i = nCand - 1; i > 0; i = prev) { - prev = mCandidates[i].prev; - mBreaks.push_back(mCandidates[i].offset); - mWidths.push_back(mCandidates[i].postBreak - mCandidates[prev].preBreak); - mFlags.push_back(0); - } - std::reverse(mBreaks.begin(), mBreaks.end()); - std::reverse(mWidths.begin(), mWidths.end()); - std::reverse(mFlags.begin(), mFlags.end()); + finishBreaksOptimal(); } size_t LineBreaker::computeBreaks() { if (mStrategy == kBreakStrategy_Greedy) { computeBreaksGreedy(); + } else if (mLineWidths.isConstant()) { + computeBreaksOptimalRect(); } else { - computeBreaksOpt(); + computeBreaksOptimal(); } return mBreaks.size(); } @@ -290,6 +412,8 @@ void LineBreaker::finish() { mTextBuf.shrink_to_fit(); mCharWidths.clear(); mCharWidths.shrink_to_fit(); + mHyphBuf.clear(); + mHyphBuf.shrink_to_fit(); mCandidates.shrink_to_fit(); mBreaks.shrink_to_fit(); mWidths.shrink_to_fit(); From 201d89470128e5b3fbb913cfca2c0b11b7713a88 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 14 Apr 2015 18:29:39 -0700 Subject: [PATCH 075/364] Add margins array to line widths object In order to support layout in non-rectangular regions, the LineWidths object needs to accept an arbitrary array of margins. This is implemented in addition to the existing firstWidthLineCount/restWidth mechanism for convenience, though using only arrays would have the same expressive power. Bug: 20182243 Change-Id: Iea96bca1a92012314ac27e617c67f306c1f1b2f2 --- .../src/flutter/include/minikin/LineBreaker.h | 18 ++++++++++++++++-- .../src/flutter/libs/minikin/LineBreaker.cpp | 5 +++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index 92e72e249c0..eb501e7cc85 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -44,17 +44,29 @@ class LineWidths { mFirstWidthLineCount = firstWidthLineCount; mRestWidth = restWidth; } + void setMargins(const std::vector& margins) { + mMargins = margins; + } bool isConstant() const { // technically mFirstWidthLineCount == 0 would count too, but doesn't actually happen - return mRestWidth == mFirstWidth; + return mRestWidth == mFirstWidth && mMargins.empty(); } float getLineWidth(int line) const { - return (line < mFirstWidthLineCount) ? mFirstWidth : mRestWidth; + float width = (line < mFirstWidthLineCount) ? mFirstWidth : mRestWidth; + if (!mMargins.empty()) { + if ((size_t)line < mMargins.size()) { + width -= mMargins[line]; + } else { + width -= mMargins.back(); + } + } + return width; } private: float mFirstWidth; int mFirstWidthLineCount; float mRestWidth; + std::vector mMargins; }; class TabStops { @@ -120,6 +132,8 @@ class LineBreaker { void setLineWidths(float firstWidth, int firstWidthLineCount, float restWidth); + void setMargins(const std::vector& margins); + void setTabStops(const int* stops, size_t nStops, int tabWidth) { mTabStops.set(stops, nStops, tabWidth); } diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index f7f3fb3fd0c..9298f77848c 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -78,6 +78,11 @@ void LineBreaker::setLineWidths(float firstWidth, int firstWidthLineCount, float mLineWidths.setWidths(firstWidth, firstWidthLineCount, restWidth); } + +void LineBreaker::setMargins(const std::vector& margins) { + mLineWidths.setMargins(margins); +} + // This function determines whether a character is a space that disappears at end of line. // It is the Unicode set: [[:General_Category=Space_Separator:]-[:Line_Break=Glue:]] // Note: all such characters are in the BMP, so it's ok to use code units for this. From 6705d6ff2ad1aa43fae0b665aaca2482ae079763 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 15 Apr 2015 15:22:42 -0700 Subject: [PATCH 076/364] Rename "margins" to "indents" The name "margin" conflicts with another meaning, so we're making the name in the public api "idents" and the code consistent in naming. Change-Id: I9170116b4d972e4b25f0f319e78376310288eb41 --- .../src/flutter/include/minikin/LineBreaker.h | 18 +++++++++--------- .../src/flutter/libs/minikin/LineBreaker.cpp | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index eb501e7cc85..ebe5dc44325 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -44,20 +44,20 @@ class LineWidths { mFirstWidthLineCount = firstWidthLineCount; mRestWidth = restWidth; } - void setMargins(const std::vector& margins) { - mMargins = margins; + void setIndents(const std::vector& indents) { + mIndents = indents; } bool isConstant() const { // technically mFirstWidthLineCount == 0 would count too, but doesn't actually happen - return mRestWidth == mFirstWidth && mMargins.empty(); + return mRestWidth == mFirstWidth && mIndents.empty(); } float getLineWidth(int line) const { float width = (line < mFirstWidthLineCount) ? mFirstWidth : mRestWidth; - if (!mMargins.empty()) { - if ((size_t)line < mMargins.size()) { - width -= mMargins[line]; + if (!mIndents.empty()) { + if ((size_t)line < mIndents.size()) { + width -= mIndents[line]; } else { - width -= mMargins.back(); + width -= mIndents.back(); } } return width; @@ -66,7 +66,7 @@ class LineWidths { float mFirstWidth; int mFirstWidthLineCount; float mRestWidth; - std::vector mMargins; + std::vector mIndents; }; class TabStops { @@ -132,7 +132,7 @@ class LineBreaker { void setLineWidths(float firstWidth, int firstWidthLineCount, float restWidth); - void setMargins(const std::vector& margins); + void setIndents(const std::vector& indents); void setTabStops(const int* stops, size_t nStops, int tabWidth) { mTabStops.set(stops, nStops, tabWidth); diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 9298f77848c..f4201cb26b7 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -79,8 +79,8 @@ void LineBreaker::setLineWidths(float firstWidth, int firstWidthLineCount, float } -void LineBreaker::setMargins(const std::vector& margins) { - mLineWidths.setMargins(margins); +void LineBreaker::setIndents(const std::vector& indents) { + mLineWidths.setIndents(indents); } // This function determines whether a character is a space that disappears at end of line. From 05e89cffd41e8d1562a1d51422958a08726f7dd8 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 6 Apr 2015 16:21:10 -0700 Subject: [PATCH 077/364] Add functions for measuring cursor positioning New functions for computing the correspondence between cursor position and advance, respecting grapheme boundaries. Change-Id: I620378d5f64cd74300cd43db522adeb555825dff --- engine/src/flutter/include/minikin/Layout.h | 6 +- .../src/flutter/include/minikin/Measurement.h | 31 +++++ engine/src/flutter/libs/minikin/Android.mk | 1 + .../flutter/libs/minikin/GraphemeBreak.cpp | 8 +- .../src/flutter/libs/minikin/Measurement.cpp | 116 ++++++++++++++++++ 5 files changed, 157 insertions(+), 5 deletions(-) create mode 100644 engine/src/flutter/include/minikin/Measurement.h create mode 100644 engine/src/flutter/libs/minikin/Measurement.cpp diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 543f553ce10..930407a52b6 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -106,9 +106,13 @@ public: float getAdvance() const; // Get advances, copying into caller-provided buffer. The size of this - // buffer must match the length of the string (nchars arg to doLayout). + // buffer must match the length of the string (count arg to doLayout). void getAdvances(float* advances); + // The i parameter is an offset within the buf relative to start, it is < count, where + // start and count are the parameters to doLayout + float getCharAdvance(size_t i) const { return mAdvances[i]; } + void getBounds(MinikinRect* rect); // Purge all caches, useful in low memory conditions diff --git a/engine/src/flutter/include/minikin/Measurement.h b/engine/src/flutter/include/minikin/Measurement.h new file mode 100644 index 00000000000..fc47fa31620 --- /dev/null +++ b/engine/src/flutter/include/minikin/Measurement.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2015 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_MEASUREMENT_H +#define MINIKIN_MEASUREMENT_H + +#include + +namespace android { + +float getRunAdvance(Layout& layout, const uint16_t* buf, size_t start, size_t count, size_t offset); + +size_t getOffsetForAdvance(Layout& layout, const uint16_t* buf, size_t start, size_t count, + float advance); + +} + +#endif // MINIKIN_MEASUREMENT_H diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 34b535cabd4..873f279f0c9 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -25,6 +25,7 @@ LOCAL_SRC_FILES := \ Hyphenator.cpp \ Layout.cpp \ LineBreaker.cpp \ + Measurement.cpp \ MinikinInternal.cpp \ MinikinRefCounted.cpp \ MinikinFontFreeType.cpp \ diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index 5d8978d66f1..f8f386c0de9 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -41,7 +41,7 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co uint32_t c2 = 0; size_t offset_back = offset; U16_PREV(buf, start, offset_back, c1); - U16_NEXT(buf, offset, count, c2); + U16_NEXT(buf, offset, start + count, c2); int32_t p1 = u_getIntPropertyValue(c1, UCHAR_GRAPHEME_CLUSTER_BREAK); int32_t p2 = u_getIntPropertyValue(c2, UCHAR_GRAPHEME_CLUSTER_BREAK); // Rule GB3, CR x LF @@ -54,7 +54,7 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co } // Rule GB5, / (Control | CR | LF) if (p2 == U_GCB_CONTROL || p2 == U_GCB_CR || p2 == U_GCB_LF) { - // exclude zero-width control characters from breaking (tailoring of TR29) + // exclude zero-width control characters from breaking (tailoring of UAX #29) if (c2 == 0x00ad || (c2 >= 0x200b && c2 <= 0x200f) || (c2 >= 0x2028 && c2 <= 0x202e) @@ -83,12 +83,12 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co if (p2 == U_GCB_EXTEND || p2 == U_GCB_SPACING_MARK) { if (c2 == 0xe33) { // most other implementations break THAI CHARACTER SARA AM - // (tailoring of TR29) + // (tailoring of UAX #29) return true; } return false; } - // Cluster indic syllables togeter (tailoring of TR29) + // Cluster indic syllables together (tailoring of UAX #29) if (u_getIntPropertyValue(c1, UCHAR_CANONICAL_COMBINING_CLASS) == 9 // virama && u_getIntPropertyValue(c2, UCHAR_GENERAL_CATEGORY) == U_OTHER_LETTER) { return false; diff --git a/engine/src/flutter/libs/minikin/Measurement.cpp b/engine/src/flutter/libs/minikin/Measurement.cpp new file mode 100644 index 00000000000..21df5d8234c --- /dev/null +++ b/engine/src/flutter/libs/minikin/Measurement.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2015 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. + */ + +#define LOG_TAG "Minikin" +#include + +#include +#include + +#include +#include + +namespace android { + +// These could be considered helper methods of layout, but need only be loosely coupled, so +// are separate. + +float getRunAdvance(Layout& layout, const uint16_t* buf, size_t start, size_t count, + size_t offset) { + float advance = 0.0f; + size_t lastCluster = start; + float clusterWidth = 0.0f; + for (size_t i = start; i < offset; i++) { + float charAdvance = layout.getCharAdvance(i - start); + if (charAdvance != 0.0f) { + advance += charAdvance; + lastCluster = i; + clusterWidth = charAdvance; + } + } + if (offset < start + count && layout.getCharAdvance(offset) == 0.0f) { + // In the middle of a cluster, distribute width of cluster so that each grapheme cluster + // gets an equal share. + // TODO: get caret information out of font when that's available + size_t nextCluster; + for (nextCluster = offset + 1; nextCluster < start + count; nextCluster++) { + if (layout.getCharAdvance(nextCluster - start) != 0.0f) break; + } + int numGraphemeClusters = 0; + int numGraphemeClustersAfter = 0; + for (size_t i = lastCluster; i < nextCluster; i++) { + bool isAfter = i >= offset; + if (GraphemeBreak::isGraphemeBreak(buf, start, count, i)) { + numGraphemeClusters++; + if (isAfter) { + numGraphemeClustersAfter++; + } + } + } + if (numGraphemeClusters > 0) { + advance -= clusterWidth * numGraphemeClustersAfter / numGraphemeClusters; + } + } + return advance; +} + +/** + * Essentially the inverse of getRunAdvance. Compute the value of offset for which the + * measured caret comes closest to the provided advance param, and which is on a grapheme + * cluster boundary. + * + * The actual implementation fast-forwards through clusters to get "close", then does a finer-grain + * search within the cluster and grapheme breaks. + */ +size_t getOffsetForAdvance(Layout& layout, const uint16_t* buf, size_t start, size_t count, + float advance) { + float x = 0.0f, xLastClusterStart = 0.0f, xSearchStart = 0.0f; + size_t lastClusterStart = start, searchStart = start; + for (size_t i = start; i < start + count; i++) { + if (GraphemeBreak::isGraphemeBreak(buf, start, count, i)) { + searchStart = lastClusterStart; + xSearchStart = xLastClusterStart; + } + float width = layout.getCharAdvance(i - start); + if (width != 0.0f) { + lastClusterStart = i; + xLastClusterStart = x; + x += width; + if (x > advance) { + break; + } + } + } + size_t best = searchStart; + float bestDist = FLT_MAX; + for (size_t i = searchStart; i <= start + count; i++) { + if (GraphemeBreak::isGraphemeBreak(buf, start, count, i)) { + // "getRunAdvance(layout, buf, start, count, bufSize, i) - advance" but more efficient + float delta = getRunAdvance(layout, buf, searchStart, count, i) + xSearchStart + - advance; + if (std::abs(delta) < bestDist) { + bestDist = std::abs(delta); + best = i; + } + if (delta >= 0.0f) { + break; + } + } + } + return best; +} + +} From d24df3eb94bf54e19d3e57163c180dfee01a0ba7 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 22 Apr 2015 15:31:29 -0700 Subject: [PATCH 078/364] Don't include trailing newline in width for line breaking In a paragraph with a trailing newline, the width of the newline character was included in the line width for breaking purposes, basically as if it were a non-breaking space. This caused a discrepancy, where Layout.getDesiredWidth() suggested that the text would fit in a single line, but StaticLayout would break it because of the added width of the newline character. The proposed fix is simply to consider newline to be a space that disappears at the end of a line. Bug: 20152308 Change-Id: I539574c5b8ea892c8ed6aca6c59e90ccdf74a680 --- engine/src/flutter/libs/minikin/LineBreaker.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index f4201cb26b7..88190fff6f5 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -84,11 +84,12 @@ void LineBreaker::setIndents(const std::vector& indents) { } // This function determines whether a character is a space that disappears at end of line. -// It is the Unicode set: [[:General_Category=Space_Separator:]-[:Line_Break=Glue:]] +// It is the Unicode set: [[:General_Category=Space_Separator:]-[:Line_Break=Glue:]], +// plus '\n'. // Note: all such characters are in the BMP, so it's ok to use code units for this. static bool isLineEndSpace(uint16_t c) { - return c == ' ' || c == 0x1680 || (0x2000 <= c && c <= 0x200A && c != 0x2007) || c == 0x205F || - c == 0x3000; + return c == '\n' || c == ' ' || c == 0x1680 || (0x2000 <= c && c <= 0x200A && c != 0x2007) || + c == 0x205F || c == 0x3000; } // Ordinarily, this method measures the text in the range given. However, when paint From 1be122da962f68ce6cfb0a10fd292f14b9afd1b4 Mon Sep 17 00:00:00 2001 From: John Reck Date: Thu, 16 Apr 2015 15:27:12 -0700 Subject: [PATCH 079/364] Move Bitmap to a different namespace namespace naming collision. Move minikin's Bitmap out of android:: and into minikin:: Change-Id: I5ae3925f81b848dc79576429ab55243b96f7fed2 --- engine/src/flutter/include/minikin/Layout.h | 10 ++- engine/src/flutter/libs/minikin/Layout.cpp | 82 +++++++++++---------- engine/src/flutter/sample/example.cpp | 8 +- 3 files changed, 53 insertions(+), 47 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 930407a52b6..cdf4aac5236 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -24,7 +24,7 @@ #include #include -namespace android { +namespace minikin { // The Bitmap class is for debugging. We'll probably move it out // of here into a separate lightweight software rendering module @@ -34,13 +34,17 @@ public: Bitmap(int width, int height); ~Bitmap(); void writePnm(std::ofstream& o) const; - void drawGlyph(const GlyphBitmap& bitmap, int x, int y); + void drawGlyph(const android::GlyphBitmap& bitmap, int x, int y); private: int width; int height; uint8_t* buf; }; +} // namespace minikin + +namespace android { + struct LayoutGlyph { // index into mFaces and mHbFonts vectors. We could imagine // moving this into a run length representation, because it's @@ -89,7 +93,7 @@ public: void doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint); - void draw(Bitmap*, int x0, int y0, float size) const; + void draw(minikin::Bitmap*, int x0, int y0, float size) const; // Deprecated. Nont needed. Remove when callers are removed. static void init(); diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 28dac7f644b..88baeac6f55 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -41,6 +41,48 @@ using std::string; using std::vector; +namespace minikin { + +Bitmap::Bitmap(int width, int height) : width(width), height(height) { + buf = new uint8_t[width * height](); +} + +Bitmap::~Bitmap() { + delete[] buf; +} + +void Bitmap::writePnm(std::ofstream &o) const { + o << "P5" << std::endl; + o << width << " " << height << std::endl; + o << "255" << std::endl; + o.write((const char *)buf, width * height); + o.close(); +} + +void Bitmap::drawGlyph(const android::GlyphBitmap& bitmap, int x, int y) { + int bmw = bitmap.width; + int bmh = bitmap.height; + x += bitmap.left; + y -= bitmap.top; + int x0 = std::max(0, x); + int x1 = std::min(width, x + bmw); + int y0 = std::max(0, y); + int y1 = std::min(height, y + bmh); + const unsigned char* src = bitmap.buffer + (y0 - y) * bmw + (x0 - x); + uint8_t* dst = buf + y0 * width; + for (int yy = y0; yy < y1; yy++) { + for (int xx = x0; xx < x1; xx++) { + int pixel = (int)dst[xx] + (int)src[xx - x]; + pixel = pixel > 0xff ? 0xff : pixel; + dst[xx] = pixel; + } + src += bmw; + dst += width; + } +} + +} // namespace minikin + namespace android { const int kDirection_Mask = 0x1; @@ -218,44 +260,6 @@ hash_t hash_type(const LayoutCacheKey& key) { return key.hash(); } -Bitmap::Bitmap(int width, int height) : width(width), height(height) { - buf = new uint8_t[width * height](); -} - -Bitmap::~Bitmap() { - delete[] buf; -} - -void Bitmap::writePnm(std::ofstream &o) const { - o << "P5" << std::endl; - o << width << " " << height << std::endl; - o << "255" << std::endl; - o.write((const char *)buf, width * height); - o.close(); -} - -void Bitmap::drawGlyph(const GlyphBitmap& bitmap, int x, int y) { - int bmw = bitmap.width; - int bmh = bitmap.height; - x += bitmap.left; - y -= bitmap.top; - int x0 = std::max(0, x); - int x1 = std::min(width, x + bmw); - int y0 = std::max(0, y); - int y1 = std::min(height, y + bmh); - const unsigned char* src = bitmap.buffer + (y0 - y) * bmw + (x0 - x); - uint8_t* dst = buf + y0 * width; - for (int yy = y0; yy < y1; yy++) { - for (int xx = x0; xx < x1; xx++) { - int pixel = (int)dst[xx] + (int)src[xx - x]; - pixel = pixel > 0xff ? 0xff : pixel; - dst[xx] = pixel; - } - src += bmw; - dst += width; - } -} - void MinikinRect::join(const MinikinRect& r) { if (isEmpty()) { set(r); @@ -814,7 +818,7 @@ void Layout::appendLayout(Layout* src, size_t start) { } } -void Layout::draw(Bitmap* surface, int x0, int y0, float size) const { +void Layout::draw(minikin::Bitmap* surface, int x0, int y0, float size) const { /* TODO: redo as MinikinPaint settings if (mProps.hasTag(minikinHinting)) { diff --git a/engine/src/flutter/sample/example.cpp b/engine/src/flutter/sample/example.cpp index 487357a47bf..3fbfa7910e0 100644 --- a/engine/src/flutter/sample/example.cpp +++ b/engine/src/flutter/sample/example.cpp @@ -28,8 +28,8 @@ #include using std::vector; - -namespace android { +using namespace android; +using namespace minikin; FT_Library library; // TODO: this should not be a global @@ -99,8 +99,6 @@ int runMinikinTest() { return 0; } -} - int main(int argc, const char** argv) { - return android::runMinikinTest(); + return runMinikinTest(); } From e92a3c62b5b6ae85516cca5a49920e225dd53d93 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Tue, 12 May 2015 14:35:24 -0700 Subject: [PATCH 080/364] Support hyphenation frequency in Minikin. Three hyphenation frequencies are now supported: kHyphenationFrequency_None, which turns off both automatic hyphenation and soft hyphens. kHyphenationFrequency_Normal, which has aconservative amount of hyphenation useful as a conservative default. kHyphenationFrequency_Full, which has a typographic-quality amount of hyphenation useful for running text and tight screens. Bug: 21038249 Change-Id: I2800f718c887c9389a1a059d7ec07d7fa2ca1dee --- engine/src/flutter/include/minikin/LineBreaker.h | 13 +++++++++++++ engine/src/flutter/libs/minikin/LineBreaker.cpp | 8 +++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index ebe5dc44325..36314fb5114 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -36,6 +36,12 @@ enum BreakStrategy { kBreakStrategy_Balanced = 2 }; +enum HyphenationFrequency { + kHyphenationFrequency_None = 0, + kHyphenationFrequency_Normal = 1, + kHyphenationFrequency_Full = 2 +}; + // TODO: want to generalize to be able to handle array of line widths class LineWidths { public: @@ -142,6 +148,12 @@ class LineBreaker { void setStrategy(BreakStrategy strategy) { mStrategy = strategy; } + HyphenationFrequency getHyphenationFrequency() const { return mHyphenationFrequency; } + + void setHyphenationFrequency(HyphenationFrequency frequency) { + mHyphenationFrequency = frequency; + } + // TODO: this class is actually fairly close to being general and not tied to using // Minikin to do the shaping of the strings. The main thing that would need to be changed // is having some kind of callback (or virtual class, or maybe even template), which could @@ -218,6 +230,7 @@ class LineBreaker { // layout parameters BreakStrategy mStrategy = kBreakStrategy_Greedy; + HyphenationFrequency mHyphenationFrequency = kHyphenationFrequency_Normal; LineWidths mLineWidths; TabStops mTabStops; diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 88190fff6f5..5eb077c5aac 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -113,6 +113,9 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa // a heuristic that seems to perform well hyphenPenalty = 0.5 * paint->size * paint->scaleX * mLineWidths.getLineWidth(0); + if (mHyphenationFrequency == kHyphenationFrequency_Normal) { + hyphenPenalty *= 4.0; // TODO: Replace with a better value after some testing + } } size_t current = (size_t)mBreakIterator->current(); @@ -140,7 +143,9 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa // Override ICU's treatment of soft hyphen as a break opportunity, because we want it // to be a hyphen break, with penalty and drawing behavior. if (c != CHAR_SOFT_HYPHEN) { - if (paint != nullptr && mHyphenator != nullptr && wordEnd > lastBreak) { + if (paint != nullptr && mHyphenator != nullptr && + mHyphenationFrequency != kHyphenationFrequency_None && + wordEnd > lastBreak) { mHyphenator->hyphenate(&mHyphBuf, &mTextBuf[lastBreak], wordEnd - lastBreak); #if VERBOSE_DEBUG std::string hyphenatedString; @@ -426,6 +431,7 @@ void LineBreaker::finish() { mFlags.shrink_to_fit(); } mStrategy = kBreakStrategy_Greedy; + mHyphenationFrequency = kHyphenationFrequency_Normal; } } // namespace android From e6fff385b6b966b15dc4901a2737ffc521985b9b Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 1 Jun 2015 11:22:07 -0700 Subject: [PATCH 081/364] Disable hyphenation for unreasonably long words Very long words cause O(n^2) behavior. These are unlikely to happen in real text, but do happen with synthetic strings, so in those cases we just disable hyphenation. Bug: 20790394 Change-Id: Idf957dd40b24efe1476f619f17093a48b5bc56f7 --- engine/src/flutter/libs/minikin/LineBreaker.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 5eb077c5aac..dbd6ea8206b 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -37,6 +37,12 @@ const float SCORE_INFTY = std::numeric_limits::max(); const float SCORE_OVERFULL = 1e12f; const float SCORE_DESPERATE = 1e10f; +// Very long words trigger O(n^2) behavior in hyphenation, so we disable hyphenation for +// unreasonably long words. This is somewhat of a heuristic because extremely long words +// are possible in some languages. This does mean that very long real words can get +// broken by desperate breaks, with no hyphens. +const size_t LONGEST_HYPHENATED_WORD = 45; + // When the text buffer is within this limit, capacity of vectors is retained at finish(), // to avoid allocation. const size_t MAX_TEXT_BUF_RETAIN = 32678; @@ -145,7 +151,7 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa if (c != CHAR_SOFT_HYPHEN) { if (paint != nullptr && mHyphenator != nullptr && mHyphenationFrequency != kHyphenationFrequency_None && - wordEnd > lastBreak) { + wordEnd > lastBreak && wordEnd - lastBreak <= LONGEST_HYPHENATED_WORD) { mHyphenator->hyphenate(&mHyphBuf, &mTextBuf[lastBreak], wordEnd - lastBreak); #if VERBOSE_DEBUG std::string hyphenatedString; From b77d0bd01bfe7796be599667b38fa6dfd074d59a Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 1 Jun 2015 14:27:00 -0700 Subject: [PATCH 082/364] Use context start correctly in getRunAdvance We were not taking context start into account when deciding whether to split a ligature, which was causing inconsistent behavior. This patch consistently references the widths array relative to the start of the context. Bug: 21549197 Change-Id: I7c71e10c1af84354fefe782fc0b87120016e6555 --- engine/src/flutter/libs/minikin/Measurement.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/Measurement.cpp b/engine/src/flutter/libs/minikin/Measurement.cpp index 21df5d8234c..98d2c01a397 100644 --- a/engine/src/flutter/libs/minikin/Measurement.cpp +++ b/engine/src/flutter/libs/minikin/Measurement.cpp @@ -41,7 +41,7 @@ float getRunAdvance(Layout& layout, const uint16_t* buf, size_t start, size_t co clusterWidth = charAdvance; } } - if (offset < start + count && layout.getCharAdvance(offset) == 0.0f) { + if (offset < start + count && layout.getCharAdvance(offset - start) == 0.0f) { // In the middle of a cluster, distribute width of cluster so that each grapheme cluster // gets an equal share. // TODO: get caret information out of font when that's available From 19c69aef98ca76bd56917818ec013f1f7510f54e Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 8 Jun 2015 13:41:44 -0700 Subject: [PATCH 083/364] Increase hyphenation penalty for short last line Tuning for hyphenation parameters. We discourage hyphenation on the last line, but offset this penalty by also applying a penalty for each line, which optimizes for minimizing the number of lines. Thus, when hyphenation can reduce the number of lines, it increases the chance they're used. There's probably more tuning and refinement that can be done, but testing suggests that the tunable parameters are appropriate. Bug: 20883322 Change-Id: Ida7eaf8aced109e426694f5a386924a842d29c4b --- .../src/flutter/include/minikin/LineBreaker.h | 9 +- .../src/flutter/libs/minikin/LineBreaker.cpp | 112 +++++++----------- 2 files changed, 45 insertions(+), 76 deletions(-) diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index 36314fb5114..e031fb3182c 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -200,9 +200,6 @@ class LineBreaker { float currentLineWidth() const; - // compute shrink/stretch penalty for line - float computeScore(float delta, bool atEnd); - void addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, float penalty, uint8_t hyph); @@ -213,10 +210,7 @@ class LineBreaker { void computeBreaksGreedy(); - void computeBreaksOptimal(); - - // special case when LineWidth is constant (layout is rectangle) - void computeBreaksOptimalRect(); + void computeBreaksOptimal(bool isRectangular); void finishBreaksOptimal(); @@ -241,6 +235,7 @@ class LineBreaker { ParaWidth mWidth = 0; std::vector mCandidates; + float mLinePenalty = 0.0f; // the following are state for greedy breaker (updated while adding style runs) size_t mLastBreak; diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index dbd6ea8206b..8275a6cc10e 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -37,6 +37,13 @@ const float SCORE_INFTY = std::numeric_limits::max(); const float SCORE_OVERFULL = 1e12f; const float SCORE_DESPERATE = 1e10f; +// Multiplier for hyphen penalty on last line. +const float LAST_LINE_PENALTY_MULTIPLIER = 4.0f; +// Penalty assigned to each line break (to try to minimize number of lines) +// TODO: when we implement full justification (so spaces can shrink and stretch), this is +// probably not the most appropriate method. +const float LINE_PENALTY_MULTIPLIER = 2.0f; + // Very long words trigger O(n^2) behavior in hyphenation, so we disable hyphenation for // unreasonably long words. This is somewhat of a heuristic because extremely long words // are possible in some languages. This does mean that very long real words can get @@ -122,6 +129,8 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa if (mHyphenationFrequency == kHyphenationFrequency_Normal) { hyphenPenalty *= 4.0; // TODO: Replace with a better value after some testing } + + mLinePenalty = std::max(mLinePenalty, hyphenPenalty * LINE_PENALTY_MULTIPLIER); } size_t current = (size_t)mBreakIterator->current(); @@ -235,17 +244,6 @@ void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth post addCandidate(cand); } -// TODO: for justified text, refine with shrink/stretch -float LineBreaker::computeScore(float delta, bool atEnd) { - if (delta < 0) { - return SCORE_OVERFULL; - } else if (atEnd && mStrategy != kBreakStrategy_Balanced) { - return 0.0; - } else { - return delta * delta; - } -} - // TODO performance: could avoid populating mCandidates if greedy only void LineBreaker::addCandidate(Candidate cand) { size_t candIndex = mCandidates.size(); @@ -320,55 +318,7 @@ void LineBreaker::finishBreaksOptimal() { std::reverse(mFlags.begin(), mFlags.end()); } -void LineBreaker::computeBreaksOptimal() { - size_t active = 0; - size_t nCand = mCandidates.size(); - for (size_t i = 1; i < nCand; i++) { - bool atEnd = i == nCand - 1; - float best = SCORE_INFTY; - size_t bestPrev = 0; - - size_t lineNumberLast = mCandidates[active].lineNumber; - float width = mLineWidths.getLineWidth(lineNumberLast); - ParaWidth leftEdge = mCandidates[i].postBreak - width; - float bestHope = 0; - - for (size_t j = active; j < i; j++) { - size_t lineNumber = mCandidates[j].lineNumber; - if (lineNumber != lineNumberLast) { - float widthNew = mLineWidths.getLineWidth(lineNumber); - if (widthNew != width) { - leftEdge = mCandidates[i].postBreak - width; - bestHope = 0; - width = widthNew; - } - lineNumberLast = lineNumber; - } - float jScore = mCandidates[j].score; - if (jScore + bestHope >= best) continue; - float delta = mCandidates[j].preBreak - leftEdge; - - float widthScore = computeScore(delta, atEnd); - if (delta < 0) { - active = j + 1; - } else { - bestHope = widthScore; - } - - float score = jScore + widthScore; - if (score <= best) { - best = score; - bestPrev = j; - } - } - mCandidates[i].score = best + mCandidates[i].penalty; - mCandidates[i].prev = bestPrev; - mCandidates[i].lineNumber = mCandidates[bestPrev].lineNumber + 1; - } - finishBreaksOptimal(); -} - -void LineBreaker::computeBreaksOptimalRect() { +void LineBreaker::computeBreaksOptimal(bool isRectangle) { size_t active = 0; size_t nCand = mCandidates.size(); float width = mLineWidths.getLineWidth(0); @@ -376,19 +326,43 @@ void LineBreaker::computeBreaksOptimalRect() { bool atEnd = i == nCand - 1; float best = SCORE_INFTY; size_t bestPrev = 0; + size_t lineNumberLast = 0; - // Width-based component of score increases as line gets shorter, so score will always be - // at least this. + if (!isRectangle) { + size_t lineNumberLast = mCandidates[active].lineNumber; + width = mLineWidths.getLineWidth(lineNumberLast); + } + ParaWidth leftEdge = mCandidates[i].postBreak - width; float bestHope = 0; - ParaWidth leftEdge = mCandidates[i].postBreak - width; for (size_t j = active; j < i; j++) { - // TODO performance: can break if bestHope >= best; worth it? + if (!isRectangle) { + size_t lineNumber = mCandidates[j].lineNumber; + if (lineNumber != lineNumberLast) { + float widthNew = mLineWidths.getLineWidth(lineNumber); + if (widthNew != width) { + leftEdge = mCandidates[i].postBreak - width; + bestHope = 0; + width = widthNew; + } + lineNumberLast = lineNumber; + } + } float jScore = mCandidates[j].score; if (jScore + bestHope >= best) continue; float delta = mCandidates[j].preBreak - leftEdge; - float widthScore = computeScore(delta, atEnd); + // compute width score for line + float widthScore = 0.0f; + if (delta < 0) { + widthScore = SCORE_OVERFULL; + } else if (atEnd && mStrategy != kBreakStrategy_Balanced) { + // increase penalty for hyphen on last line + widthScore = LAST_LINE_PENALTY_MULTIPLIER * mCandidates[j].penalty; + } else { + widthScore = delta * delta; + } + if (delta < 0) { active = j + 1; } else { @@ -401,8 +375,9 @@ void LineBreaker::computeBreaksOptimalRect() { bestPrev = j; } } - mCandidates[i].score = best + mCandidates[i].penalty; + mCandidates[i].score = best + mCandidates[i].penalty + mLinePenalty; mCandidates[i].prev = bestPrev; + mCandidates[i].lineNumber = mCandidates[bestPrev].lineNumber + 1; } finishBreaksOptimal(); } @@ -410,10 +385,8 @@ void LineBreaker::computeBreaksOptimalRect() { size_t LineBreaker::computeBreaks() { if (mStrategy == kBreakStrategy_Greedy) { computeBreaksGreedy(); - } else if (mLineWidths.isConstant()) { - computeBreaksOptimalRect(); } else { - computeBreaksOptimal(); + computeBreaksOptimal(mLineWidths.isConstant()); } return mBreaks.size(); } @@ -438,6 +411,7 @@ void LineBreaker::finish() { } mStrategy = kBreakStrategy_Greedy; mHyphenationFrequency = kHyphenationFrequency_Normal; + mLinePenalty = 0.0f; } } // namespace android From 8081d06133ad04200da70d8015a0027860bef706 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Wed, 10 Jun 2015 17:45:46 +0900 Subject: [PATCH 084/364] Fix: getOffsetForAdvance can return worng offset. searchStart was passed to getRunAdvance, but it can be different from the start that has been used to initialize Layout object. As a result, wrong index could be used in getRunAdvance. Bug: 21744454 Change-Id: Ibe83cc50ed6f0da2a1532318bc224502be350699 --- .../src/flutter/libs/minikin/Measurement.cpp | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Measurement.cpp b/engine/src/flutter/libs/minikin/Measurement.cpp index 98d2c01a397..0b68ac5f640 100644 --- a/engine/src/flutter/libs/minikin/Measurement.cpp +++ b/engine/src/flutter/libs/minikin/Measurement.cpp @@ -28,26 +28,26 @@ namespace android { // These could be considered helper methods of layout, but need only be loosely coupled, so // are separate. -float getRunAdvance(Layout& layout, const uint16_t* buf, size_t start, size_t count, - size_t offset) { +static float getRunAdvance(Layout& layout, const uint16_t* buf, size_t layoutStart, size_t start, + size_t count, size_t offset) { float advance = 0.0f; size_t lastCluster = start; float clusterWidth = 0.0f; for (size_t i = start; i < offset; i++) { - float charAdvance = layout.getCharAdvance(i - start); + float charAdvance = layout.getCharAdvance(i - layoutStart); if (charAdvance != 0.0f) { advance += charAdvance; lastCluster = i; clusterWidth = charAdvance; } } - if (offset < start + count && layout.getCharAdvance(offset - start) == 0.0f) { + if (offset < start + count && layout.getCharAdvance(offset - layoutStart) == 0.0f) { // In the middle of a cluster, distribute width of cluster so that each grapheme cluster // gets an equal share. // TODO: get caret information out of font when that's available size_t nextCluster; for (nextCluster = offset + 1; nextCluster < start + count; nextCluster++) { - if (layout.getCharAdvance(nextCluster - start) != 0.0f) break; + if (layout.getCharAdvance(nextCluster - layoutStart) != 0.0f) break; } int numGraphemeClusters = 0; int numGraphemeClustersAfter = 0; @@ -67,6 +67,11 @@ float getRunAdvance(Layout& layout, const uint16_t* buf, size_t start, size_t co return advance; } +float getRunAdvance(Layout& layout, const uint16_t* buf, size_t start, size_t count, + size_t offset) { + return getRunAdvance(layout, buf, start, start, count, offset); +} + /** * Essentially the inverse of getRunAdvance. Compute the value of offset for which the * measured caret comes closest to the provided advance param, and which is on a grapheme @@ -98,9 +103,10 @@ size_t getOffsetForAdvance(Layout& layout, const uint16_t* buf, size_t start, si float bestDist = FLT_MAX; for (size_t i = searchStart; i <= start + count; i++) { if (GraphemeBreak::isGraphemeBreak(buf, start, count, i)) { - // "getRunAdvance(layout, buf, start, count, bufSize, i) - advance" but more efficient - float delta = getRunAdvance(layout, buf, searchStart, count, i) + xSearchStart - - advance; + // "getRunAdvance(layout, buf, start, count, i) - advance" but more efficient + float delta = getRunAdvance(layout, buf, start, searchStart, count - searchStart, i) + + + xSearchStart - advance; if (std::abs(delta) < bestDist) { bestDist = std::abs(delta); best = i; From 48e52a29af97d17be2248e51b9d6d8602c9d6ce3 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Fri, 12 Jun 2015 10:29:59 -0700 Subject: [PATCH 085/364] Use ASCII HYPHEN-MINUS when there's no HYPHEN in the font. Previously, we just assumed the font in use had a U+2010 HYPHEN character, resulting in a tofu (or an empty space) being shown when U+2010 was not supported in the font used to render the hyphenated word. Now we try to fallback to U+002D HYPHEN-MINUS, which has a very good chance of being available in at least any Latin font. We still show a tofu when neither character is supported, to intentionally alert that something is missing. Bug: 20497913 Bug: 21088552 Bug: 21570828 Change-Id: Iff69bbc38836c03495e9124502b5207c39270da2 --- engine/src/flutter/libs/minikin/Layout.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 88baeac6f55..17ce596bd64 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -729,7 +729,17 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t // TODO: check whether this is really the desired semantics. It could have the // effect of assigning the hyphen width to a nonspacing mark unsigned int lastCluster = srunend - 1; - hb_buffer_add(buffer, 0x2010, lastCluster); + + hb_codepoint_t hyphenChar = 0x2010; // HYPHEN + hb_codepoint_t glyph; + // Fallback to ASCII HYPHEN-MINUS if the font didn't have a glyph for HYPHEN. Note + // that we intentionally don't do anything special if the font doesn't have a + // HYPHEN-MINUS either, so a tofu could be shown, hinting towards something + // missing. + if (!hb_font_get_glyph(hbFont, hyphenChar, 0, &glyph)) { + hyphenChar = 0x002D; // HYPHEN-MINUS + } + hb_buffer_add(buffer, hyphenChar, lastCluster); } hb_shape(hbFont, buffer, features.empty() ? NULL : &features[0], features.size()); unsigned int numGlyphs; From e5cb2f787c4a388a723b8fb62980e2238c85faaa Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 24 Jun 2015 12:59:18 -0700 Subject: [PATCH 086/364] Separate additional penalty for last line with hyphen A recent change added a penalty for a hyphen at the last line break, which is visually undesirable. However, the penalty was assessed to "widthScore", which broke the assumption (used for another optimization) that widthScore increases monotonically. This patch separates the penalty into a different parameter, restoring the validity of the monotonicity assumption. Bug: 22066119 Change-Id: I6a47a350ef3ceee2f00ee430d6954d0c307227f0 --- engine/src/flutter/libs/minikin/LineBreaker.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 8275a6cc10e..162d14b8af7 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -353,12 +353,17 @@ void LineBreaker::computeBreaksOptimal(bool isRectangle) { float delta = mCandidates[j].preBreak - leftEdge; // compute width score for line + + // Note: the "bestHope" optimization makes the assumption that, when delta is + // non-negative, widthScore will increase monotonically as successive candidate + // breaks are considered. float widthScore = 0.0f; + float additionalPenalty = 0.0f; if (delta < 0) { widthScore = SCORE_OVERFULL; } else if (atEnd && mStrategy != kBreakStrategy_Balanced) { // increase penalty for hyphen on last line - widthScore = LAST_LINE_PENALTY_MULTIPLIER * mCandidates[j].penalty; + additionalPenalty = LAST_LINE_PENALTY_MULTIPLIER * mCandidates[j].penalty; } else { widthScore = delta * delta; } @@ -369,7 +374,7 @@ void LineBreaker::computeBreaksOptimal(bool isRectangle) { bestHope = widthScore; } - float score = jScore + widthScore; + float score = jScore + widthScore + additionalPenalty; if (score <= best) { best = score; bestPrev = j; @@ -378,6 +383,9 @@ void LineBreaker::computeBreaksOptimal(bool isRectangle) { mCandidates[i].score = best + mCandidates[i].penalty + mLinePenalty; mCandidates[i].prev = bestPrev; mCandidates[i].lineNumber = mCandidates[bestPrev].lineNumber + 1; +#ifdef VERBOSE_DEBUG + ALOGD("break %d: score=%g, prev=%d", i, mCandidates[i].score, mCandidates[i].prev); +#endif } finishBreaksOptimal(); } From 5704594913e26de179ca914f55aeb149c0984388 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 26 Jun 2015 11:15:17 -0700 Subject: [PATCH 087/364] Disable letterspacing for connected scripts The appearance of letterspacing with scripts with cursive connections is poor, so we simply disable letterspacing for those scripts. There may be some cases where some form of letterspacing is desirable, but this gives the highest likelihood that the final result will be good without requiring additional work from clients. Bug: 21935803 Change-Id: Ie25266249ac3a2605aa89ef5132e8edbe3a06d35 --- engine/src/flutter/libs/minikin/Layout.cpp | 47 +++++++++++++++++----- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 17ce596bd64..0c8c4ca79e0 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -514,6 +514,29 @@ static size_t getNextWordBreak(const uint16_t* chars, size_t offset, size_t len) return len; } +/** + * Disable certain scripts (mostly those with cursive connection) from having letterspacing + * applied. See https://github.com/behdad/harfbuzz/issues/64 for more details. + */ +static bool isScriptOkForLetterspacing(hb_script_t script) { + return !( + script == HB_SCRIPT_ARABIC || + script == HB_SCRIPT_NKO || + script == HB_SCRIPT_PSALTER_PAHLAVI || + script == HB_SCRIPT_MANDAIC || + script == HB_SCRIPT_MONGOLIAN || + script == HB_SCRIPT_PHAGS_PA || + script == HB_SCRIPT_DEVANAGARI || + script == HB_SCRIPT_BENGALI || + script == HB_SCRIPT_GURMUKHI || + script == HB_SCRIPT_MODI || + script == HB_SCRIPT_SHARADA || + script == HB_SCRIPT_SYLOTI_NAGRI || + script == HB_SCRIPT_TIRHUTA || + script == HB_SCRIPT_OGHAM + ); +} + void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint) { AutoMutex _l(gMinikinLock); @@ -678,15 +701,6 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t double size = ctx->paint.size; double scaleX = ctx->paint.scaleX; - double letterSpace = ctx->paint.letterSpacing * size * scaleX; - double letterSpaceHalfLeft; - if ((ctx->paint.paintFlags & LinearTextFlag) == 0) { - letterSpace = round(letterSpace); - letterSpaceHalfLeft = floor(letterSpace * 0.5); - } else { - letterSpaceHalfLeft = letterSpace * 0.5; - } - double letterSpaceHalfRight = letterSpace - letterSpaceHalfLeft; float x = mAdvance; float y = 0; @@ -716,6 +730,21 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t srunend = srunstart; hb_script_t script = getScriptRun(buf + start, run.end, &srunend); + double letterSpace = 0.0; + double letterSpaceHalfLeft = 0.0; + double letterSpaceHalfRight = 0.0; + + if (ctx->paint.letterSpacing != 0.0 && isScriptOkForLetterspacing(script)) { + letterSpace = ctx->paint.letterSpacing * size * scaleX; + if ((ctx->paint.paintFlags & LinearTextFlag) == 0) { + letterSpace = round(letterSpace); + letterSpaceHalfLeft = floor(letterSpace * 0.5); + } else { + letterSpaceHalfLeft = letterSpace * 0.5; + } + letterSpaceHalfRight = letterSpace - letterSpaceHalfLeft; + } + hb_buffer_clear_contents(buffer); hb_buffer_set_script(buffer, script); hb_buffer_set_direction(buffer, isRtl? HB_DIRECTION_RTL : HB_DIRECTION_LTR); From 8726aff8cf57aeccacff60cf0e5fb4a7330994c4 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 29 Jun 2015 14:21:10 -0700 Subject: [PATCH 088/364] Fix logspam and incorrect cluster offset An incorrect cluster offset calculation was causing a lot of log messages to appear. Separately, a confusion between #if and #ifdef was causing unintended logging of line breaks. This patch fixes both. Bug: 22178333 Change-Id: I2b3673ed66c784f5082fd127a8dc10bd3df6ed79 --- engine/src/flutter/libs/minikin/Layout.cpp | 2 +- engine/src/flutter/libs/minikin/LineBreaker.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 0c8c4ca79e0..bac5fc77439 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -757,7 +757,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t if (ctx->paint.hyphenEdit.hasHyphen() && srunend > srunstart) { // TODO: check whether this is really the desired semantics. It could have the // effect of assigning the hyphen width to a nonspacing mark - unsigned int lastCluster = srunend - 1; + unsigned int lastCluster = start + srunend - 1; hb_codepoint_t hyphenChar = 0x2010; // HYPHEN hb_codepoint_t glyph; diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 162d14b8af7..baf2dfa4125 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -383,7 +383,7 @@ void LineBreaker::computeBreaksOptimal(bool isRectangle) { mCandidates[i].score = best + mCandidates[i].penalty + mLinePenalty; mCandidates[i].prev = bestPrev; mCandidates[i].lineNumber = mCandidates[bestPrev].lineNumber + 1; -#ifdef VERBOSE_DEBUG +#if VERBOSE_DEBUG ALOGD("break %d: score=%g, prev=%d", i, mCandidates[i].score, mCandidates[i].prev); #endif } From 1b3bfb262437625ca4e6efb93b7b90543d6b5ec3 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 30 Jun 2015 10:15:43 -0700 Subject: [PATCH 089/364] Allow clusters to start with zero-width characters The logic in getRunAdvance() assumed that any zero-width character was part of the preceding cluster, which is valid most of the time. However, characters such as ZWNBSP (U+FEFF) renders as a zero width glyph and is also a grapheme cluster boundary. This patch adds a clause to handle that case. Bug: 22121742 Change-Id: Iad79a7d988bded1ef05f0fd7905d20669ea22051 --- engine/src/flutter/libs/minikin/Measurement.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/Measurement.cpp b/engine/src/flutter/libs/minikin/Measurement.cpp index 0b68ac5f640..a7bc64bea16 100644 --- a/engine/src/flutter/libs/minikin/Measurement.cpp +++ b/engine/src/flutter/libs/minikin/Measurement.cpp @@ -41,7 +41,8 @@ static float getRunAdvance(Layout& layout, const uint16_t* buf, size_t layoutSta clusterWidth = charAdvance; } } - if (offset < start + count && layout.getCharAdvance(offset - layoutStart) == 0.0f) { + if (offset < start + count && layout.getCharAdvance(offset - layoutStart) == 0.0f && + !GraphemeBreak::isGraphemeBreak(buf, start, count, offset)) { // In the middle of a cluster, distribute width of cluster so that each grapheme cluster // gets an equal share. // TODO: get caret information out of font when that's available From 2685aef48e970518da4f3514ef1db4f74fef656e Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 9 Jul 2015 15:58:16 -0700 Subject: [PATCH 090/364] Add HyphenEdit to layout cache We bypass the word layout cache for "complex" cases, which includes things like OpenType features. We were counting a hyphen edit as such a case, but the problem is that we measure a _lot_ of these when doing layout with hyphenation. This patch adds plumbing for hyphen edits to the layout cache, so that word fragments with hyphens can be cached as well. Bug: 22378829 Change-Id: Idba4df4faa14f48a5faccc8a7a7955a36c19ef27 --- engine/src/flutter/include/minikin/MinikinFont.h | 4 ++-- engine/src/flutter/libs/minikin/Layout.cpp | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index ee885f497c4..7f65cd7b0aa 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -35,6 +35,7 @@ public: HyphenEdit() : hyphen(0) { } HyphenEdit(uint32_t hyphenInt) : hyphen(hyphenInt) { } bool hasHyphen() const { return hyphen != 0; } + bool operator==(const HyphenEdit &other) const { return hyphen == other.hyphen; } private: uint32_t hyphen; }; @@ -48,8 +49,7 @@ struct MinikinPaint { fakery(), fontFeatureSettings() { } bool skipCache() const { - // TODO: add hyphen to cache - return !fontFeatureSettings.empty() || hyphenEdit.hasHyphen(); + return !fontFeatureSettings.empty(); } MinikinFont *font; diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index bac5fc77439..be29e3ca2a0 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -110,7 +110,7 @@ public: mStart(start), mCount(count), mId(collection->getId()), mStyle(style), mSize(paint.size), mScaleX(paint.scaleX), mSkewX(paint.skewX), mLetterSpacing(paint.letterSpacing), - mPaintFlags(paint.paintFlags), mIsRtl(dir) { + mPaintFlags(paint.paintFlags), mHyphenEdit(paint.hyphenEdit), mIsRtl(dir) { } bool operator==(const LayoutCacheKey &other) const; hash_t hash() const; @@ -144,6 +144,7 @@ private: float mSkewX; float mLetterSpacing; int32_t mPaintFlags; + HyphenEdit mHyphenEdit; bool mIsRtl; // Note: any fields added to MinikinPaint must also be reflected here. // TODO: language matching (possibly integrate into style) @@ -236,6 +237,7 @@ bool LayoutCacheKey::operator==(const LayoutCacheKey& other) const { && mSkewX == other.mSkewX && mLetterSpacing == other.mLetterSpacing && mPaintFlags == other.mPaintFlags + && mHyphenEdit == other.mHyphenEdit && mIsRtl == other.mIsRtl && mNchars == other.mNchars && !memcmp(mChars, other.mChars, mNchars * sizeof(uint16_t)); @@ -251,6 +253,7 @@ hash_t LayoutCacheKey::hash() const { hash = JenkinsHashMix(hash, hash_type(mSkewX)); hash = JenkinsHashMix(hash, hash_type(mLetterSpacing)); hash = JenkinsHashMix(hash, hash_type(mPaintFlags)); + hash = JenkinsHashMix(hash, hash_type(mHyphenEdit.hasHyphen())); hash = JenkinsHashMix(hash, hash_type(mIsRtl)); hash = JenkinsHashMixShorts(hash, mChars, mNchars); return JenkinsHashWhiten(hash); From 9793a7eda48113bbcd7fa802c7c59bb997d0cf2a Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Tue, 14 Jul 2015 13:04:49 -0700 Subject: [PATCH 091/364] Avoid re-hyphenating already-hyphenated phrases. Previously, automatic hyphenation blindly took almost every line breaking opportunity as a word break, so words like "low-budget" were treated as two separate words, "low-", and "budget", each automatically hyphenated. This patch makes sure the subwords in already-hyphenated phrases are not passed to the automatic hyphenator, while keeping the possibility of a potential line break where a hyphen already exists. Bug: 22484266 Bug: 22287425 Change-Id: Ie46dbdd70e993d64a9b9cf44b4ae93b21459dbc2 --- engine/src/flutter/libs/minikin/LineBreaker.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index baf2dfa4125..bf8be269b04 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -29,7 +29,9 @@ using std::vector; namespace android { const int CHAR_TAB = 0x0009; +const uint16_t CHAR_HYPHEN_MINUS = 0x002D; const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; +const uint16_t CHAR_HYPHEN = 0x2010; // Large scores in a hierarchy; we prefer desperate breaks to an overfull line. All these // constants are larger than any reasonable actual width score. @@ -138,6 +140,7 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa size_t lastBreak = start; ParaWidth lastBreakWidth = mWidth; ParaWidth postBreak = mWidth; + bool temporarilySkipHyphenation = false; for (size_t i = start; i < end; i++) { uint16_t c = mTextBuf[i]; if (c == CHAR_TAB) { @@ -158,8 +161,12 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa // Override ICU's treatment of soft hyphen as a break opportunity, because we want it // to be a hyphen break, with penalty and drawing behavior. if (c != CHAR_SOFT_HYPHEN) { + // TODO: Add a new type of HyphenEdit for breaks whose hyphen already exists, so + // we can pass the whole word down to Hyphenator like the soft hyphen case. + bool wordEndsInHyphen = (c == CHAR_HYPHEN_MINUS || c == CHAR_HYPHEN); if (paint != nullptr && mHyphenator != nullptr && mHyphenationFrequency != kHyphenationFrequency_None && + !wordEndsInHyphen && !temporarilySkipHyphenation && wordEnd > lastBreak && wordEnd - lastBreak <= LONGEST_HYPHENATED_WORD) { mHyphenator->hyphenate(&mHyphBuf, &mTextBuf[lastBreak], wordEnd - lastBreak); #if VERBOSE_DEBUG @@ -188,6 +195,8 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa } } } + // Skip hyphenating the next word if and only if the present word ends in a hyphen + temporarilySkipHyphenation = wordEndsInHyphen; // Skip break for zero-width characters. if (current == mTextBuf.size() || mCharWidths[current] > 0) { From de1bd61f00c6f2556ef95befafd2470a8bff2aa1 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 15 Jul 2015 10:59:59 -0700 Subject: [PATCH 092/364] Add missing hyphen-like characters. This adds various hyphen-like characters missed in the previous patch, that should disallow automatic hyphenation of words containing them. Bug: 22484266 Change-Id: Ie972cb50384dbe0aa1ab5ec50286b75f9877953a --- .../src/flutter/libs/minikin/LineBreaker.cpp | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index bf8be269b04..72e5c183c6a 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -29,9 +29,7 @@ using std::vector; namespace android { const int CHAR_TAB = 0x0009; -const uint16_t CHAR_HYPHEN_MINUS = 0x002D; const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; -const uint16_t CHAR_HYPHEN = 0x2010; // Large scores in a hierarchy; we prefer desperate breaks to an overfull line. All these // constants are larger than any reasonable actual width score. @@ -107,6 +105,24 @@ static bool isLineEndSpace(uint16_t c) { c == 0x205F || c == 0x3000; } +// This function determines whether a character is like U+2010 HYPHEN in +// line breaking and usage: a character immediately after which line breaks +// are allowed, but words containing it should not be automatically +// hyphenated. This is a curated set, created by manually inspecting all +// the characters that have the Unicode line breaking property of BA or HY +// and seeing which ones are hyphens. +static bool isLineBreakingHyphen(uint16_t c) { + return (c == 0x002D || // HYPHEN-MINUS + c == 0x058A || // ARMENIAN HYPHEN + c == 0x05BE || // HEBREW PUNCTUATION MAQAF + c == 0x1400 || // CANADIAN SYLLABICS HYPHEN + c == 0x2010 || // HYPHEN + c == 0x2013 || // EN DASH + c == 0x2027 || // HYPHENATION POINT + c == 0x2E17 || // DOUBLE OBLIQUE HYPHEN + c == 0x2E40); // DOUBLE HYPHEN +} + // Ordinarily, this method measures the text in the range given. However, when paint // is nullptr, it assumes the widths have already been calculated and stored in the // width buffer. @@ -163,7 +179,7 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa if (c != CHAR_SOFT_HYPHEN) { // TODO: Add a new type of HyphenEdit for breaks whose hyphen already exists, so // we can pass the whole word down to Hyphenator like the soft hyphen case. - bool wordEndsInHyphen = (c == CHAR_HYPHEN_MINUS || c == CHAR_HYPHEN); + bool wordEndsInHyphen = isLineBreakingHyphen(c); if (paint != nullptr && mHyphenator != nullptr && mHyphenationFrequency != kHyphenationFrequency_None && !wordEndsInHyphen && !temporarilySkipHyphenation && From 7f0d04161b1b8c4d7995c7a3d9dd3c3a44d3c56e Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 15 Jul 2015 12:19:19 -0700 Subject: [PATCH 093/364] Use ICU to lowercase words to hyphenate. Previously, the standard C tolower() function was used, which didn't support any characters beyond the basic ASCII letters. Bug: 22506121 Change-Id: Ibb81121caa29be44fbb59aa98891e9faafc57592 --- engine/src/flutter/libs/minikin/Hyphenator.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Hyphenator.cpp b/engine/src/flutter/libs/minikin/Hyphenator.cpp index c50b3861af4..3eb151b9e02 100644 --- a/engine/src/flutter/libs/minikin/Hyphenator.cpp +++ b/engine/src/flutter/libs/minikin/Hyphenator.cpp @@ -16,9 +16,9 @@ #include #include -#include #include #include +#include // HACK: for reading pattern file #include @@ -95,8 +95,19 @@ void Hyphenator::hyphenate(vector* result, const uint16_t* word, size_t hyphenateSoft(result, word, len); return; } - // TODO: use locale-sensitive case folding from ICU. - c = tolower(c); + // TODO: This uses ICU's simple character to character lowercasing, which ignores + // the locale, and ignores cases when lowercasing a character results in more than + // one character. It should be fixed to consider the locale (in order for it to work + // correctly for Turkish and Azerbaijani), as well as support one-to-many, and + // many-to-many case conversions (including non-BMP cases). + if (c < 0x00C0) { // U+00C0 is the lowest uppercase non-ASCII character + // Convert uppercase ASCII to lowercase ASCII, but keep other characters as-is + if (0x0041 <= c && c <= 0x005A) { + c += 0x0020; + } + } else { + c = u_tolower(c); + } } auto search = node->succ.find(c); if (search != node->succ.end()) { From 8a83b1a4ef2876fc23ceb0499019d7022f72ee5d Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 20 Jul 2015 15:37:54 -0700 Subject: [PATCH 094/364] Consistently apply break opportunities in text spans It's essential not to apply a break opportunity within a replacement span, otherwise things can happen such as displaying the span twice. The old code tested this case based on zero-width characters. However, this test was both imprecise, and also in some cases read uninitialized values from the mCharWidths array, which in turn led to inconsistent line breaking of the same text. This patch applies all line break opportunities (as identified by ICU) within text (as opposed to replacement spans), and also applies break opportunities at the beginning and end of replacement spans, but avoids breaks within a replacement span. Bug: 20138621 Change-Id: I36baeb44d6808356649e1bb69ca57f093fc8c723 --- engine/src/flutter/libs/minikin/LineBreaker.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 72e5c183c6a..a832ca20e26 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -214,8 +214,8 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa // Skip hyphenating the next word if and only if the present word ends in a hyphen temporarilySkipHyphenation = wordEndsInHyphen; - // Skip break for zero-width characters. - if (current == mTextBuf.size() || mCharWidths[current] > 0) { + // Skip break for zero-width characters inside replacement span + if (paint != nullptr || current == end || mCharWidths[current] > 0) { addWordBreak(current, mWidth, postBreak, 0.0, 0); } lastBreak = current; From 4d86b85e69d25382a06b3f19f4a84154ec85361d Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 21 Jul 2015 05:31:11 +0000 Subject: [PATCH 095/364] Revert "Allow clusters to start with zero-width characters" This reverts commit 1b3bfb262437625ca4e6efb93b7b90543d6b5ec3. Bug: 22589743 Bug: 22121742 Change-Id: I7b482ffb8a0ee174ddc804aa890de45bdbd758e3 --- engine/src/flutter/libs/minikin/Measurement.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Measurement.cpp b/engine/src/flutter/libs/minikin/Measurement.cpp index a7bc64bea16..0b68ac5f640 100644 --- a/engine/src/flutter/libs/minikin/Measurement.cpp +++ b/engine/src/flutter/libs/minikin/Measurement.cpp @@ -41,8 +41,7 @@ static float getRunAdvance(Layout& layout, const uint16_t* buf, size_t layoutSta clusterWidth = charAdvance; } } - if (offset < start + count && layout.getCharAdvance(offset - layoutStart) == 0.0f && - !GraphemeBreak::isGraphemeBreak(buf, start, count, offset)) { + if (offset < start + count && layout.getCharAdvance(offset - layoutStart) == 0.0f) { // In the middle of a cluster, distribute width of cluster so that each grapheme cluster // gets an equal share. // TODO: get caret information out of font when that's available From 2be7eeef688e8e5546aae9540683e37fa994927f Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 29 Jul 2015 13:03:50 -0700 Subject: [PATCH 096/364] Improve fallback where explicit variant is not given In computing scores for which fallback font to choose, a match of a variant given explicitly in the xml config file scores higher than a family with no explicit variant. One consequence is that U+2010 HYPHEN is chosen from the Naskh Arabic font in the fallback case. This patch scores families with no variants as a match (effectively the same as if the xml file specified both variants). Thus, it will choose the first matching font (Roboto), which is a better choice. This patch also revises the list of "sticky" characters to include various hyphens, so Arabic (and potentially other scripts) text that includes hyphens can access the script-specific variants matched to the underlying text. Bug: 22824219 Change-Id: I6ec1043037f89cad50ca99ac24c473395546bcdf --- engine/src/flutter/libs/minikin/FontCollection.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index e3911c5bd3f..b4bfe313ba4 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -122,7 +122,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, return family; } int score = lang.match(family->lang()) * 2; - if (variant != 0 && variant == family->variant()) { + if (family->variant() == 0 || family->variant() == variant) { score++; } if (score > bestScore) { @@ -152,10 +152,13 @@ const uint32_t NBSP = 0xa0; const uint32_t ZWJ = 0x200c; const uint32_t ZWNJ = 0x200d; const uint32_t KEYCAP = 0x20e3; +const uint32_t HYPHEN = 0x2010; +const uint32_t NB_HYPHEN = 0x2011; // Characters where we want to continue using existing font run instead of // recomputing the best match in the fallback list. -static const uint32_t stickyWhitelist[] = { '!', ',', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ, KEYCAP }; +static const uint32_t stickyWhitelist[] = { '!', ',', '-', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ, + KEYCAP, HYPHEN, NB_HYPHEN }; static bool isStickyWhitelisted(uint32_t c) { for (size_t i = 0; i < sizeof(stickyWhitelist) / sizeof(stickyWhitelist[0]); i++) { From 36a78d6d47a0b97e94ab358f2a38aaf6ac0e3945 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Thu, 6 Aug 2015 13:33:14 -0700 Subject: [PATCH 097/364] Gold plate grapheme cluster breaks. This tailors Unicode's Grapheme_Cluster_Break property to better classify characters currently with the Control property value. Also adds support for rule GB9b of UAX #29, needed since there are now characters we are tailoring to be Prepend. The rule was previously ommited in our implementation because there was no characters in the Prepend class. Bug: 15653110 Change-Id: If10da88df0980f7d676c8c0b950eda5fb8dbe741 --- .../flutter/libs/minikin/GraphemeBreak.cpp | 78 +++++++++++++++---- 1 file changed, 62 insertions(+), 16 deletions(-) diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index f8f386c0de9..21da180b105 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -22,6 +22,48 @@ namespace android { +int32_t tailoredGraphemeClusterBreak(uint32_t c) { + // Characters defined as Control that we want to treat them as Extend. + // These are curated manually. + if (c == 0x00AD // SHY + || c == 0x061C // ALM + || c == 0x180E // MONGOLIAN VOWEL SEPARATOR + || c == 0x200B // ZWSP + || c == 0x200E // LRM + || c == 0x200F // RLM + || (0x202A <= c && c <= 0x202E) // LRE, RLE, PDF, LRO, RLO + || ((c | 0xF) == 0x206F) // WJ, invisible math operators, LRI, RLI, FSI, PDI, + // and the deprecated invisible format controls + || c == 0xFEFF // BOM + || ((c | 0x7F) == 0xE007F)) // recently undeprecated tag characters in Plane 14 + return U_GCB_EXTEND; + // UTC-approved characters for the Prepend class, per + // http://www.unicode.org/L2/L2015/15183r-graph-cluster-brk.txt + // These should be removed when our copy of ICU gets updated to Unicode 9.0 (~2016 or 2017). + else if ((0x0600 <= c && c <= 0x0605) // Arabic subtending marks + || c == 0x06DD // ARABIC SUBTENDING MARK + || c == 0x070F // SYRIAC ABBREVIATION MARK + || c == 0x0D4E // MALAYALAM LETTER DOT REPH + || c == 0x110BD // KAITHI NUMBER SIGN + || c == 0x111C2 // SHARADA SIGN JIHVAMULIYA + || c == 0x111C3) // SHARADA SIGN UPADHMANIYA + return U_GCB_PREPEND; + // THAI CHARACTER SARA AM is treated as a normal letter by most other implementations: they + // allow a grapheme break before it. + else if (c == 0x0E33) + return U_GCB_OTHER; + else + return u_getIntPropertyValue(c, UCHAR_GRAPHEME_CLUSTER_BREAK); +} + +// Returns true for all characters whose IndicSyllabicCategory is Pure_Killer. +// From http://www.unicode.org/Public/8.0.0/ucd/IndicSyllabicCategory.txt +bool isPureKiller(uint32_t c) { + return (c == 0x0E3A || c == 0x0E4E || c == 0x0F84 || c == 0x103A || c == 0x1714 || c == 0x1734 + || c == 0x17D1 || c == 0x1BAA || c == 0x1BF2 || c == 0x1BF3 || c == 0xA806 + || c == 0xA953 || c == 0xABED || c == 0x11134 || c == 0x112EA || c == 0x1172B); +} + bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t count, size_t offset) { // This implementation closely follows Unicode Standard Annex #29 on @@ -42,8 +84,8 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co size_t offset_back = offset; U16_PREV(buf, start, offset_back, c1); U16_NEXT(buf, offset, start + count, c2); - int32_t p1 = u_getIntPropertyValue(c1, UCHAR_GRAPHEME_CLUSTER_BREAK); - int32_t p2 = u_getIntPropertyValue(c2, UCHAR_GRAPHEME_CLUSTER_BREAK); + int32_t p1 = tailoredGraphemeClusterBreak(c1); + int32_t p2 = tailoredGraphemeClusterBreak(c2); // Rule GB3, CR x LF if (p1 == U_GCB_CR && p2 == U_GCB_LF) { return false; @@ -54,13 +96,6 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co } // Rule GB5, / (Control | CR | LF) if (p2 == U_GCB_CONTROL || p2 == U_GCB_CR || p2 == U_GCB_LF) { - // exclude zero-width control characters from breaking (tailoring of UAX #29) - if (c2 == 0x00ad - || (c2 >= 0x200b && c2 <= 0x200f) - || (c2 >= 0x2028 && c2 <= 0x202e) - || (c2 >= 0x2060 && c2 <= 0x206f)) { - return false; - } return true; } // Rule GB6, L x ( L | V | LV | LVT ) @@ -76,20 +111,31 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co return false; } // Rule GB8a, Regional_Indicator x Regional_Indicator + // + // Known limitation: This is overly conservative, and returns no grapheme breaks between two + // flags, such as in the character sequence "U+1F1FA U+1F1F8 [potential break] U+1F1FA U+1F1F8". + // Also, it assumes that all combinations of Regional Indicators produce a flag, where they + // don't. + // + // There is no easy solution for doing this correctly, except for querying the font and doing + // some lookback. if (p1 == U_GCB_REGIONAL_INDICATOR && p2 == U_GCB_REGIONAL_INDICATOR) { return false; } - // Rule GB9, x Extend; Rule GB9a, x SpacingMark - if (p2 == U_GCB_EXTEND || p2 == U_GCB_SPACING_MARK) { - if (c2 == 0xe33) { - // most other implementations break THAI CHARACTER SARA AM - // (tailoring of UAX #29) - return true; - } + // Rule GB9, x Extend; Rule GB9a, x SpacingMark; Rule GB9b, Prepend x + if (p2 == U_GCB_EXTEND || p2 == U_GCB_SPACING_MARK || p1 == U_GCB_PREPEND) { return false; } // Cluster indic syllables together (tailoring of UAX #29) + // Known limitation: this is overly conservative, and assumes that the virama may form a + // conjunct with the following letter, which doesn't always happen. + // + // There is no easy solution to do this correctly. Even querying the font does not help (with + // the current font technoloies), since the font may be creating the conjunct using multiple + // glyphs, while the user may be perceiving that sequence of glyphs as one conjunct or one + // letter. if (u_getIntPropertyValue(c1, UCHAR_CANONICAL_COMBINING_CLASS) == 9 // virama + && !isPureKiller(c1) && u_getIntPropertyValue(c2, UCHAR_GENERAL_CATEGORY) == U_OTHER_LETTER) { return false; } From 92603d1527ba3c15d395e0c52c600684bd6099f6 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Fri, 7 Aug 2015 21:37:37 -0700 Subject: [PATCH 098/364] Support three-letter language codes in FontLanguage. Also handle the case of weird language code that we don't understand properly better, by treating them not equal to each other. Change-Id: Iaccb251fa38d700932f6eadac254d3d1fa09b3ea --- .../src/flutter/include/minikin/FontFamily.h | 13 +++-- .../src/flutter/libs/minikin/FontFamily.cpp | 57 ++++++++++++------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 7bdff6eb4ff..d21a20af718 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -40,7 +40,9 @@ public: // Parse from string FontLanguage(const char* buf, size_t size); - bool operator==(const FontLanguage other) const { return mBits == other.mBits; } + bool operator==(const FontLanguage other) const { + return mBits != kUnsupportedLanguage && mBits == other.mBits; + } operator bool() const { return mBits != 0; } std::string getString() const; @@ -53,10 +55,11 @@ private: uint32_t bits() const { return mBits; } - static const uint32_t kBaseLangMask = 0xffff; - static const uint32_t kScriptMask = (1 << 18) - (1 << 16); - static const uint32_t kHansFlag = 1 << 16; - static const uint32_t kHantFlag = 1 << 17; + static const uint32_t kUnsupportedLanguage = 0xFFFFFFFFu; + static const uint32_t kBaseLangMask = 0xFFFFFFu; + static const uint32_t kScriptMask = (1u << 26) - (1u << 24); + static const uint32_t kHansFlag = 1u << 24; + static const uint32_t kHantFlag = 1u << 25; uint32_t mBits; }; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index da7320bce5d..c70cf88023f 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -40,7 +40,14 @@ FontLanguage::FontLanguage(const char* buf, size_t size) { if (c == '-' || c == '_') break; } if (i == 2) { - bits = (uint8_t(buf[0]) << 8) | uint8_t(buf[1]); + bits = uint8_t(buf[0]) | (uint8_t(buf[1]) << 8); + } else if (i == 3) { + bits = uint8_t(buf[0]) | (uint8_t(buf[1]) << 8) | (uint8_t(buf[2]) << 16); + } else { + mBits = kUnsupportedLanguage; + // We don't understand anything other than two-letter or three-letter + // language codes, so we skip parsing the rest of the string. + return; } size_t next; for (i++; i < size; i = next + 1) { @@ -62,28 +69,38 @@ FontLanguage::FontLanguage(const char* buf, size_t size) { } std::string FontLanguage::getString() const { - char buf[16]; - size_t i = 0; - if (mBits & kBaseLangMask) { - buf[i++] = (mBits >> 8) & 0xFFu; - buf[i++] = mBits & 0xFFu; - } - if (mBits & kScriptMask) { - if (!i) - buf[i++] = 'x'; - buf[i++] = '-'; - buf[i++] = 'H'; - buf[i++] = 'a'; - buf[i++] = 'n'; - if (mBits & kHansFlag) - buf[i++] = 's'; - else - buf[i++] = 't'; - } - return std::string(buf, i); + if (mBits == kUnsupportedLanguage) { + return "und"; + } + char buf[16]; + size_t i = 0; + if (mBits & kBaseLangMask) { + buf[i++] = mBits & 0xFFu; + buf[i++] = (mBits >> 8) & 0xFFu; + char third_letter = (mBits >> 16) & 0xFFu; + if (third_letter != 0) buf[i++] = third_letter; + } + if (mBits & kScriptMask) { + if (!i) { + // This should not happen, but as it apparently has, we fill the language code part + // with "und". + buf[i++] = 'u'; + buf[i++] = 'n'; + buf[i++] = 'd'; + } + buf[i++] = '-'; + buf[i++] = 'H'; + buf[i++] = 'a'; + buf[i++] = 'n'; + buf[i++] = (mBits & kHansFlag) ? 's' : 't'; + } + return std::string(buf, i); } int FontLanguage::match(const FontLanguage other) const { + if (mBits == kUnsupportedLanguage || other.mBits == kUnsupportedLanguage) + return 0; + int result = 0; if ((mBits & kBaseLangMask) == (other.mBits & kBaseLangMask)) { result++; From f1919543373951d4fa2dab862d463ad1ecf3e204 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Tue, 11 Aug 2015 16:27:06 -0700 Subject: [PATCH 099/364] Clean up use of printf() in Layout.cpp. Reported externally at https://code.google.com/p/android/issues/detail?id=167715. Bug: 21498085 Change-Id: I73f22de03b0151ce31a6b3070d051a2a701b33d2 --- engine/src/flutter/libs/minikin/Layout.cpp | 26 +++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index be29e3ca2a0..1b1ad1f296a 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -18,7 +18,6 @@ #include #include -#include // for debugging #include #include @@ -302,8 +301,10 @@ hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { return 0; } ok = font->GetTable(tag, reinterpret_cast(buffer), &length); - printf("referenceTable %c%c%c%c length=%d %d\n", +#ifdef VERBOSE_DEBUG + ALOGD("referenceTable %c%c%c%c length=%d %d", (tag >>24) & 0xff, (tag>>16)&0xff, (tag>>8)&0xff, tag&0xff, length, ok); +#endif if (!ok) { free(buffer); return 0; @@ -717,9 +718,8 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t ctx->paint.font = mFaces[font_ix].font; ctx->paint.fakery = mFaces[font_ix].fakery; hb_font_t* hbFont = ctx->hbFonts[font_ix]; -#ifdef VERBOSE - std::cout << "Run " << run_ix << ", font " << font_ix << - " [" << run.start << ":" << run.end << "]" << std::endl; +#ifdef VERBOSE_DEBUG + ALOGD("Run %u, font %d [%d:%d]", run_ix, font_ix, run.start, run.end); #endif hb_font_set_ppem(hbFont, size * scaleX, size); @@ -783,10 +783,14 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t x += letterSpaceHalfLeft; } for (unsigned int i = 0; i < numGlyphs; i++) { - #ifdef VERBOSE - std::cout << positions[i].x_advance << " " << positions[i].y_advance << " " << positions[i].x_offset << " " << positions[i].y_offset << std::endl; std::cout << "DoLayout " << info[i].codepoint << - ": " << HBFixedToFloat(positions[i].x_advance) << "; " << positions[i].x_offset << ", " << positions[i].y_offset << std::endl; - #endif +#ifdef VERBOSE_DEBUG + ALOGD("%d %d %d %d", + positions[i].x_advance, positions[i].y_advance, + positions[i].x_offset, positions[i].y_offset); + ALOGD("DoLayout %u: %f; %d, %d", + info[i].codepoint, HBFixedToFloat(positions[i].x_advance), + positions[i].x_offset, positions[i].y_offset); +#endif if (i > 0 && info[i - 1].cluster != info[i].cluster) { mAdvances[info[i - 1].cluster - start] += letterSpaceHalfRight; mAdvances[info[i].cluster - start] += letterSpaceHalfLeft; @@ -877,8 +881,10 @@ void Layout::draw(minikin::Bitmap* surface, int x0, int y0, float size) const { MinikinPaint paint; paint.size = size; bool ok = face->Render(glyph.glyph_id, paint, &glyphBitmap); - printf("glyphBitmap.width=%d, glyphBitmap.height=%d (%d, %d) x=%f, y=%f, ok=%d\n", +#ifdef VERBOSE_DEBUG + ALOGD("glyphBitmap.width=%d, glyphBitmap.height=%d (%d, %d) x=%f, y=%f, ok=%d", glyphBitmap.width, glyphBitmap.height, glyphBitmap.left, glyphBitmap.top, glyph.x, glyph.y, ok); +#endif if (ok) { surface->drawGlyph(glyphBitmap, x0 + int(floor(glyph.x + 0.5)), y0 + int(floor(glyph.y + 0.5))); From 4f1a8688721c4c20524cb7c8e5b68e3865dbbe63 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 12 Aug 2015 11:29:39 -0700 Subject: [PATCH 100/364] Add basic unit tests for Minikin Initial unit tests for Minikin functionality. Also fixes an incorrect Hangul case (uncovered in testing), and improves handling of broken UTF-16. Change-Id: I69b441d8e3b19ed06abcc56f13271abadf3d1010 --- engine/src/flutter/libs/minikin/Android.mk | 26 +++- .../flutter/libs/minikin/GraphemeBreak.cpp | 14 +- engine/src/flutter/tests/Android.mk | 41 ++++++ .../src/flutter/tests/GraphemeBreakTests.cpp | 130 ++++++++++++++++++ engine/src/flutter/tests/UnicodeUtils.cpp | 96 +++++++++++++ engine/src/flutter/tests/UnicodeUtils.h | 18 +++ engine/src/flutter/tests/how_to_run.txt | 4 + 7 files changed, 316 insertions(+), 13 deletions(-) create mode 100644 engine/src/flutter/tests/Android.mk create mode 100644 engine/src/flutter/tests/GraphemeBreakTests.cpp create mode 100644 engine/src/flutter/tests/UnicodeUtils.cpp create mode 100644 engine/src/flutter/tests/UnicodeUtils.h create mode 100644 engine/src/flutter/tests/how_to_run.txt diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 873f279f0c9..e2b588c19c7 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -16,7 +16,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_SRC_FILES := \ +minikin_src_files := \ AnalyzeStyle.cpp \ CmapCoverage.cpp \ FontCollection.cpp \ @@ -31,20 +31,34 @@ LOCAL_SRC_FILES := \ MinikinFontFreeType.cpp \ SparseBitSet.cpp -LOCAL_MODULE := libminikin - -LOCAL_C_INCLUDES += \ +minikin_c_includes := \ external/harfbuzz_ng/src \ external/freetype/include \ frameworks/minikin/include -LOCAL_SHARED_LIBRARIES := \ +minikin_shared_libraries := \ libharfbuzz_ng \ libft2 \ liblog \ - libpng \ libz \ libicuuc \ libutils +LOCAL_MODULE := libminikin +LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include +LOCAL_SRC_FILES := $(minikin_src_files) +LOCAL_C_INCLUDES := $(minikin_c_includes) +LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) + include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) + +LOCAL_MODULE := libminikin +LOCAL_MODULE_TAGS := optional +LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include +LOCAL_SRC_FILES := $(minikin_src_files) +LOCAL_C_INCLUDES := $(minikin_c_includes) +LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) + +include $(BUILD_STATIC_LIBRARY) diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index 21da180b105..eca74b178ce 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -71,13 +71,13 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co // implementing a tailored version of extended grapheme clusters. // The GB rules refer to section 3.1.1, Grapheme Cluster Boundary Rules. - // Rule GB1, sot /; Rule GB2, / eot + // Rule GB1, sot ÷; Rule GB2, ÷ eot if (offset <= start || offset >= start + count) { return true; } if (U16_IS_TRAIL(buf[offset])) { - // Don't break a surrogate pair - return false; + // Don't break a surrogate pair, but a lonely trailing surrogate pair is a break + return !U16_IS_LEAD(buf[offset - 1]); } uint32_t c1 = 0; uint32_t c2 = 0; @@ -90,11 +90,11 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co if (p1 == U_GCB_CR && p2 == U_GCB_LF) { return false; } - // Rule GB4, (Control | CR | LF) / + // Rule GB4, (Control | CR | LF) ÷ if (p1 == U_GCB_CONTROL || p1 == U_GCB_CR || p1 == U_GCB_LF) { return true; } - // Rule GB5, / (Control | CR | LF) + // Rule GB5, ÷ (Control | CR | LF) if (p2 == U_GCB_CONTROL || p2 == U_GCB_CR || p2 == U_GCB_LF) { return true; } @@ -107,7 +107,7 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co return false; } // Rule GB8, ( LVT | T ) x T - if ((p1 == U_GCB_L || p1 == U_GCB_T) && p2 == U_GCB_T) { + if ((p1 == U_GCB_LVT || p1 == U_GCB_T) && p2 == U_GCB_T) { return false; } // Rule GB8a, Regional_Indicator x Regional_Indicator @@ -139,7 +139,7 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co && u_getIntPropertyValue(c2, UCHAR_GENERAL_CATEGORY) == U_OTHER_LETTER) { return false; } - // Rule GB10, Any / Any + // Rule GB10, Any ÷ Any return true; } diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk new file mode 100644 index 00000000000..ebce0eace3b --- /dev/null +++ b/engine/src/flutter/tests/Android.mk @@ -0,0 +1,41 @@ +# Copyright (C) 2015 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. + +# see how_to_run.txt for instructions on running these tests + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := minikin_tests +LOCAL_MODULE_TAGS := tests + +LOCAL_STATIC_LIBRARIES := libminikin + +# Shared libraries which are dependencies of minikin; these are not automatically +# pulled in by the build system (and thus sadly must be repeated). + +LOCAL_SHARED_LIBRARIES := \ + libharfbuzz_ng \ + libft2 \ + liblog \ + libz \ + libicuuc \ + libutils + +LOCAL_SRC_FILES += \ + GraphemeBreakTests.cpp \ + UnicodeUtils.cpp + +include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/GraphemeBreakTests.cpp b/engine/src/flutter/tests/GraphemeBreakTests.cpp new file mode 100644 index 00000000000..6eda4da9fdb --- /dev/null +++ b/engine/src/flutter/tests/GraphemeBreakTests.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2015 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 +#include +#include + +using namespace android; + +bool IsBreak(const char* src) { + const size_t BUF_SIZE = 256; + uint16_t buf[BUF_SIZE]; + size_t offset; + size_t size; + ParseUnicode(buf, BUF_SIZE, src, &size, &offset); + return GraphemeBreak::isGraphemeBreak(buf, 0, size, offset); +} + +TEST(GraphemeBreak, utf16) { + EXPECT_FALSE(IsBreak("U+D83C | U+DC31")); // emoji, U+1F431 + + // tests for invalid UTF-16 + EXPECT_TRUE(IsBreak("U+D800 | U+D800")); // two leading surrogates + EXPECT_TRUE(IsBreak("U+DC00 | U+DC00")); // two trailing surrogates + EXPECT_TRUE(IsBreak("'a' | U+D800")); // lonely leading surrogate + EXPECT_TRUE(IsBreak("U+DC00 | 'a'")); // lonely trailing surrogate + EXPECT_TRUE(IsBreak("U+D800 | 'a'")); // leading surrogate followed by non-surrogate + EXPECT_TRUE(IsBreak("'a' | U+DC00")); // non-surrogate followed by trailing surrogate +} + +TEST(GraphemeBreak, rules) { + // Rule GB1, sot ÷; Rule GB2, ÷ eot + EXPECT_TRUE(IsBreak("| 'a'")); + EXPECT_TRUE(IsBreak("'a' |")); + + // Rule GB3, CR x LF + EXPECT_FALSE(IsBreak("U+000D | U+000A")); // CR x LF + + // Rule GB4, (Control | CR | LF) ÷ + EXPECT_TRUE(IsBreak("'a' | U+2028")); // Line separator + EXPECT_TRUE(IsBreak("'a' | U+000D")); // LF + EXPECT_TRUE(IsBreak("'a' | U+000A")); // CR + + // Rule GB5, ÷ (Control | CR | LF) + EXPECT_TRUE(IsBreak("U+2028 | 'a'")); // Line separator + EXPECT_TRUE(IsBreak("U+000D | 'a'")); // LF + EXPECT_TRUE(IsBreak("U+000A | 'a'")); // CR + + // Rule GB6, L x ( L | V | LV | LVT ) + EXPECT_FALSE(IsBreak("U+1100 | U+1100")); // L x L + EXPECT_FALSE(IsBreak("U+1100 | U+1161")); // L x V + EXPECT_FALSE(IsBreak("U+1100 | U+AC00")); // L x LV + EXPECT_FALSE(IsBreak("U+1100 | U+AC01")); // L x LVT + + // Rule GB7, ( LV | V ) x ( V | T ) + EXPECT_FALSE(IsBreak("U+AC00 | U+1161")); // LV x V + EXPECT_FALSE(IsBreak("U+1161 | U+1161")); // V x V + EXPECT_FALSE(IsBreak("U+AC00 | U+11A8")); // LV x T + EXPECT_FALSE(IsBreak("U+1161 | U+11A8")); // V x T + + // Rule GB8, ( LVT | T ) x T + EXPECT_FALSE(IsBreak("U+AC01 | U+11A8")); // LVT x T + EXPECT_FALSE(IsBreak("U+11A8 | U+11A8")); // T x T + + // Other hangul pairs not counted above _are_ breaks (GB10) + EXPECT_TRUE(IsBreak("U+AC00 | U+1100")); // LV x L + EXPECT_TRUE(IsBreak("U+AC01 | U+1100")); // LVT x L + EXPECT_TRUE(IsBreak("U+11A8 | U+1100")); // T x L + EXPECT_TRUE(IsBreak("U+11A8 | U+AC00")); // T x LV + EXPECT_TRUE(IsBreak("U+11A8 | U+AC01")); // T x LVT + + // Rule GB8a, Regional_Indicator x Regional_Indicator + EXPECT_FALSE(IsBreak("U+1F1FA | U+1F1F8")); + + // Rule GB9, x Extend + EXPECT_FALSE(IsBreak("'a' | U+0301")); // combining accent + // Rule GB9a, x SpacingMark + EXPECT_FALSE(IsBreak("U+0915 | U+093E")); // KA, AA (spacing mark) + // Rule GB9b, Prepend x + // see tailoring test for prepend, as current ICU doesn't have any characters in the class + + // Rule GB10, Any ÷ Any + EXPECT_TRUE(IsBreak("'a' | 'b'")); + EXPECT_TRUE(IsBreak("'f' | 'i'")); // probable ligature + EXPECT_TRUE(IsBreak("U+0644 | U+0627")); // probable ligature, lam + alef + EXPECT_TRUE(IsBreak("U+4E00 | U+4E00")); // CJK ideographs + EXPECT_TRUE(IsBreak("'a' | U+1F1FA U+1F1F8")); // Regional indicator pair (flag) + EXPECT_TRUE(IsBreak("U+1F1FA U+1F1F8 | 'a'")); // Regional indicator pair (flag) +} + +TEST(GraphemeBreak, tailoring) { + // control characters that we interpret as "extend" + EXPECT_FALSE(IsBreak("'a' | U+00AD")); // soft hyphen + EXPECT_FALSE(IsBreak("'a' | U+200B")); // zwsp + EXPECT_FALSE(IsBreak("'a' | U+200E")); // lrm + EXPECT_FALSE(IsBreak("'a' | U+202A")); // lre + EXPECT_FALSE(IsBreak("'a' | U+E0041")); // tag character + + // UTC-approved characters for the Prepend class + EXPECT_FALSE(IsBreak("U+06DD | U+0661")); // arabic subtending mark + digit one + + EXPECT_TRUE(IsBreak("U+0E01 | U+0E33")); // Thai sara am + + // virama is not a grapheme break, but "pure killer" is + EXPECT_FALSE(IsBreak("U+0915 | U+094D U+0915")); // Devanagari ka+virama+ka + EXPECT_FALSE(IsBreak("U+0915 U+094D | U+0915")); // Devanagari ka+virama+ka + EXPECT_FALSE(IsBreak("U+0E01 | U+0E3A U+0E01")); // thai phinthu = pure killer + EXPECT_TRUE(IsBreak("U+0E01 U+0E3A | U+0E01")); // thai phinthu = pure killer +} + +TEST(GraphemeBreak, offsets) { + uint16_t string[] = { 0x0041, 0x06DD, 0x0045, 0x0301, 0x0049, 0x0301 }; + EXPECT_TRUE(GraphemeBreak::isGraphemeBreak(string, 2, 3, 2)); + EXPECT_FALSE(GraphemeBreak::isGraphemeBreak(string, 2, 3, 3)); + EXPECT_TRUE(GraphemeBreak::isGraphemeBreak(string, 2, 3, 4)); + EXPECT_TRUE(GraphemeBreak::isGraphemeBreak(string, 2, 3, 5)); +} diff --git a/engine/src/flutter/tests/UnicodeUtils.cpp b/engine/src/flutter/tests/UnicodeUtils.cpp new file mode 100644 index 00000000000..501fc9f4808 --- /dev/null +++ b/engine/src/flutter/tests/UnicodeUtils.cpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2015 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 +#include +#include + +// src is of the form "U+1F431 | 'h' 'i'". Position of "|" gets saved to offset if non-null. +// Size is returned in an out parameter because gtest needs a void return for ASSERT to work. +void ParseUnicode(uint16_t* buf, size_t buf_size, const char* src, size_t* result_size, + size_t* offset) { + size_t input_ix = 0; + size_t output_ix = 0; + bool seen_offset = false; + + while (src[input_ix] != 0) { + switch (src[input_ix]) { + case '\'': + // single ASCII char + ASSERT_LT(src[input_ix], 0x80); + input_ix++; + ASSERT_NE(src[input_ix], 0); + ASSERT_LT(output_ix, buf_size); + buf[output_ix++] = (uint16_t)src[input_ix++]; + ASSERT_EQ(src[input_ix], '\''); + input_ix++; + break; + case 'u': + case 'U': { + // Unicode codepoint in hex syntax + input_ix++; + ASSERT_EQ(src[input_ix], '+'); + input_ix++; + char* endptr = (char*)src + input_ix; + unsigned long int codepoint = strtoul(src + input_ix, &endptr, 16); + size_t num_hex_digits = endptr - (src + input_ix); + ASSERT_GE(num_hex_digits, 4u); // also triggers on invalid number syntax, digits = 0 + ASSERT_LE(num_hex_digits, 6u); + ASSERT_LE(codepoint, 0x10FFFFu); + input_ix += num_hex_digits; + if (U16_LENGTH(codepoint) == 1) { + ASSERT_LE(output_ix + 1, buf_size); + buf[output_ix++] = codepoint; + } else { + // UTF-16 encoding + ASSERT_LE(output_ix + 2, buf_size); + buf[output_ix++] = U16_LEAD(codepoint); + buf[output_ix++] = U16_TRAIL(codepoint); + } + break; + } + case ' ': + input_ix++; + break; + case '|': + ASSERT_FALSE(seen_offset); + ASSERT_NE(offset, nullptr); + *offset = output_ix; + seen_offset = true; + input_ix++; + break; + default: + FAIL(); // unexpected character + } + } + ASSERT_NE(result_size, nullptr); + *result_size = output_ix; + ASSERT_TRUE(seen_offset || offset == nullptr); +} + +TEST(UnicodeUtils, parse) { + const size_t BUF_SIZE = 256; + uint16_t buf[BUF_SIZE]; + size_t offset; + size_t size; + ParseUnicode(buf, BUF_SIZE, "U+000D U+1F431 | 'a'", &size, &offset); + EXPECT_EQ(size, 4u); + EXPECT_EQ(offset, 3u); + EXPECT_EQ(buf[0], 0x000D); + EXPECT_EQ(buf[1], 0xD83D); + EXPECT_EQ(buf[2], 0xDC31); + EXPECT_EQ(buf[3], 'a'); +} diff --git a/engine/src/flutter/tests/UnicodeUtils.h b/engine/src/flutter/tests/UnicodeUtils.h new file mode 100644 index 00000000000..4f1b06a2fc1 --- /dev/null +++ b/engine/src/flutter/tests/UnicodeUtils.h @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2015 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. + */ + + void ParseUnicode(uint16_t* buf, size_t buf_size, const char* src, size_t* result_size, + size_t* offset); diff --git a/engine/src/flutter/tests/how_to_run.txt b/engine/src/flutter/tests/how_to_run.txt new file mode 100644 index 00000000000..a6b79528551 --- /dev/null +++ b/engine/src/flutter/tests/how_to_run.txt @@ -0,0 +1,4 @@ +mmm -j8 frameworks/minikin/tests && +adb push $OUT/data/nativetest/minikin_tests/minikin_tests \ + /data/nativetest/minikin_tests/minikin_tests && +adb shell /data/nativetest/minikin_tests/minikin_tests From f09cf789ef140f47d02554d7aec74a5c1c42f9f4 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 25 Aug 2015 12:06:46 -0700 Subject: [PATCH 101/364] Update word breaker to be aware tone mark and variation selector. This CL does: 1. Move the getNextWordBreak/getPrevWordBreak function to a separate source file. 2. Adding "ForCache" suffix for function name for making clear these function is for layout cache. 3. Introduce unit tests for them. Bug: 11256006 Change-Id: I4138751a4570915f1a0d6c8921f89700f8ec7f35 --- engine/src/flutter/libs/minikin/Android.mk | 1 + engine/src/flutter/libs/minikin/Layout.cpp | 60 +-- .../src/flutter/libs/minikin/LayoutUtils.cpp | 76 +++ engine/src/flutter/libs/minikin/LayoutUtils.h | 42 ++ engine/src/flutter/tests/Android.mk | 3 + engine/src/flutter/tests/LayoutUtilsTest.cpp | 510 ++++++++++++++++++ 6 files changed, 638 insertions(+), 54 deletions(-) create mode 100644 engine/src/flutter/libs/minikin/LayoutUtils.cpp create mode 100644 engine/src/flutter/libs/minikin/LayoutUtils.h create mode 100644 engine/src/flutter/tests/LayoutUtilsTest.cpp diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index e2b588c19c7..765a3ddfd75 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -24,6 +24,7 @@ minikin_src_files := \ GraphemeBreak.cpp \ Hyphenator.cpp \ Layout.cpp \ + LayoutUtils.cpp \ LineBreaker.cpp \ Measurement.cpp \ MinikinInternal.cpp \ diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 1b1ad1f296a..b995a144cf1 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -33,6 +33,7 @@ #include #include +#include "LayoutUtils.h" #include "MinikinInternal.h" #include #include @@ -468,56 +469,6 @@ static hb_script_t getScriptRun(const uint16_t* chars, size_t len, ssize_t* iter return current_script; } -/** - * For the purpose of layout, a word break is a boundary with no - * kerning or complex script processing. This is necessarily a - * heuristic, but should be accurate most of the time. - */ -static bool isWordBreak(int c) { - if (c == ' ' || (c >= 0x2000 && c <= 0x200a) || c == 0x3000) { - // spaces - return true; - } - if ((c >= 0x3400 && c <= 0x9fff)) { - // CJK ideographs (and yijing hexagram symbols) - return true; - } - // Note: kana is not included, as sophisticated fonts may kern kana - return false; -} - -/** - * Return offset of previous word break. It is either < offset or == 0. - */ -static size_t getPrevWordBreak(const uint16_t* chars, size_t offset) { - if (offset == 0) return 0; - if (isWordBreak(chars[offset - 1])) { - return offset - 1; - } - for (size_t i = offset - 1; i > 0; i--) { - if (isWordBreak(chars[i - 1])) { - return i; - } - } - return 0; -} - -/** - * Return offset of next word break. It is either > offset or == len. - */ -static size_t getNextWordBreak(const uint16_t* chars, size_t offset, size_t len) { - if (offset >= len) return len; - if (isWordBreak(chars[offset])) { - return offset + 1; - } - for (size_t i = offset + 1; i < len; i++) { - if (isWordBreak(chars[i])) { - return i; - } - } - return len; -} - /** * Disable certain scripts (mostly those with cursive connection) from having letterspacing * applied. See https://github.com/behdad/harfbuzz/issues/64 for more details. @@ -615,10 +566,11 @@ void Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, HyphenEdit hyphen = ctx->paint.hyphenEdit; if (!isRtl) { // left to right - size_t wordstart = start == bufSize ? start : getPrevWordBreak(buf, start + 1); + size_t wordstart = + start == bufSize ? start : getPrevWordBreakForCache(buf, start + 1, bufSize); size_t wordend; for (size_t iter = start; iter < start + count; iter = wordend) { - wordend = getNextWordBreak(buf, iter, bufSize); + wordend = getNextWordBreakForCache(buf, iter, bufSize); // Only apply hyphen to the last word in the string. ctx->paint.hyphenEdit = wordend >= start + count ? hyphen : HyphenEdit(); size_t wordcount = std::min(start + count, wordend) - iter; @@ -630,9 +582,9 @@ void Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, // right to left size_t wordstart; size_t end = start + count; - size_t wordend = end == 0 ? 0 : getNextWordBreak(buf, end - 1, bufSize); + size_t wordend = end == 0 ? 0 : getNextWordBreakForCache(buf, end - 1, bufSize); for (size_t iter = end; iter > start; iter = wordstart) { - wordstart = getPrevWordBreak(buf, iter); + wordstart = getPrevWordBreakForCache(buf, iter, bufSize); // Only apply hyphen to the last (leftmost) word in the string. ctx->paint.hyphenEdit = iter == end ? hyphen : HyphenEdit(); size_t bufStart = std::max(start, wordstart); diff --git a/engine/src/flutter/libs/minikin/LayoutUtils.cpp b/engine/src/flutter/libs/minikin/LayoutUtils.cpp new file mode 100644 index 00000000000..418268286c6 --- /dev/null +++ b/engine/src/flutter/libs/minikin/LayoutUtils.cpp @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2015 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. + */ + +#define LOG_TAG "Minikin" + +#include "LayoutUtils.h" + +/** + * For the purpose of layout, a word break is a boundary with no + * kerning or complex script processing. This is necessarily a + * heuristic, but should be accurate most of the time. + */ +static bool isWordBreakAfter(int c) { + if (c == ' ' || (c >= 0x2000 && c <= 0x200a) || c == 0x3000) { + // spaces + return true; + } + // Note: kana is not included, as sophisticated fonts may kern kana + return false; +} + +static bool isWordBreakBefore(int c) { + // CJK ideographs (and yijing hexagram symbols) + return isWordBreakAfter(c) || (c >= 0x3400 && c <= 0x9fff); +} + +/** + * Return offset of previous word break. It is either < offset or == 0. + */ +size_t getPrevWordBreakForCache( + const uint16_t* chars, size_t offset, size_t len) { + if (offset == 0) return 0; + if (offset > len) offset = len; + if (isWordBreakBefore(chars[offset - 1])) { + return offset - 1; + } + for (size_t i = offset - 1; i > 0; i--) { + if (isWordBreakBefore(chars[i]) || isWordBreakAfter(chars[i - 1])) { + return i; + } + } + return 0; +} + +/** + * Return offset of next word break. It is either > offset or == len. + */ +size_t getNextWordBreakForCache( + const uint16_t* chars, size_t offset, size_t len) { + if (offset >= len) return len; + if (isWordBreakAfter(chars[offset])) { + return offset + 1; + } + for (size_t i = offset + 1; i < len; i++) { + // No need to check isWordBreakAfter(chars[i - 1]) since it is checked + // in previous iteration. Note that isWordBreakBefore returns true + // whenever isWordBreakAfter returns true. + if (isWordBreakBefore(chars[i])) { + return i; + } + } + return len; +} diff --git a/engine/src/flutter/libs/minikin/LayoutUtils.h b/engine/src/flutter/libs/minikin/LayoutUtils.h new file mode 100644 index 00000000000..83ddd0a255d --- /dev/null +++ b/engine/src/flutter/libs/minikin/LayoutUtils.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2015 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_LAYOUT_UTILS_H +#define MINIKIN_LAYOUT_UTILS_H + +#include + +/** + * Return offset of previous word break. It is either < offset or == 0. + * + * For the purpose of layout, a word break is a boundary with no + * kerning or complex script processing. This is necessarily a + * heuristic, but should be accurate most of the time. + */ +size_t getPrevWordBreakForCache( + const uint16_t* chars, size_t offset, size_t len); + +/** + * Return offset of next word break. It is either > offset or == len. + * + * For the purpose of layout, a word break is a boundary with no + * kerning or complex script processing. This is necessarily a + * heuristic, but should be accurate most of the time. + */ +size_t getNextWordBreakForCache( + const uint16_t* chars, size_t offset, size_t len); + +#endif // MINIKIN_LAYOUT_UTILS_H diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index ebce0eace3b..00847e3b2a7 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -36,6 +36,9 @@ LOCAL_SHARED_LIBRARIES := \ LOCAL_SRC_FILES += \ GraphemeBreakTests.cpp \ + LayoutUtilsTest.cpp \ UnicodeUtils.cpp +LOCAL_C_INCLUDES := $(LOCAL_PATH)/../libs/minikin/ + include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/LayoutUtilsTest.cpp b/engine/src/flutter/tests/LayoutUtilsTest.cpp new file mode 100644 index 00000000000..f4fbb181076 --- /dev/null +++ b/engine/src/flutter/tests/LayoutUtilsTest.cpp @@ -0,0 +1,510 @@ +/* + * Copyright (C) 2015 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 +#include + +#include "LayoutUtils.h" + +namespace { + +void ExpectNextWordBreakForCache(size_t offset_in, const char* query_str) { + const size_t BUF_SIZE = 256U; + uint16_t buf[BUF_SIZE]; + size_t expected_breakpoint = 0U; + size_t size = 0U; + + ParseUnicode(buf, BUF_SIZE, query_str, &size, &expected_breakpoint); + EXPECT_EQ(expected_breakpoint, + getNextWordBreakForCache(buf, offset_in, size)) + << "Expected position is [" << query_str << "] from offset " << offset_in; +} + +void ExpectPrevWordBreakForCache(size_t offset_in, const char* query_str) { + const size_t BUF_SIZE = 256U; + uint16_t buf[BUF_SIZE]; + size_t expected_breakpoint = 0U; + size_t size = 0U; + + ParseUnicode(buf, BUF_SIZE, query_str, &size, &expected_breakpoint); + EXPECT_EQ(expected_breakpoint, + getPrevWordBreakForCache(buf, offset_in, size)) + << "Expected position is [" << query_str << "] from offset " << offset_in; +} + +TEST(WordBreakTest, goNextWordBreakTest) { + ExpectNextWordBreakForCache(0, "|"); + + // Continue for spaces. + ExpectNextWordBreakForCache(0, "'a' 'b' 'c' 'd' |"); + ExpectNextWordBreakForCache(1, "'a' 'b' 'c' 'd' |"); + ExpectNextWordBreakForCache(2, "'a' 'b' 'c' 'd' |"); + ExpectNextWordBreakForCache(3, "'a' 'b' 'c' 'd' |"); + ExpectNextWordBreakForCache(4, "'a' 'b' 'c' 'd' |"); + ExpectNextWordBreakForCache(1000, "'a' 'b' 'c' 'd' |"); + + // Space makes word break. + ExpectNextWordBreakForCache(0, "'a' 'b' | U+0020 'c' 'd'"); + ExpectNextWordBreakForCache(1, "'a' 'b' | U+0020 'c' 'd'"); + ExpectNextWordBreakForCache(2, "'a' 'b' U+0020 | 'c' 'd'"); + ExpectNextWordBreakForCache(3, "'a' 'b' U+0020 'c' 'd' |"); + ExpectNextWordBreakForCache(4, "'a' 'b' U+0020 'c' 'd' |"); + ExpectNextWordBreakForCache(5, "'a' 'b' U+0020 'c' 'd' |"); + ExpectNextWordBreakForCache(1000, "'a' 'b' U+0020 'c' 'd' |"); + + ExpectNextWordBreakForCache(0, "'a' 'b' | U+2000 'c' 'd'"); + ExpectNextWordBreakForCache(1, "'a' 'b' | U+2000 'c' 'd'"); + ExpectNextWordBreakForCache(2, "'a' 'b' U+2000 | 'c' 'd'"); + ExpectNextWordBreakForCache(3, "'a' 'b' U+2000 'c' 'd' |"); + ExpectNextWordBreakForCache(4, "'a' 'b' U+2000 'c' 'd' |"); + ExpectNextWordBreakForCache(5, "'a' 'b' U+2000 'c' 'd' |"); + ExpectNextWordBreakForCache(1000, "'a' 'b' U+2000 'c' 'd' |"); + + ExpectNextWordBreakForCache(0, "'a' 'b' | U+2000 U+2000 'c' 'd'"); + ExpectNextWordBreakForCache(1, "'a' 'b' | U+2000 U+2000 'c' 'd'"); + ExpectNextWordBreakForCache(2, "'a' 'b' U+2000 | U+2000 'c' 'd'"); + ExpectNextWordBreakForCache(3, "'a' 'b' U+2000 U+2000 | 'c' 'd'"); + ExpectNextWordBreakForCache(4, "'a' 'b' U+2000 U+2000 'c' 'd' |"); + ExpectNextWordBreakForCache(5, "'a' 'b' U+2000 U+2000 'c' 'd' |"); + ExpectNextWordBreakForCache(6, "'a' 'b' U+2000 U+2000 'c' 'd' |"); + ExpectNextWordBreakForCache(1000, "'a' 'b' U+2000 U+2000 'c' 'd' |"); + + // CJK ideographs makes word break. + ExpectNextWordBreakForCache(0, "U+4E00 | U+4E00 U+4E00 U+4E00 U+4E00"); + ExpectNextWordBreakForCache(1, "U+4E00 U+4E00 | U+4E00 U+4E00 U+4E00"); + ExpectNextWordBreakForCache(2, "U+4E00 U+4E00 U+4E00 | U+4E00 U+4E00"); + ExpectNextWordBreakForCache(3, "U+4E00 U+4E00 U+4E00 U+4E00 | U+4E00"); + ExpectNextWordBreakForCache(4, "U+4E00 U+4E00 U+4E00 U+4E00 U+4E00 |"); + ExpectNextWordBreakForCache(5, "U+4E00 U+4E00 U+4E00 U+4E00 U+4E00 |"); + ExpectNextWordBreakForCache(1000, + "U+4E00 U+4E00 U+4E00 U+4E00 U+4E00 |"); + + ExpectNextWordBreakForCache(0, "U+4E00 | U+4E8C U+4E09 U+56DB U+4E94"); + ExpectNextWordBreakForCache(1, "U+4E00 U+4E8C | U+4E09 U+56DB U+4E94"); + ExpectNextWordBreakForCache(2, "U+4E00 U+4E8C U+4E09 | U+56DB U+4E94"); + ExpectNextWordBreakForCache(3, "U+4E00 U+4E8C U+4E09 U+56DB | U+4E94"); + ExpectNextWordBreakForCache(4, "U+4E00 U+4E8C U+4E09 U+56DB U+4E94 |"); + ExpectNextWordBreakForCache(5, "U+4E00 U+4E8C U+4E09 U+56DB U+4E94 |"); + ExpectNextWordBreakForCache(1000, + "U+4E00 U+4E8C U+4E09 U+56DB U+4E94 |"); + + ExpectNextWordBreakForCache(0, "U+4E00 'a' 'b' | U+2000 'c' U+4E00"); + ExpectNextWordBreakForCache(1, "U+4E00 'a' 'b' | U+2000 'c' U+4E00"); + ExpectNextWordBreakForCache(2, "U+4E00 'a' 'b' | U+2000 'c' U+4E00"); + ExpectNextWordBreakForCache(3, "U+4E00 'a' 'b' U+2000 | 'c' U+4E00"); + ExpectNextWordBreakForCache(4, "U+4E00 'a' 'b' U+2000 'c' | U+4E00"); + ExpectNextWordBreakForCache(5, "U+4E00 'a' 'b' U+2000 'c' U+4E00 |"); + ExpectNextWordBreakForCache(1000, "U+4E00 'a' 'b' U+2000 'c' U+4E00 |"); + + // Continue if trailing characters is Unicode combining characters. + ExpectNextWordBreakForCache(0, "U+4E00 U+0332 | U+4E00"); + ExpectNextWordBreakForCache(1, "U+4E00 U+0332 | U+4E00"); + ExpectNextWordBreakForCache(2, "U+4E00 U+0332 U+4E00 |"); + ExpectNextWordBreakForCache(3, "U+4E00 U+0332 U+4E00 |"); + ExpectNextWordBreakForCache(1000, "U+4E00 U+0332 U+4E00 |"); + + // Surrogate pairs. + ExpectNextWordBreakForCache(0, "U+1F60D U+1F618 |"); + ExpectNextWordBreakForCache(1, "U+1F60D U+1F618 |"); + ExpectNextWordBreakForCache(2, "U+1F60D U+1F618 |"); + ExpectNextWordBreakForCache(3, "U+1F60D U+1F618 |"); + ExpectNextWordBreakForCache(4, "U+1F60D U+1F618 |"); + ExpectNextWordBreakForCache(1000, "U+1F60D U+1F618 |"); + + // Broken surrogate pairs. + // U+D84D is leading surrogate but there is no trailing surrogate for it. + ExpectNextWordBreakForCache(0, "U+D84D U+1F618 |"); + ExpectNextWordBreakForCache(1, "U+D84D U+1F618 |"); + ExpectNextWordBreakForCache(2, "U+D84D U+1F618 |"); + ExpectNextWordBreakForCache(3, "U+D84D U+1F618 |"); + ExpectNextWordBreakForCache(1000, "U+D84D U+1F618 |"); + + ExpectNextWordBreakForCache(0, "U+1F618 U+D84D |"); + ExpectNextWordBreakForCache(1, "U+1F618 U+D84D |"); + ExpectNextWordBreakForCache(2, "U+1F618 U+D84D |"); + ExpectNextWordBreakForCache(3, "U+1F618 U+D84D |"); + ExpectNextWordBreakForCache(1000, "U+1F618 U+D84D |"); + + // U+DE0D is trailing surrogate but there is no leading surrogate for it. + ExpectNextWordBreakForCache(0, "U+DE0D U+1F618 |"); + ExpectNextWordBreakForCache(1, "U+DE0D U+1F618 |"); + ExpectNextWordBreakForCache(2, "U+DE0D U+1F618 |"); + ExpectNextWordBreakForCache(3, "U+DE0D U+1F618 |"); + ExpectNextWordBreakForCache(1000, "U+DE0D U+1F618 |"); + + ExpectNextWordBreakForCache(0, "U+1F618 U+DE0D |"); + ExpectNextWordBreakForCache(1, "U+1F618 U+DE0D |"); + ExpectNextWordBreakForCache(2, "U+1F618 U+DE0D |"); + ExpectNextWordBreakForCache(3, "U+1F618 U+DE0D |"); + ExpectNextWordBreakForCache(1000, "U+1F618 U+DE0D |"); + + // Regional indicator pair. U+1F1FA U+1F1F8 is US national flag. + ExpectNextWordBreakForCache(0, "U+1F1FA U+1F1F8 |"); + ExpectNextWordBreakForCache(1, "U+1F1FA U+1F1F8 |"); + ExpectNextWordBreakForCache(2, "U+1F1FA U+1F1F8 |"); + ExpectNextWordBreakForCache(1000, "U+1F1FA U+1F1F8 |"); + + // Tone marks. + // CJK ideographic char + Tone mark + CJK ideographic char + ExpectNextWordBreakForCache(0, "U+4444 U+302D | U+4444"); + ExpectNextWordBreakForCache(1, "U+4444 U+302D | U+4444"); + ExpectNextWordBreakForCache(2, "U+4444 U+302D U+4444 |"); + ExpectNextWordBreakForCache(3, "U+4444 U+302D U+4444 |"); + ExpectNextWordBreakForCache(1000, "U+4444 U+302D U+4444 |"); + + // Variation Selectors. + // CJK Ideographic char + Variation Selector(VS1) + CJK Ideographic char + ExpectNextWordBreakForCache(0, "U+845B U+FE00 | U+845B"); + ExpectNextWordBreakForCache(1, "U+845B U+FE00 | U+845B"); + ExpectNextWordBreakForCache(2, "U+845B U+FE00 U+845B |"); + ExpectNextWordBreakForCache(3, "U+845B U+FE00 U+845B |"); + ExpectNextWordBreakForCache(1000, "U+845B U+FE00 U+845B |"); + + // CJK Ideographic char + Variation Selector(VS17) + CJK Ideographic char + ExpectNextWordBreakForCache(0, "U+845B U+E0100 | U+845B"); + ExpectNextWordBreakForCache(1, "U+845B U+E0100 | U+845B"); + ExpectNextWordBreakForCache(2, "U+845B U+E0100 | U+845B"); + ExpectNextWordBreakForCache(3, "U+845B U+E0100 U+845B |"); + ExpectNextWordBreakForCache(4, "U+845B U+E0100 U+845B |"); + ExpectNextWordBreakForCache(5, "U+845B U+E0100 U+845B |"); + ExpectNextWordBreakForCache(1000, "U+845B U+E0100 U+845B |"); + + // CJK ideographic char + Tone mark + Variation Character(VS1) + ExpectNextWordBreakForCache(0, "U+4444 U+302D U+FE00 | U+4444"); + ExpectNextWordBreakForCache(1, "U+4444 U+302D U+FE00 | U+4444"); + ExpectNextWordBreakForCache(2, "U+4444 U+302D U+FE00 | U+4444"); + ExpectNextWordBreakForCache(3, "U+4444 U+302D U+FE00 U+4444 |"); + ExpectNextWordBreakForCache(4, "U+4444 U+302D U+FE00 U+4444 |"); + ExpectNextWordBreakForCache(1000, "U+4444 U+302D U+FE00 U+4444 |"); + + // CJK ideographic char + Tone mark + Variation Character(VS17) + ExpectNextWordBreakForCache(0, "U+4444 U+302D U+E0100 | U+4444"); + ExpectNextWordBreakForCache(1, "U+4444 U+302D U+E0100 | U+4444"); + ExpectNextWordBreakForCache(2, "U+4444 U+302D U+E0100 | U+4444"); + ExpectNextWordBreakForCache(3, "U+4444 U+302D U+E0100 | U+4444"); + ExpectNextWordBreakForCache(4, "U+4444 U+302D U+E0100 U+4444 |"); + ExpectNextWordBreakForCache(5, "U+4444 U+302D U+E0100 U+4444 |"); + ExpectNextWordBreakForCache(1000, "U+4444 U+302D U+E0100 U+4444 |"); + + // CJK ideographic char + Variation Character(VS1) + Tone mark + ExpectNextWordBreakForCache(0, "U+4444 U+FE00 U+302D | U+4444"); + ExpectNextWordBreakForCache(1, "U+4444 U+FE00 U+302D | U+4444"); + ExpectNextWordBreakForCache(2, "U+4444 U+FE00 U+302D | U+4444"); + ExpectNextWordBreakForCache(3, "U+4444 U+FE00 U+302D U+4444 |"); + ExpectNextWordBreakForCache(4, "U+4444 U+FE00 U+302D U+4444 |"); + ExpectNextWordBreakForCache(1000, "U+4444 U+FE00 U+302D U+4444 |"); + + // CJK ideographic char + Variation Character(VS17) + Tone mark + ExpectNextWordBreakForCache(0, "U+4444 U+E0100 U+302D | U+4444"); + ExpectNextWordBreakForCache(1, "U+4444 U+E0100 U+302D | U+4444"); + ExpectNextWordBreakForCache(2, "U+4444 U+E0100 U+302D | U+4444"); + ExpectNextWordBreakForCache(3, "U+4444 U+E0100 U+302D | U+4444"); + ExpectNextWordBreakForCache(4, "U+4444 U+E0100 U+302D U+4444 |"); + ExpectNextWordBreakForCache(5, "U+4444 U+E0100 U+302D U+4444 |"); + ExpectNextWordBreakForCache(1000, "U+4444 U+E0100 U+302D U+4444 |"); + + // Following test cases are unusual usage of variation selectors and tone + // marks for caching up the further behavior changes, e.g. index of bounds + // or crashes. Please feel free to update the test expectations if the + // behavior change makes sense to you. + + // Isolated Tone marks and Variation Selectors + ExpectNextWordBreakForCache(0, "U+FE00 |"); + ExpectNextWordBreakForCache(1, "U+FE00 |"); + ExpectNextWordBreakForCache(1000, "U+FE00 |"); + ExpectNextWordBreakForCache(0, "U+E0100 |"); + ExpectNextWordBreakForCache(1000, "U+E0100 |"); + ExpectNextWordBreakForCache(0, "U+302D |"); + ExpectNextWordBreakForCache(1000, "U+302D |"); + + // CJK Ideographic char + Variation Selector(VS1) + Variation Selector(VS1) + ExpectNextWordBreakForCache(0, "U+845B U+FE00 U+FE00 | U+845B"); + ExpectNextWordBreakForCache(1, "U+845B U+FE00 U+FE00 | U+845B"); + ExpectNextWordBreakForCache(2, "U+845B U+FE00 U+FE00 | U+845B"); + ExpectNextWordBreakForCache(3, "U+845B U+FE00 U+FE00 U+845B |"); + ExpectNextWordBreakForCache(4, "U+845B U+FE00 U+FE00 U+845B |"); + ExpectNextWordBreakForCache(1000, "U+845B U+FE00 U+FE00 U+845B |"); + + // CJK Ideographic char + Variation Selector(VS17) + Variation Selector(VS17) + ExpectNextWordBreakForCache(0, "U+845B U+E0100 U+E0100 | U+845B"); + ExpectNextWordBreakForCache(1, "U+845B U+E0100 U+E0100 | U+845B"); + ExpectNextWordBreakForCache(2, "U+845B U+E0100 U+E0100 | U+845B"); + ExpectNextWordBreakForCache(3, "U+845B U+E0100 U+E0100 | U+845B"); + ExpectNextWordBreakForCache(4, "U+845B U+E0100 U+E0100 | U+845B"); + ExpectNextWordBreakForCache(5, "U+845B U+E0100 U+E0100 U+845B |"); + ExpectNextWordBreakForCache(6, "U+845B U+E0100 U+E0100 U+845B |"); + ExpectNextWordBreakForCache(1000, + "U+845B U+E0100 U+E0100 U+845B |"); + + // CJK Ideographic char + Variation Selector(VS1) + Variation Selector(VS17) + ExpectNextWordBreakForCache(0, "U+845B U+FE00 U+E0100 | U+845B"); + ExpectNextWordBreakForCache(1, "U+845B U+FE00 U+E0100 | U+845B"); + ExpectNextWordBreakForCache(2, "U+845B U+FE00 U+E0100 | U+845B"); + ExpectNextWordBreakForCache(3, "U+845B U+FE00 U+E0100 | U+845B"); + ExpectNextWordBreakForCache(4, "U+845B U+FE00 U+E0100 U+845B |"); + ExpectNextWordBreakForCache(5, "U+845B U+FE00 U+E0100 U+845B |"); + ExpectNextWordBreakForCache(1000, "U+845B U+FE00 U+E0100 U+845B |"); + + // CJK Ideographic char + Variation Selector(VS17) + Variation Selector(VS1) + ExpectNextWordBreakForCache(0, "U+845B U+E0100 U+FE00 | U+845B"); + ExpectNextWordBreakForCache(1, "U+845B U+E0100 U+FE00 | U+845B"); + ExpectNextWordBreakForCache(2, "U+845B U+E0100 U+FE00 | U+845B"); + ExpectNextWordBreakForCache(3, "U+845B U+E0100 U+FE00 | U+845B"); + ExpectNextWordBreakForCache(4, "U+845B U+E0100 U+FE00 U+845B |"); + ExpectNextWordBreakForCache(5, "U+845B U+E0100 U+FE00 U+845B |"); + ExpectNextWordBreakForCache(1000, "U+845B U+E0100 U+FE00 U+845B |"); + + // Tone mark. + Tone mark + ExpectNextWordBreakForCache(0, "U+4444 U+302D U+302D | U+4444"); + ExpectNextWordBreakForCache(1, "U+4444 U+302D U+302D | U+4444"); + ExpectNextWordBreakForCache(2, "U+4444 U+302D U+302D | U+4444"); + ExpectNextWordBreakForCache(3, "U+4444 U+302D U+302D U+4444 |"); + ExpectNextWordBreakForCache(4, "U+4444 U+302D U+302D U+4444 |"); + ExpectNextWordBreakForCache(1000, "U+4444 U+302D U+302D U+4444 |"); +} + +TEST(WordBreakTest, goPrevWordBreakTest) { + ExpectPrevWordBreakForCache(0, "|"); + + // Continue for spaces. + ExpectPrevWordBreakForCache(0, "| 'a' 'b' 'c' 'd'"); + ExpectPrevWordBreakForCache(1, "| 'a' 'b' 'c' 'd'"); + ExpectPrevWordBreakForCache(2, "| 'a' 'b' 'c' 'd'"); + ExpectPrevWordBreakForCache(3, "| 'a' 'b' 'c' 'd'"); + ExpectPrevWordBreakForCache(4, "| 'a' 'b' 'c' 'd'"); + ExpectPrevWordBreakForCache(1000, "| 'a' 'b' 'c' 'd'"); + + // Space makes word break. + ExpectPrevWordBreakForCache(0, "| 'a' 'b' U+0020 'c' 'd'"); + ExpectPrevWordBreakForCache(1, "| 'a' 'b' U+0020 'c' 'd'"); + ExpectPrevWordBreakForCache(2, "| 'a' 'b' U+0020 'c' 'd'"); + ExpectPrevWordBreakForCache(3, "'a' 'b' | U+0020 'c' 'd'"); + ExpectPrevWordBreakForCache(4, "'a' 'b' U+0020 | 'c' 'd'"); + ExpectPrevWordBreakForCache(5, "'a' 'b' U+0020 | 'c' 'd'"); + ExpectPrevWordBreakForCache(1000, "'a' 'b' U+0020 | 'c' 'd'"); + + ExpectPrevWordBreakForCache(0, "| 'a' 'b' U+2000 'c' 'd'"); + ExpectPrevWordBreakForCache(1, "| 'a' 'b' U+2000 'c' 'd'"); + ExpectPrevWordBreakForCache(2, "| 'a' 'b' U+2000 'c' 'd'"); + ExpectPrevWordBreakForCache(3, "'a' 'b' | U+2000 'c' 'd'"); + ExpectPrevWordBreakForCache(4, "'a' 'b' U+2000 | 'c' 'd'"); + ExpectPrevWordBreakForCache(5, "'a' 'b' U+2000 | 'c' 'd'"); + ExpectPrevWordBreakForCache(1000, "'a' 'b' U+2000 | 'c' 'd'"); + + ExpectPrevWordBreakForCache(0, "| 'a' 'b' U+2000 U+2000 'c' 'd'"); + ExpectPrevWordBreakForCache(1, "| 'a' 'b' U+2000 U+2000 'c' 'd'"); + ExpectPrevWordBreakForCache(2, "| 'a' 'b' U+2000 U+2000 'c' 'd'"); + ExpectPrevWordBreakForCache(3, "'a' 'b' | U+2000 U+2000 'c' 'd'"); + ExpectPrevWordBreakForCache(4, "'a' 'b' U+2000 | U+2000 'c' 'd'"); + ExpectPrevWordBreakForCache(5, "'a' 'b' U+2000 U+2000 | 'c' 'd'"); + ExpectPrevWordBreakForCache(6, "'a' 'b' U+2000 U+2000 | 'c' 'd'"); + ExpectPrevWordBreakForCache(1000, "'a' 'b' U+2000 U+2000 | 'c' 'd'"); + + // CJK ideographs makes word break. + ExpectPrevWordBreakForCache(0, "| U+4E00 U+4E00 U+4E00 U+4E00 U+4E00"); + ExpectPrevWordBreakForCache(1, "| U+4E00 U+4E00 U+4E00 U+4E00 U+4E00"); + ExpectPrevWordBreakForCache(2, "U+4E00 | U+4E00 U+4E00 U+4E00 U+4E00"); + ExpectPrevWordBreakForCache(3, "U+4E00 U+4E00 | U+4E00 U+4E00 U+4E00"); + ExpectPrevWordBreakForCache(4, "U+4E00 U+4E00 U+4E00 | U+4E00 U+4E00"); + ExpectPrevWordBreakForCache(5, "U+4E00 U+4E00 U+4E00 U+4E00 | U+4E00"); + ExpectPrevWordBreakForCache(1000, "U+4E00 U+4E00 U+4E00 U+4E00 | U+4E00"); + + ExpectPrevWordBreakForCache(0, "| U+4E00 U+4E8C U+4E09 U+56DB U+4E94"); + ExpectPrevWordBreakForCache(1, "| U+4E00 U+4E8C U+4E09 U+56DB U+4E94"); + ExpectPrevWordBreakForCache(2, "U+4E00 | U+4E8C U+4E09 U+56DB U+4E94"); + ExpectPrevWordBreakForCache(3, "U+4E00 U+4E8C | U+4E09 U+56DB U+4E94"); + ExpectPrevWordBreakForCache(4, "U+4E00 U+4E8C U+4E09 | U+56DB U+4E94"); + ExpectPrevWordBreakForCache(5, "U+4E00 U+4E8C U+4E09 U+56DB | U+4E94"); + ExpectPrevWordBreakForCache(1000, "U+4E00 U+4E8C U+4E09 U+56DB | U+4E94"); + + // Mixed case. + ExpectPrevWordBreakForCache(0, "| U+4E00 'a' 'b' U+2000 'c' U+4E00"); + ExpectPrevWordBreakForCache(1, "| U+4E00 'a' 'b' U+2000 'c' U+4E00"); + ExpectPrevWordBreakForCache(2, "| U+4E00 'a' 'b' U+2000 'c' U+4E00"); + ExpectPrevWordBreakForCache(3, "| U+4E00 'a' 'b' U+2000 'c' U+4E00"); + ExpectPrevWordBreakForCache(4, "U+4E00 'a' 'b' | U+2000 'c' U+4E00"); + ExpectPrevWordBreakForCache(5, "U+4E00 'a' 'b' U+2000 | 'c' U+4E00"); + ExpectPrevWordBreakForCache(6, "U+4E00 'a' 'b' U+2000 'c' | U+4E00"); + ExpectPrevWordBreakForCache(1000, "U+4E00 'a' 'b' U+2000 'c' | U+4E00"); + + // Continue if trailing characters is Unicode combining characters. + ExpectPrevWordBreakForCache(0, "| U+4E00 U+0332 U+4E00"); + ExpectPrevWordBreakForCache(1, "| U+4E00 U+0332 U+4E00"); + ExpectPrevWordBreakForCache(2, "| U+4E00 U+0332 U+4E00"); + ExpectPrevWordBreakForCache(3, "U+4E00 U+0332 | U+4E00"); + ExpectPrevWordBreakForCache(1000, "U+4E00 U+0332 | U+4E00"); + + // Surrogate pairs. + ExpectPrevWordBreakForCache(0, "| U+1F60D U+1F618"); + ExpectPrevWordBreakForCache(1, "| U+1F60D U+1F618"); + ExpectPrevWordBreakForCache(2, "| U+1F60D U+1F618"); + ExpectPrevWordBreakForCache(3, "| U+1F60D U+1F618"); + ExpectPrevWordBreakForCache(4, "| U+1F60D U+1F618"); + ExpectPrevWordBreakForCache(1000, "| U+1F60D U+1F618"); + + // Broken surrogate pairs. + // U+D84D is leading surrogate but there is no trailing surrogate for it. + ExpectPrevWordBreakForCache(0, "| U+D84D U+1F618"); + ExpectPrevWordBreakForCache(1, "| U+D84D U+1F618"); + ExpectPrevWordBreakForCache(2, "| U+D84D U+1F618"); + ExpectPrevWordBreakForCache(3, "| U+D84D U+1F618"); + ExpectPrevWordBreakForCache(1000, "| U+D84D U+1F618"); + + ExpectPrevWordBreakForCache(0, "| U+1F618 U+D84D"); + ExpectPrevWordBreakForCache(1, "| U+1F618 U+D84D"); + ExpectPrevWordBreakForCache(2, "| U+1F618 U+D84D"); + ExpectPrevWordBreakForCache(3, "| U+1F618 U+D84D"); + ExpectPrevWordBreakForCache(1000, "| U+1F618 U+D84D"); + + // U+DE0D is trailing surrogate but there is no leading surrogate for it. + ExpectPrevWordBreakForCache(0, "| U+DE0D U+1F618"); + ExpectPrevWordBreakForCache(1, "| U+DE0D U+1F618"); + ExpectPrevWordBreakForCache(2, "| U+DE0D U+1F618"); + ExpectPrevWordBreakForCache(3, "| U+DE0D U+1F618"); + ExpectPrevWordBreakForCache(1000, "| U+DE0D U+1F618"); + + ExpectPrevWordBreakForCache(0, "| U+1F618 U+DE0D"); + ExpectPrevWordBreakForCache(1, "| U+1F618 U+DE0D"); + ExpectPrevWordBreakForCache(2, "| U+1F618 U+DE0D"); + ExpectPrevWordBreakForCache(3, "| U+1F618 U+DE0D"); + ExpectPrevWordBreakForCache(1000, "| U+1F618 U+DE0D"); + + // Regional indicator pair. U+1F1FA U+1F1F8 is US national flag. + ExpectPrevWordBreakForCache(0, "| U+1F1FA U+1F1F8"); + ExpectPrevWordBreakForCache(1, "| U+1F1FA U+1F1F8"); + ExpectPrevWordBreakForCache(2, "| U+1F1FA U+1F1F8"); + ExpectPrevWordBreakForCache(1000, "| U+1F1FA U+1F1F8"); + + // Tone marks. + // CJK ideographic char + Tone mark + CJK ideographic char + ExpectPrevWordBreakForCache(0, "| U+4444 U+302D U+4444"); + ExpectPrevWordBreakForCache(1, "| U+4444 U+302D U+4444"); + ExpectPrevWordBreakForCache(2, "| U+4444 U+302D U+4444"); + ExpectPrevWordBreakForCache(3, "U+4444 U+302D | U+4444"); + ExpectPrevWordBreakForCache(1000, "U+4444 U+302D | U+4444"); + + // Variation Selectors. + // CJK Ideographic char + Variation Selector(VS1) + CJK Ideographic char + ExpectPrevWordBreakForCache(0, "| U+845B U+FE00 U+845B"); + ExpectPrevWordBreakForCache(1, "| U+845B U+FE00 U+845B"); + ExpectPrevWordBreakForCache(2, "| U+845B U+FE00 U+845B"); + ExpectPrevWordBreakForCache(3, "U+845B U+FE00 | U+845B"); + ExpectPrevWordBreakForCache(1000, "U+845B U+FE00 | U+845B"); + + // CJK Ideographic char + Variation Selector(VS17) + CJK Ideographic char + ExpectPrevWordBreakForCache(0, "| U+845B U+E0100 U+845B"); + ExpectPrevWordBreakForCache(1, "| U+845B U+E0100 U+845B"); + ExpectPrevWordBreakForCache(2, "| U+845B U+E0100 U+845B"); + ExpectPrevWordBreakForCache(3, "| U+845B U+E0100 U+845B"); + ExpectPrevWordBreakForCache(4, "U+845B U+E0100 | U+845B"); + ExpectPrevWordBreakForCache(5, "U+845B U+E0100 | U+845B"); + ExpectPrevWordBreakForCache(1000, "U+845B U+E0100 | U+845B"); + + // CJK ideographic char + Tone mark + Variation Character(VS1) + ExpectPrevWordBreakForCache(0, "| U+4444 U+302D U+FE00 U+4444"); + ExpectPrevWordBreakForCache(1, "| U+4444 U+302D U+FE00 U+4444"); + ExpectPrevWordBreakForCache(2, "| U+4444 U+302D U+FE00 U+4444"); + ExpectPrevWordBreakForCache(3, "| U+4444 U+302D U+FE00 U+4444"); + ExpectPrevWordBreakForCache(4, "U+4444 U+302D U+FE00 | U+4444"); + ExpectPrevWordBreakForCache(1000, "U+4444 U+302D U+FE00 | U+4444"); + + // CJK ideographic char + Tone mark + Variation Character(VS17) + ExpectPrevWordBreakForCache(0, "| U+4444 U+302D U+E0100 U+4444"); + ExpectPrevWordBreakForCache(1, "| U+4444 U+302D U+E0100 U+4444"); + ExpectPrevWordBreakForCache(2, "| U+4444 U+302D U+E0100 U+4444"); + ExpectPrevWordBreakForCache(3, "| U+4444 U+302D U+E0100 U+4444"); + ExpectPrevWordBreakForCache(4, "| U+4444 U+302D U+E0100 U+4444"); + ExpectPrevWordBreakForCache(5, "U+4444 U+302D U+E0100 | U+4444"); + ExpectPrevWordBreakForCache(1000, "U+4444 U+302D U+E0100 | U+4444"); + + // CJK ideographic char + Variation Character(VS1) + Tone mark + ExpectPrevWordBreakForCache(0, "| U+4444 U+FE00 U+302D U+4444"); + ExpectPrevWordBreakForCache(1, "| U+4444 U+FE00 U+302D U+4444"); + ExpectPrevWordBreakForCache(2, "| U+4444 U+FE00 U+302D U+4444"); + ExpectPrevWordBreakForCache(3, "| U+4444 U+FE00 U+302D U+4444"); + ExpectPrevWordBreakForCache(4, "U+4444 U+FE00 U+302D | U+4444"); + ExpectPrevWordBreakForCache(1000, "U+4444 U+FE00 U+302D | U+4444"); + + // CJK ideographic char + Variation Character(VS17) + Tone mark + ExpectPrevWordBreakForCache(0, "| U+4444 U+E0100 U+302D U+4444"); + ExpectPrevWordBreakForCache(1, "| U+4444 U+E0100 U+302D U+4444"); + ExpectPrevWordBreakForCache(2, "| U+4444 U+E0100 U+302D U+4444"); + ExpectPrevWordBreakForCache(3, "| U+4444 U+E0100 U+302D U+4444"); + ExpectPrevWordBreakForCache(4, "| U+4444 U+E0100 U+302D U+4444"); + ExpectPrevWordBreakForCache(5, "U+4444 U+E0100 U+302D | U+4444"); + ExpectPrevWordBreakForCache(1000, "U+4444 U+E0100 U+302D | U+4444"); + + // Following test cases are unusual usage of variation selectors and tone + // marks for caching up the further behavior changes, e.g. index of bounds + // or crashes. Please feel free to update the test expectations if the + // behavior change makes sense to you. + + // Isolated Tone marks and Variation Selectors + ExpectPrevWordBreakForCache(0, "| U+FE00"); + ExpectPrevWordBreakForCache(1, "| U+FE00"); + ExpectPrevWordBreakForCache(1000, "| U+FE00"); + ExpectPrevWordBreakForCache(0, "| U+E0100"); + ExpectPrevWordBreakForCache(1000, "| U+E0100"); + ExpectPrevWordBreakForCache(0, "| U+302D"); + ExpectPrevWordBreakForCache(1000, "| U+302D"); + + // CJK Ideographic char + Variation Selector(VS1) + Variation Selector(VS1) + ExpectPrevWordBreakForCache(0, "| U+845B U+FE00 U+FE00 U+845B"); + ExpectPrevWordBreakForCache(1, "| U+845B U+FE00 U+FE00 U+845B"); + ExpectPrevWordBreakForCache(2, "| U+845B U+FE00 U+FE00 U+845B"); + ExpectPrevWordBreakForCache(3, "| U+845B U+FE00 U+FE00 U+845B"); + ExpectPrevWordBreakForCache(4, "U+845B U+FE00 U+FE00 | U+845B"); + ExpectPrevWordBreakForCache(1000, "U+845B U+FE00 U+FE00 | U+845B"); + + // CJK Ideographic char + Variation Selector(VS17) + Variation Selector(VS17) + ExpectPrevWordBreakForCache(0, "| U+845B U+E0100 U+E0100 U+845B"); + ExpectPrevWordBreakForCache(1, "| U+845B U+E0100 U+E0100 U+845B"); + ExpectPrevWordBreakForCache(2, "| U+845B U+E0100 U+E0100 U+845B"); + ExpectPrevWordBreakForCache(3, "| U+845B U+E0100 U+E0100 U+845B"); + ExpectPrevWordBreakForCache(4, "| U+845B U+E0100 U+E0100 U+845B"); + ExpectPrevWordBreakForCache(5, "| U+845B U+E0100 U+E0100 U+845B"); + ExpectPrevWordBreakForCache(6, "U+845B U+E0100 U+E0100 | U+845B"); + ExpectPrevWordBreakForCache(1000, + "U+845B U+E0100 U+E0100 | U+845B"); + + // CJK Ideographic char + Variation Selector(VS1) + Variation Selector(VS17) + ExpectPrevWordBreakForCache(0, "| U+845B U+FE00 U+E0100 U+845B"); + ExpectPrevWordBreakForCache(1, "| U+845B U+FE00 U+E0100 U+845B"); + ExpectPrevWordBreakForCache(2, "| U+845B U+FE00 U+E0100 U+845B"); + ExpectPrevWordBreakForCache(3, "| U+845B U+FE00 U+E0100 U+845B"); + ExpectPrevWordBreakForCache(4, "| U+845B U+FE00 U+E0100 U+845B"); + ExpectPrevWordBreakForCache(5, "U+845B U+FE00 U+E0100 | U+845B"); + ExpectPrevWordBreakForCache(1000, "U+845B U+FE00 U+E0100 | U+845B"); + + // CJK Ideographic char + Variation Selector(VS17) + Variation Selector(VS1) + ExpectPrevWordBreakForCache(0, "| U+845B U+E0100 U+FE00 U+845B"); + ExpectPrevWordBreakForCache(1, "| U+845B U+E0100 U+FE00 U+845B"); + ExpectPrevWordBreakForCache(2, "| U+845B U+E0100 U+FE00 U+845B"); + ExpectPrevWordBreakForCache(3, "| U+845B U+E0100 U+FE00 U+845B"); + ExpectPrevWordBreakForCache(4, "| U+845B U+E0100 U+FE00 U+845B"); + ExpectPrevWordBreakForCache(5, "U+845B U+E0100 U+FE00 | U+845B"); + ExpectPrevWordBreakForCache(1000, "U+845B U+E0100 U+FE00 | U+845B"); + + // Tone mark. + Tone mark + ExpectPrevWordBreakForCache(0, "| U+4444 U+302D U+302D U+4444"); + ExpectPrevWordBreakForCache(1, "| U+4444 U+302D U+302D U+4444"); + ExpectPrevWordBreakForCache(2, "| U+4444 U+302D U+302D U+4444"); + ExpectPrevWordBreakForCache(3, "| U+4444 U+302D U+302D U+4444"); + ExpectPrevWordBreakForCache(4, "U+4444 U+302D U+302D | U+4444"); + ExpectPrevWordBreakForCache(1000, "U+4444 U+302D U+302D | U+4444"); +} + +} // namespace From 0345da636e985fd6975642099cb7ba4b05b4e3a6 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 1 Sep 2015 15:16:19 +0900 Subject: [PATCH 102/364] Resolve glyph ID by HarfBuzz function. Currently codepoint to glyph ID resolution is done through MinikinFont interface. To support variation selector, use HarfBuzz API instead of calling this interface since one of its implementation Skia doesn't support variation selector. On the other hand, we don't want to get glyph horizontal advance values by HarfBuzz since HarfBuzz doesn't return correct values when the hinting is active. Thus, use ot_font as a parent font and override glyph_h_advance/glyph_h_origin functions as is. With this change, MinikinFont::GetGlyph is no longer necessary but not removing in this CL for easy reverting since removing interface requires multi-repository commit. This is a base work of b/11256006 and this patch doesn't provide any user visible changes. Bug: 11256006 Change-Id: I061172c0b674bb649ce8bc013ffecf38708bdc41 --- engine/src/flutter/libs/minikin/Layout.cpp | 24 +++++++++------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index b995a144cf1..eaa2b7d2e10 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -32,6 +32,7 @@ #include #include +#include #include "LayoutUtils.h" #include "MinikinInternal.h" @@ -314,18 +315,6 @@ hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { HB_MEMORY_MODE_WRITABLE, buffer, free); } -static hb_bool_t harfbuzzGetGlyph(hb_font_t* hbFont, void* fontData, hb_codepoint_t unicode, hb_codepoint_t variationSelector, hb_codepoint_t* glyph, void* userData) -{ - MinikinPaint* paint = reinterpret_cast(fontData); - MinikinFont* font = paint->font; - uint32_t glyph_id; - bool ok = font->GetGlyph(unicode, &glyph_id); - if (ok) { - *glyph = glyph_id; - } - return ok; -} - static hb_position_t harfbuzzGetGlyphHorizontalAdvance(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, void* userData) { MinikinPaint* paint = reinterpret_cast(fontData); @@ -346,7 +335,6 @@ hb_font_funcs_t* getHbFontFuncs() { if (hbFontFuncs == 0) { hbFontFuncs = hb_font_funcs_create(); - hb_font_funcs_set_glyph_func(hbFontFuncs, harfbuzzGetGlyph, 0, 0); hb_font_funcs_set_glyph_h_advance_func(hbFontFuncs, harfbuzzGetGlyphHorizontalAdvance, 0, 0); hb_font_funcs_set_glyph_h_origin_func(hbFontFuncs, harfbuzzGetGlyphHorizontalOrigin, 0, 0); hb_font_funcs_make_immutable(hbFontFuncs); @@ -367,7 +355,15 @@ static hb_face_t* getHbFace(MinikinFont* minikinFont) { static hb_font_t* create_hb_font(MinikinFont* minikinFont, MinikinPaint* minikinPaint) { hb_face_t* face = getHbFace(minikinFont); - hb_font_t* font = hb_font_create(face); + hb_font_t* parent_font = hb_font_create(face); + hb_ot_font_set_funcs(parent_font); + + unsigned int upem = hb_face_get_upem(face); + hb_font_set_scale(parent_font, upem, upem); + + hb_font_t* font = hb_font_create_sub_font(parent_font); + hb_font_destroy(parent_font); + hb_font_set_funcs(font, getHbFontFuncs(), minikinPaint, 0); return font; } From 5debe07231d79a17821af4ded508970398b65c0e Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 16 Sep 2015 20:31:35 +0900 Subject: [PATCH 103/364] Introduce unit tests for FontCollection::itemize. Introduced tests depend on installed font list in running device. I verified these test passed on Nexus 5(hammerhead), Nexus 6(shamu) and Nexus 9(volantis). Bug: 11256006 Bug: 17759267 Change-Id: I6f806370e17f6c6d3dad8df0cb70bb475a827873 --- engine/src/flutter/tests/Android.mk | 20 +- .../tests/FontCollectionItemizeTest.cpp | 343 ++++++++++++++++++ engine/src/flutter/tests/FontTestUtils.cpp | 81 +++++ engine/src/flutter/tests/FontTestUtils.h | 30 ++ .../src/flutter/tests/MinikinFontForTest.cpp | 62 ++++ engine/src/flutter/tests/MinikinFontForTest.h | 38 ++ 6 files changed, 569 insertions(+), 5 deletions(-) create mode 100644 engine/src/flutter/tests/FontCollectionItemizeTest.cpp create mode 100644 engine/src/flutter/tests/FontTestUtils.cpp create mode 100644 engine/src/flutter/tests/FontTestUtils.h create mode 100644 engine/src/flutter/tests/MinikinFontForTest.cpp create mode 100644 engine/src/flutter/tests/MinikinFontForTest.h diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index 00847e3b2a7..680cbe93498 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -27,18 +27,28 @@ LOCAL_STATIC_LIBRARIES := libminikin # pulled in by the build system (and thus sadly must be repeated). LOCAL_SHARED_LIBRARIES := \ - libharfbuzz_ng \ + libskia \ libft2 \ - liblog \ - libz \ + libharfbuzz_ng \ libicuuc \ - libutils + liblog \ + libutils \ + libz + +LOCAL_STATIC_LIBRARIES += \ + libxml2 LOCAL_SRC_FILES += \ + FontCollectionItemizeTest.cpp \ + FontTestUtils.cpp \ + MinikinFontForTest.cpp \ GraphemeBreakTests.cpp \ LayoutUtilsTest.cpp \ UnicodeUtils.cpp -LOCAL_C_INCLUDES := $(LOCAL_PATH)/../libs/minikin/ +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/../libs/minikin/ \ + external/libxml2/include \ + external/skia/src/core \ include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp new file mode 100644 index 00000000000..cabc9679848 --- /dev/null +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -0,0 +1,343 @@ +/* + * Copyright (C) 2015 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 + +#include "FontTestUtils.h" +#include "MinikinFontForTest.h" +#include "UnicodeUtils.h" + +using android::FontCollection; +using android::FontLanguage; +using android::FontStyle; + +const char kEmojiFont[] = "/system/fonts/NotoColorEmoji.ttf"; +const char kJAFont[] = "/system/fonts/NotoSansJP-Regular.otf"; +const char kKOFont[] = "/system/fonts/NotoSansKR-Regular.otf"; +const char kLatinBoldFont[] = "/system/fonts/Roboto-Bold.ttf"; +const char kLatinBoldItalicFont[] = "/system/fonts/Roboto-BoldItalic.ttf"; +const char kLatinFont[] = "/system/fonts/Roboto-Regular.ttf"; +const char kLatinItalicFont[] = "/system/fonts/Roboto-Italic.ttf"; +const char kZH_HansFont[] = "/system/fonts/NotoSansSC-Regular.otf"; +const char kZH_HantFont[] = "/system/fonts/NotoSansTC-Regular.otf"; + +// Utility function for calling itemize function. +void itemize(FontCollection* collection, const char* str, FontStyle style, + std::vector* result) { + const size_t BUF_SIZE = 256; + uint16_t buf[BUF_SIZE]; + size_t len; + + result->clear(); + ParseUnicode(buf, BUF_SIZE, str, &len, NULL); + collection->itemize(buf, len, style, result); +} + +// Utility function to obtain font path associated with run. +const std::string& getFontPath(const FontCollection::Run& run) { + return ((MinikinFontForTest*)run.fakedFont.font)->fontPath(); +} + +TEST(FontCollectionItemizeTest, itemize_latin) { + std::unique_ptr collection = getFontCollection(); + std::vector runs; + + const FontStyle kRegularStyle = FontStyle(); + const FontStyle kItalicStyle = FontStyle(4, true); + const FontStyle kBoldStyle = FontStyle(7, false); + const FontStyle kBoldItalicStyle = FontStyle(7, true); + + itemize(collection.get(), "'a' 'b' 'c' 'd' 'e'", kRegularStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + itemize(collection.get(), "'a' 'b' 'c' 'd' 'e'", kItalicStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kLatinItalicFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + itemize(collection.get(), "'a' 'b' 'c' 'd' 'e'", kBoldStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kLatinBoldFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + itemize(collection.get(), "'a' 'b' 'c' 'd' 'e'", kBoldItalicStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kLatinBoldItalicFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + // Continue if the specific characters (e.g. hyphen, comma, etc.) is + // followed. + itemize(collection.get(), "'a' ',' '-' 'd' '!'", kRegularStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + itemize(collection.get(), "'a' ',' '-' 'd' '!'", kRegularStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + // U+0301(COMBINING ACUTE ACCENT) must be in the same run with preceding + // chars if the font supports it. + itemize(collection.get(), "'a' U+0301", kRegularStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); +} + +TEST(FontCollectionItemizeTest, itemize_emoji) { + std::unique_ptr collection = getFontCollection(); + std::vector runs; + + itemize(collection.get(), "U+1F469 U+1F467", FontStyle(), &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(4, runs[0].end); + EXPECT_EQ(kEmojiFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + // U+20E3(COMBINING ENCLOSING KEYCAP) must be in the same run with preceding + // character if the font supports. + itemize(collection.get(), "'0' U+20E3", FontStyle(), &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kEmojiFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + // Currently there is no fonts which has a glyph for 'a' + U+20E3, so they + // are splitted into two. + itemize(collection.get(), "'a' U+20E3", FontStyle(), &runs); + ASSERT_EQ(2U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + EXPECT_EQ(1, runs[1].start); + EXPECT_EQ(2, runs[1].end); + EXPECT_EQ(kEmojiFont, getFontPath(runs[1])); + EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeItalic()); +} + +TEST(FontCollectionItemizeTest, itemize_non_latin) { + std::unique_ptr collection = getFontCollection(); + std::vector runs; + + FontStyle kJAStyle = FontStyle(FontLanguage("ja_JP", 5)); + FontStyle kUSStyle = FontStyle(FontLanguage("en_US", 5)); + FontStyle kZH_HansStyle = FontStyle(FontLanguage("zh_Hans", 7)); + + // All Japanese Hiragana characters. + itemize(collection.get(), "U+3042 U+3044 U+3046 U+3048 U+304A", kUSStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + // All Korean Hangul characters. + itemize(collection.get(), "U+B300 U+D55C U+BBFC U+AD6D", kUSStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(4, runs[0].end); + EXPECT_EQ(kKOFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + // All Han characters ja, zh-Hans font having. + // Japanese font should be selected if the specified language is Japanese. + itemize(collection.get(), "U+81ED U+82B1 U+5FCD", kJAStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(3, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + // Simplified Chinese font should be selected if the specified language is Simplified + // Chinese. + itemize(collection.get(), "U+81ED U+82B1 U+5FCD", kZH_HansStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(3, runs[0].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + // Fallbacks to other fonts if there is no glyph in the specified language's + // font. There is no character U+4F60 in Japanese. + itemize(collection.get(), "U+81ED U+4F60 U+5FCD", kJAStyle, &runs); + ASSERT_EQ(3U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + EXPECT_EQ(1, runs[1].start); + EXPECT_EQ(2, runs[1].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[1])); + EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeItalic()); + + EXPECT_EQ(2, runs[2].start); + EXPECT_EQ(3, runs[2].end); + EXPECT_EQ(kJAFont, getFontPath(runs[2])); + EXPECT_FALSE(runs[2].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[2].fakedFont.fakery.isFakeItalic()); + + // Tone mark. + itemize(collection.get(), "U+4444 U+302D", FontStyle(), &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); +} + +TEST(FontCollectionItemizeTest, itemize_mixed) { + std::unique_ptr collection = getFontCollection(); + std::vector runs; + + FontStyle kUSStyle = FontStyle(FontLanguage("en_US", 5)); + + itemize(collection.get(), "'a' U+4F60 'b' U+4F60 'c'", kUSStyle, &runs); + ASSERT_EQ(5U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + EXPECT_EQ(1, runs[1].start); + EXPECT_EQ(2, runs[1].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[1])); + EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeItalic()); + + EXPECT_EQ(2, runs[2].start); + EXPECT_EQ(3, runs[2].end); + EXPECT_EQ(kLatinFont, getFontPath(runs[2])); + EXPECT_FALSE(runs[2].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[2].fakedFont.fakery.isFakeItalic()); + + EXPECT_EQ(3, runs[3].start); + EXPECT_EQ(4, runs[3].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[3])); + EXPECT_FALSE(runs[3].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[3].fakedFont.fakery.isFakeItalic()); + + EXPECT_EQ(4, runs[4].start); + EXPECT_EQ(5, runs[4].end); + EXPECT_EQ(kLatinFont, getFontPath(runs[4])); + EXPECT_FALSE(runs[4].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[4].fakedFont.fakery.isFakeItalic()); +} + +TEST(FontCollectionItemizeTest, itemize_no_crash) { + std::unique_ptr collection = getFontCollection(); + std::vector runs; + + // Broken Surrogate pairs. Check only not crashing. + itemize(collection.get(), "'a' U+D83D 'a'", FontStyle(), &runs); + itemize(collection.get(), "'a' U+DC69 'a'", FontStyle(), &runs); + itemize(collection.get(), "'a' U+D83D U+D83D 'a'", FontStyle(), &runs); + itemize(collection.get(), "'a' U+DC69 U+DC69 'a'", FontStyle(), &runs); + + // Isolated variation selector. Check only not crashing. + itemize(collection.get(), "U+FE00 U+FE00", FontStyle(), &runs); + itemize(collection.get(), "U+E0100 U+E0100", FontStyle(), &runs); + itemize(collection.get(), "U+FE00 U+E0100", FontStyle(), &runs); + itemize(collection.get(), "U+E0100 U+FE00", FontStyle(), &runs); + + // Tone mark only. Check only not crashing. + itemize(collection.get(), "U+302D", FontStyle(), &runs); + itemize(collection.get(), "U+302D U+302D", FontStyle(), &runs); + + // Tone mark and variation selector mixed. Check only not crashing. + itemize(collection.get(), "U+FE00 U+302D U+E0100", FontStyle(), &runs); +} + +TEST(FontCollectionItemizeTest, itemize_fakery) { + std::unique_ptr collection = getFontCollection(); + std::vector runs; + + FontStyle kJABoldStyle = FontStyle(FontLanguage("ja_JP", 5), 0, 7, false); + FontStyle kJAItalicStyle = FontStyle(FontLanguage("ja_JP", 5), 0, 5, true); + FontStyle kJABoldItalicStyle = FontStyle(FontLanguage("ja_JP", 5), 0, 7, true); + + // Currently there is no italic or bold font for Japanese. FontFakery has + // the differences between desired and actual font style. + + // All Japanese Hiragana characters. + itemize(collection.get(), "U+3042 U+3044 U+3046 U+3048 U+304A", kJABoldStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + // All Japanese Hiragana characters. + itemize(collection.get(), "U+3042 U+3044 U+3046 U+3048 U+304A", kJAItalicStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeItalic()); + + // All Japanese Hiragana characters. + itemize(collection.get(), "U+3042 U+3044 U+3046 U+3048 U+304A", kJABoldItalicStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeItalic()); +} + +// TODO(11256006): Add Variation Selector test cases once it is supported. diff --git a/engine/src/flutter/tests/FontTestUtils.cpp b/engine/src/flutter/tests/FontTestUtils.cpp new file mode 100644 index 00000000000..e5d6c2a4481 --- /dev/null +++ b/engine/src/flutter/tests/FontTestUtils.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2015 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 + +#include +#include + +#include "MinikinFontForTest.h" + +const char kFontDir[] = "/system/fonts/"; +const char kFontXml[] = "/system/etc/fonts.xml"; + +std::unique_ptr getFontCollection() { + xmlDoc* doc = xmlReadFile(kFontXml, NULL, 0); + xmlNode* familySet = xmlDocGetRootElement(doc); + + std::vector families; + for (xmlNode* familyNode = familySet->children; familyNode; familyNode = familyNode->next) { + if (xmlStrcmp(familyNode->name, (const xmlChar*)"family") != 0) { + continue; + } + + xmlChar* variantXmlch = xmlGetProp(familyNode, (const xmlChar*)"variant"); + int variant = android::VARIANT_DEFAULT; + if (variantXmlch) { + if (xmlStrcmp(variantXmlch, (const xmlChar*)"elegant") == 0) { + variant = android::VARIANT_ELEGANT; + } else if (xmlStrcmp(variantXmlch, (const xmlChar*)"compact") == 0) { + variant = android::VARIANT_COMPACT; + } + } + + xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); + + android::FontFamily* family = new android::FontFamily( + android::FontLanguage((const char*)lang, xmlStrlen(lang)), variant); + + for (xmlNode* fontNode = familyNode->children; fontNode; fontNode = fontNode->next) { + if (xmlStrcmp(fontNode->name, (const xmlChar*)"font") != 0) { + continue; + } + + int weight = atoi((const char*)(xmlGetProp(fontNode, (const xmlChar*)"weight"))) / 100; + bool italic = xmlStrcmp( + xmlGetProp(fontNode, (const xmlChar*)"style"), (const xmlChar*)"italic") == 0; + + xmlChar* fontFileName = xmlNodeListGetString(doc, fontNode->xmlChildrenNode, 1); + std::string fontPath = kFontDir + std::string((const char*)fontFileName); + xmlFree(fontFileName); + + if (access(fontPath.c_str(), R_OK) != 0) { + // Skip not accessible fonts. + continue; + } + + family->addFont(new MinikinFontForTest(fontPath), android::FontStyle(weight, italic)); + } + families.push_back(family); + } + xmlFreeDoc(doc); + + std::unique_ptr r(new android::FontCollection(families)); + for (size_t i = 0; i < families.size(); ++i) { + families[i]->Unref(); + } + return r; +} diff --git a/engine/src/flutter/tests/FontTestUtils.h b/engine/src/flutter/tests/FontTestUtils.h new file mode 100644 index 00000000000..d53956f2d55 --- /dev/null +++ b/engine/src/flutter/tests/FontTestUtils.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2015 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_TEST_UTILS_H +#define MINIKIN_FONT_TEST_UTILS_H + +#include + +/** + * Returns FontCollection from installed fonts. + * + * This function reads /system/etc/fonts.xml and make font families and + * collections of them. MinikinFontForTest is used for FontFamily creation. + */ +std::unique_ptr getFontCollection(); + +#endif // MINIKIN_FONT_TEST_UTILS_H diff --git a/engine/src/flutter/tests/MinikinFontForTest.cpp b/engine/src/flutter/tests/MinikinFontForTest.cpp new file mode 100644 index 00000000000..2d29e805aae --- /dev/null +++ b/engine/src/flutter/tests/MinikinFontForTest.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2015 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 "MinikinFontForTest.h" + +#include + +#include + +#include + +MinikinFontForTest::MinikinFontForTest(const std::string& font_path) : mFontPath(font_path) { + mTypeface = SkTypeface::CreateFromFile(font_path.c_str()); +} + +MinikinFontForTest::~MinikinFontForTest() { +} + +bool MinikinFontForTest::GetGlyph(uint32_t codepoint, uint32_t *glyph) const { + LOG_ALWAYS_FATAL("MinikinFontForTest::GetGlyph is not yet implemented"); + return false; +} + +float MinikinFontForTest::GetHorizontalAdvance( + uint32_t glyph_id, const android::MinikinPaint &paint) const { + LOG_ALWAYS_FATAL("MinikinFontForTest::GetHorizontalAdvance is not yet implemented"); + return 0.0f; +} + +void MinikinFontForTest::GetBounds(android::MinikinRect* bounds, uint32_t glyph_id, + const android::MinikinPaint& paint) const { + LOG_ALWAYS_FATAL("MinikinFontForTest::GetBounds is not yet implemented"); +} + +bool MinikinFontForTest::GetTable(uint32_t tag, uint8_t *buf, size_t *size) { + if (buf == NULL) { + const size_t tableSize = mTypeface->getTableSize(tag); + *size = tableSize; + return tableSize != 0; + } else { + const size_t actualSize = mTypeface->getTableData(tag, 0, *size, buf); + *size = actualSize; + return actualSize != 0; + } +} + +int32_t MinikinFontForTest::GetUniqueId() const { + return mTypeface->uniqueID(); +} diff --git a/engine/src/flutter/tests/MinikinFontForTest.h b/engine/src/flutter/tests/MinikinFontForTest.h new file mode 100644 index 00000000000..ecebb7e2b81 --- /dev/null +++ b/engine/src/flutter/tests/MinikinFontForTest.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2015 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 + +class SkTypeface; + +class MinikinFontForTest : public android::MinikinFont { +public: + explicit MinikinFontForTest(const std::string& font_path); + ~MinikinFontForTest(); + + // MinikinFont overrides. + bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const; + float GetHorizontalAdvance(uint32_t glyph_id, const android::MinikinPaint &paint) const; + void GetBounds(android::MinikinRect* bounds, uint32_t glyph_id, + const android::MinikinPaint& paint) const; + bool GetTable(uint32_t tag, uint8_t *buf, size_t *size); + int32_t GetUniqueId() const; + + const std::string& fontPath() const { return mFontPath; } +private: + SkTypeface *mTypeface; + const std::string mFontPath; +}; From f6aa09df276fbf0fef6381fa61318ab84c71d1af Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Wed, 23 Sep 2015 16:27:07 -0700 Subject: [PATCH 104/364] Refactoring: Introduce helper class to iterate runs. This doesn't change current behavior. It's a preparation for the following CLs. Bug: 22408712 Change-Id: Ic018422254aa3904655f499194caad74f0c0fc5d --- engine/src/flutter/include/minikin/Layout.h | 2 +- engine/src/flutter/libs/minikin/Layout.cpp | 199 ++++++++++++++------ 2 files changed, 146 insertions(+), 55 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index cdf4aac5236..83eb963b717 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -129,7 +129,7 @@ private: int findFace(FakedFont face, LayoutContext* ctx); // Lay out a single bidi run - void doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + void doLayoutRunCached(const uint16_t* buf, size_t runStart, size_t runLength, size_t bufSize, bool isRtl, LayoutContext* ctx, size_t dstStart); // Lay out a single word diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index eaa2b7d2e10..8b5a47b0488 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -488,6 +488,148 @@ static bool isScriptOkForLetterspacing(hb_script_t script) { ); } +class BidiText { +public: + class Iter { + public: + struct RunInfo { + int32_t mRunStart; + int32_t mRunLength; + bool mIsRtl; + }; + + Iter(UBiDi* bidi, size_t start, size_t end, size_t runIndex, size_t runCount, bool isRtl); + + bool operator!= (const Iter& other) const { + return mIsEnd != other.mIsEnd || mNextRunIndex != other.mNextRunIndex + || mBidi != other.mBidi; + } + + const RunInfo& operator* () const { + return mRunInfo; + } + + const Iter& operator++ () { + updateRunInfo(); + return *this; + } + + private: + UBiDi* const mBidi; + bool mIsEnd; + size_t mNextRunIndex; + const size_t mRunCount; + const int32_t mStart; + const int32_t mEnd; + RunInfo mRunInfo; + + void updateRunInfo(); + }; + + BidiText(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags); + + ~BidiText() { + if (mBidi) { + ubidi_close(mBidi); + } + } + + Iter begin () const { + return Iter(mBidi, mStart, mEnd, 0, mRunCount, mIsRtl); + } + + Iter end() const { + return Iter(mBidi, mStart, mEnd, mRunCount, mRunCount, mIsRtl); + } + +private: + const size_t mStart; + const size_t mEnd; + const size_t mBufSize; + UBiDi* mBidi; + size_t mRunCount; + bool mIsRtl; + + DISALLOW_COPY_AND_ASSIGN(BidiText); +}; + +BidiText::Iter::Iter(UBiDi* bidi, size_t start, size_t end, size_t runIndex, size_t runCount, + bool isRtl) + : mBidi(bidi), mIsEnd(runIndex == runCount), mNextRunIndex(runIndex), mRunCount(runCount), + mStart(start), mEnd(end), mRunInfo() { + if (mRunCount == 1) { + mRunInfo.mRunStart = start; + mRunInfo.mRunLength = end - start; + mRunInfo.mIsRtl = isRtl; + mNextRunIndex = mRunCount; + return; + } + updateRunInfo(); +} + +void BidiText::Iter::updateRunInfo() { + if (mNextRunIndex == mRunCount) { + // All runs have been iterated. + mIsEnd = true; + return; + } + int32_t startRun = -1; + int32_t lengthRun = -1; + const UBiDiDirection runDir = ubidi_getVisualRun(mBidi, mNextRunIndex, &startRun, &lengthRun); + mNextRunIndex++; + if (startRun == -1 || lengthRun == -1) { + ALOGE("invalid visual run"); + // skip the invalid run. + updateRunInfo(); + return; + } + const int32_t runEnd = std::min(startRun + lengthRun, mEnd); + mRunInfo.mRunStart = std::max(startRun, mStart); + mRunInfo.mRunLength = runEnd - mRunInfo.mRunStart; + if (mRunInfo.mRunLength <= 0) { + // skip the empty run. + updateRunInfo(); + return; + } + mRunInfo.mIsRtl = (runDir == UBIDI_RTL); +} + +BidiText::BidiText(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags) + : mStart(start), mEnd(start + count), mBufSize(bufSize), mBidi(NULL), mRunCount(1), + mIsRtl((bidiFlags & kDirection_Mask) != 0) { + if (bidiFlags == kBidi_Force_LTR || bidiFlags == kBidi_Force_RTL) { + // force single run. + return; + } + mBidi = ubidi_open(); + if (!mBidi) { + ALOGE("error creating bidi object"); + return; + } + UErrorCode status = U_ZERO_ERROR; + UBiDiLevel bidiReq = bidiFlags; + if (bidiFlags == kBidi_Default_LTR) { + bidiReq = UBIDI_DEFAULT_LTR; + } else if (bidiFlags == kBidi_Default_RTL) { + bidiReq = UBIDI_DEFAULT_RTL; + } + ubidi_setPara(mBidi, buf, mBufSize, bidiReq, NULL, &status); + if (!U_SUCCESS(status)) { + ALOGE("error calling ubidi_setPara, status = %d", status); + return; + } + const int paraDir = ubidi_getParaLevel(mBidi) & kDirection_Mask; + const ssize_t rc = ubidi_countRuns(mBidi, &status); + if (!U_SUCCESS(status) || rc < 0) { + ALOGW("error counting bidi runs, status = %d", status); + } + if (!U_SUCCESS(status) || rc <= 1) { + mIsRtl = (paraDir == kBidi_RTL); + return; + } + mRunCount = rc; +} + void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint) { AutoMutex _l(gMinikinLock); @@ -496,63 +638,12 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu ctx.style = style; ctx.paint = paint; - bool isRtl = (bidiFlags & kDirection_Mask) != 0; - bool doSingleRun = true; - reset(); mAdvances.resize(count, 0); - if (!(bidiFlags == kBidi_Force_LTR || bidiFlags == kBidi_Force_RTL)) { - UBiDi* bidi = ubidi_open(); - if (bidi) { - UErrorCode status = U_ZERO_ERROR; - UBiDiLevel bidiReq = bidiFlags; - if (bidiFlags == kBidi_Default_LTR) { - bidiReq = UBIDI_DEFAULT_LTR; - } else if (bidiFlags == kBidi_Default_RTL) { - bidiReq = UBIDI_DEFAULT_RTL; - } - ubidi_setPara(bidi, buf, bufSize, bidiReq, NULL, &status); - if (U_SUCCESS(status)) { - int paraDir = ubidi_getParaLevel(bidi) & kDirection_Mask; - ssize_t rc = ubidi_countRuns(bidi, &status); - if (!U_SUCCESS(status) || rc < 0) { - ALOGW("error counting bidi runs, status = %d", status); - } - if (!U_SUCCESS(status) || rc <= 1) { - isRtl = (paraDir == kBidi_RTL); - } else { - doSingleRun = false; - // iterate through runs - for (ssize_t i = 0; i < (ssize_t)rc; i++) { - int32_t startRun = -1; - int32_t lengthRun = -1; - UBiDiDirection runDir = ubidi_getVisualRun(bidi, i, &startRun, &lengthRun); - if (startRun == -1 || lengthRun == -1) { - ALOGE("invalid visual run"); - // skip the invalid run - continue; - } - int32_t endRun = std::min(startRun + lengthRun, int32_t(start + count)); - startRun = std::max(startRun, int32_t(start)); - lengthRun = endRun - startRun; - if (lengthRun > 0) { - isRtl = (runDir == UBIDI_RTL); - doLayoutRunCached(buf, startRun, lengthRun, bufSize, isRtl, &ctx, - start); - } - } - } - } else { - ALOGE("error calling ubidi_setPara, status = %d", status); - } - ubidi_close(bidi); - } else { - ALOGE("error creating bidi object"); - } - } - if (doSingleRun) { - doLayoutRunCached(buf, start, count, bufSize, isRtl, &ctx, start); + for (const BidiText::Iter::RunInfo& runInfo : BidiText(buf, start, count, bufSize, bidiFlags)) { + doLayoutRunCached(buf, runInfo.mRunStart, runInfo.mRunLength, bufSize, runInfo.mIsRtl, &ctx, + start); } ctx.clearHbFonts(); } From 52dfb07bdec36b58a91a2f38b87c2eb111e299e3 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 17 Sep 2015 17:12:13 +0900 Subject: [PATCH 105/364] Extract hb_face_t object cache mechanism from Layout.cpp. This CL does following things: - Extract hb_face_t object cache mechanism from Layout.cpp to be able to use it from other cpp file, especially from FontFamily.cpp. To address Bug 11256006 and Bug 17759267, need to touch hb_face_t from FontFamily. - Make hb_face_t cache mechanism thread-safe. - Add unit tests for HbFaceCache test cases. Bug: 11256006 Bug: 17759267 Change-Id: Ic183634ef34326793bd9a32167236611d0af34d6 --- engine/src/flutter/libs/minikin/Android.mk | 1 + .../src/flutter/libs/minikin/HbFaceCache.cpp | 119 +++++++++++++++++ engine/src/flutter/libs/minikin/HbFaceCache.h | 29 +++++ engine/src/flutter/libs/minikin/Layout.cpp | 58 +-------- .../flutter/libs/minikin/MinikinInternal.cpp | 6 + .../flutter/libs/minikin/MinikinInternal.h | 3 + engine/src/flutter/tests/Android.mk | 4 +- engine/src/flutter/tests/HbFaceCacheTest.cpp | 123 ++++++++++++++++++ 8 files changed, 287 insertions(+), 56 deletions(-) create mode 100644 engine/src/flutter/libs/minikin/HbFaceCache.cpp create mode 100644 engine/src/flutter/libs/minikin/HbFaceCache.h create mode 100644 engine/src/flutter/tests/HbFaceCacheTest.cpp diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 765a3ddfd75..fab5586e379 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -22,6 +22,7 @@ minikin_src_files := \ FontCollection.cpp \ FontFamily.cpp \ GraphemeBreak.cpp \ + HbFaceCache.cpp \ Hyphenator.cpp \ Layout.cpp \ LayoutUtils.cpp \ diff --git a/engine/src/flutter/libs/minikin/HbFaceCache.cpp b/engine/src/flutter/libs/minikin/HbFaceCache.cpp new file mode 100644 index 00000000000..fde2fa869f2 --- /dev/null +++ b/engine/src/flutter/libs/minikin/HbFaceCache.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2015 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. + */ + +#define LOG_TAG "Minikin" + +#include "HbFaceCache.h" + +#include +#include + +#include +#include "MinikinInternal.h" + +namespace android { + +static hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { + MinikinFont* font = reinterpret_cast(userData); + size_t length = 0; + bool ok = font->GetTable(tag, NULL, &length); + if (!ok) { + return 0; + } + char* buffer = reinterpret_cast(malloc(length)); + if (!buffer) { + return 0; + } + ok = font->GetTable(tag, reinterpret_cast(buffer), &length); +#ifdef VERBOSE_DEBUG + ALOGD("referenceTable %c%c%c%c length=%d %d", + (tag >>24)&0xff, (tag>>16)&0xff, (tag>>8)&0xff, tag&0xff, length, ok); +#endif + if (!ok) { + free(buffer); + return 0; + } + return hb_blob_create(const_cast(buffer), length, + HB_MEMORY_MODE_WRITABLE, buffer, free); +} + +static unsigned int disabledDecomposeCompatibility( + hb_unicode_funcs_t*, hb_codepoint_t, hb_codepoint_t*, void*) { + return 0; +} + +class HbFaceCache : private OnEntryRemoved { +public: + HbFaceCache() : mCache(kMaxEntries) { + mCache.setOnEntryRemovedListener(this); + } + + // callback for OnEntryRemoved + void operator()(int32_t& key, hb_face_t*& value) { + hb_face_destroy(value); + } + + hb_face_t* get(int32_t fontId) { + return mCache.get(fontId); + } + + void put(int32_t fontId, hb_face_t* face) { + mCache.put(fontId, face); + } + + void clear() { + mCache.clear(); + } + +private: + static const size_t kMaxEntries = 100; + + LruCache mCache; +}; + +HbFaceCache* getFaceCacheLocked() { + assertMinikinLocked(); + static HbFaceCache* cache = nullptr; + if (cache == nullptr) { + cache = new HbFaceCache(); + } + return cache; +} + +void purgeHbFaceCacheLocked() { + assertMinikinLocked(); + getFaceCacheLocked()->clear(); +} + +hb_face_t* getHbFaceLocked(MinikinFont* minikinFont) { + assertMinikinLocked(); + if (minikinFont == nullptr) { + return nullptr; + } + + HbFaceCache* faceCache = getFaceCacheLocked(); + const int32_t fontId = minikinFont->GetUniqueId(); + hb_face_t* face = faceCache->get(fontId); + if (face != nullptr) { + return face; + } + + face = hb_face_create_for_tables(referenceTable, minikinFont, nullptr); + faceCache->put(fontId, face); + return face; +} + +} // namespace android diff --git a/engine/src/flutter/libs/minikin/HbFaceCache.h b/engine/src/flutter/libs/minikin/HbFaceCache.h new file mode 100644 index 00000000000..8ee38c3603e --- /dev/null +++ b/engine/src/flutter/libs/minikin/HbFaceCache.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2015 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_HBFACE_CACHE_H +#define MINIKIN_HBFACE_CACHE_H + +struct hb_face_t; + +namespace android { +class MinikinFont; + +void purgeHbFaceCacheLocked(); +hb_face_t* getHbFaceLocked(MinikinFont* minikinFont); + +} // namespace android +#endif // MINIKIN_HBFACE_CACHE_H diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index eaa2b7d2e10..65a8a7520b9 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -35,6 +35,7 @@ #include #include "LayoutUtils.h" +#include "HbFaceCache.h" #include "MinikinInternal.h" #include #include @@ -188,22 +189,6 @@ private: static const size_t kMaxEntries = 5000; }; -class HbFaceCache : private OnEntryRemoved { -public: - HbFaceCache() : mCache(kMaxEntries) { - mCache.setOnEntryRemovedListener(this); - } - - // callback for OnEntryRemoved - void operator()(int32_t& key, hb_face_t*& value) { - hb_face_destroy(value); - } - - LruCache mCache; -private: - static const size_t kMaxEntries = 100; -}; - static unsigned int disabledDecomposeCompatibility(hb_unicode_funcs_t*, hb_codepoint_t, hb_codepoint_t*, void*) { return 0; @@ -223,7 +208,6 @@ public: hb_buffer_t* hbBuffer; hb_unicode_funcs_t* unicodeFunctions; LayoutCache layoutCache; - HbFaceCache hbFaceCache; }; ANDROID_SINGLETON_STATIC_INSTANCE(LayoutEngine); @@ -291,30 +275,6 @@ void Layout::setFontCollection(const FontCollection* collection) { mCollection = collection; } -hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { - MinikinFont* font = reinterpret_cast(userData); - size_t length = 0; - bool ok = font->GetTable(tag, NULL, &length); - if (!ok) { - return 0; - } - char* buffer = reinterpret_cast(malloc(length)); - if (!buffer) { - return 0; - } - ok = font->GetTable(tag, reinterpret_cast(buffer), &length); -#ifdef VERBOSE_DEBUG - ALOGD("referenceTable %c%c%c%c length=%d %d", - (tag >>24) & 0xff, (tag>>16)&0xff, (tag>>8)&0xff, tag&0xff, length, ok); -#endif - if (!ok) { - free(buffer); - return 0; - } - return hb_blob_create(const_cast(buffer), length, - HB_MEMORY_MODE_WRITABLE, buffer, free); -} - static hb_position_t harfbuzzGetGlyphHorizontalAdvance(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, void* userData) { MinikinPaint* paint = reinterpret_cast(fontData); @@ -342,19 +302,8 @@ hb_font_funcs_t* getHbFontFuncs() { return hbFontFuncs; } -static hb_face_t* getHbFace(MinikinFont* minikinFont) { - HbFaceCache& cache = LayoutEngine::getInstance().hbFaceCache; - int32_t fontId = minikinFont->GetUniqueId(); - hb_face_t* face = cache.mCache.get(fontId); - if (face == NULL) { - face = hb_face_create_for_tables(referenceTable, minikinFont, NULL); - cache.mCache.put(fontId, face); - } - return face; -} - static hb_font_t* create_hb_font(MinikinFont* minikinFont, MinikinPaint* minikinPaint) { - hb_face_t* face = getHbFace(minikinFont); + hb_face_t* face = getHbFaceLocked(minikinFont); hb_font_t* parent_font = hb_font_create(face); hb_ot_font_set_funcs(parent_font); @@ -885,8 +834,7 @@ void Layout::purgeCaches() { AutoMutex _l(gMinikinLock); LayoutCache& layoutCache = LayoutEngine::getInstance().layoutCache; layoutCache.clear(); - HbFaceCache& hbCache = LayoutEngine::getInstance().hbFaceCache; - hbCache.mCache.clear(); + purgeHbFaceCacheLocked(); } } // namespace android diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index 71c8649b1e3..5a21ef9862c 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -18,8 +18,14 @@ #include "MinikinInternal.h" +#include + namespace android { Mutex gMinikinLock; +void assertMinikinLocked() { + LOG_FATAL_IF(gMinikinLock.tryLock() == 0); +} + } diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.h b/engine/src/flutter/libs/minikin/MinikinInternal.h index b8430df550b..34a95bb3d12 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.h +++ b/engine/src/flutter/libs/minikin/MinikinInternal.h @@ -29,6 +29,9 @@ namespace android { extern Mutex gMinikinLock; +// Aborts if gMinikinLock is not acquired. Do nothing on the release build. +void assertMinikinLocked(); + } #endif // MINIKIN_INTERNAL_H diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index 680cbe93498..b4d5e91bc34 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -43,12 +43,14 @@ LOCAL_SRC_FILES += \ FontTestUtils.cpp \ MinikinFontForTest.cpp \ GraphemeBreakTests.cpp \ + HbFaceCacheTest.cpp \ LayoutUtilsTest.cpp \ UnicodeUtils.cpp LOCAL_C_INCLUDES := \ $(LOCAL_PATH)/../libs/minikin/ \ + external/harfbuzz_ng/src \ external/libxml2/include \ - external/skia/src/core \ + external/skia/src/core include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/HbFaceCacheTest.cpp b/engine/src/flutter/tests/HbFaceCacheTest.cpp new file mode 100644 index 00000000000..1b630738516 --- /dev/null +++ b/engine/src/flutter/tests/HbFaceCacheTest.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2015 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 + +#include "HbFaceCache.h" + +#include +#include +#include + +#include "MinikinInternal.h" +#include + +namespace android { +namespace { + +// A mock implementation of MinikinFont. The passed integer value will be +// returned in GetUniqueId(). +class MockMinikinFont : public MinikinFont { +public: + MockMinikinFont(int32_t id) : mId(id) { + } + + virtual bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const { + LOG_ALWAYS_FATAL("MockMinikinFont::GetGlyph is not implemented."); + return false; + } + + virtual float GetHorizontalAdvance( + uint32_t glyph_id, const MinikinPaint &paint) const { + LOG_ALWAYS_FATAL("MockMinikinFont::GetHorizontalAdvance is not implemented."); + return 0.0f; + } + + virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id, + const MinikinPaint &paint) const { + LOG_ALWAYS_FATAL("MockMinikinFont::GetBounds is not implemented."); + } + + virtual bool GetTable(uint32_t tag, uint8_t *buf, size_t *size) { + LOG_ALWAYS_FATAL("MockMinikinFont::GetTable is not implemented."); + return false; + } + + virtual int32_t GetUniqueId() const { + return mId; + } + +private: + int32_t mId; +}; + +class HbFaceCacheTest : public testing::Test { +public: + virtual void TearDown() { + AutoMutex _l(gMinikinLock); + purgeHbFaceCacheLocked(); + } +}; + +TEST_F(HbFaceCacheTest, getHbFaceLockedTest) { + AutoMutex _l(gMinikinLock); + + MockMinikinFont fontA(1); + MockMinikinFont fontB(2); + MockMinikinFont fontC(2); + + // Never return NULL. + EXPECT_TRUE(getHbFaceLocked(&fontA)); + EXPECT_TRUE(getHbFaceLocked(&fontB)); + EXPECT_TRUE(getHbFaceLocked(&fontC)); + + // Must return same object if same font object is passed. + EXPECT_EQ(getHbFaceLocked(&fontA), getHbFaceLocked(&fontA)); + EXPECT_EQ(getHbFaceLocked(&fontB), getHbFaceLocked(&fontB)); + EXPECT_EQ(getHbFaceLocked(&fontC), getHbFaceLocked(&fontC)); + + // Different object must be returned if the passed minikinFont has different ID. + EXPECT_NE(getHbFaceLocked(&fontA), getHbFaceLocked(&fontB)); + EXPECT_NE(getHbFaceLocked(&fontA), getHbFaceLocked(&fontC)); + + // Same object must be returned if the minikinFont has same Id. + EXPECT_EQ(getHbFaceLocked(&fontB), getHbFaceLocked(&fontC)); +} + +TEST_F(HbFaceCacheTest, purgeCacheTest) { + AutoMutex _l(gMinikinLock); + MockMinikinFont font(1); + + hb_face_t* face = getHbFaceLocked(&font); + EXPECT_TRUE(face); + + // Set user data to identify the face object. + hb_user_data_key_t key; + void* data = (void*)0xdeadbeef; + hb_face_set_user_data(face, &key, data, NULL, false); + EXPECT_EQ(data, hb_face_get_user_data(face, &key)); + + purgeHbFaceCacheLocked(); + + // By checking user data, confirm that the object after purge is different from previously + // created one. Do not compare the returned pointer here since memory allocator may assign + // same region for new object. + face = getHbFaceLocked(&font); + EXPECT_EQ(nullptr, hb_face_get_user_data(face, &key)); +} + +} // namespace +} // namespace android From 96df754284ff81f0a25e7edd486bf7bd85a59fdf Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 27 Aug 2015 13:50:00 -0700 Subject: [PATCH 106/364] Binary format for hyphenation patterns In the current state, hyphenation in all languages than Sanskrit seems to work (case-folding edge cases). Thus, we just disable Sanskrit. Packed tries are implemented, but not the finite state machine (space/speed tradeoff). This commit contains a throw-away test app, which runs on the host. I think I want to replace it with unit tests, but I'm including it in the CL because it's useful during development. Bug: 21562869 Bug: 21826930 Bug: 23317038 Bug: 23317904 Change-Id: I7479a565a4a062fa319651c2c14c0fa18c5ceaea --- engine/src/flutter/app/Android.mk | 36 ++ engine/src/flutter/app/HyphTool.cpp | 62 ++ engine/src/flutter/doc/hyb_file_format.md | 135 +++++ .../src/flutter/include/minikin/Hyphenator.h | 41 +- engine/src/flutter/libs/minikin/Android.mk | 14 + .../src/flutter/libs/minikin/Hyphenator.cpp | 276 +++++---- engine/src/flutter/tools/mk_hyb_file.py | 567 ++++++++++++++++++ 7 files changed, 1019 insertions(+), 112 deletions(-) create mode 100644 engine/src/flutter/app/Android.mk create mode 100644 engine/src/flutter/app/HyphTool.cpp create mode 100644 engine/src/flutter/doc/hyb_file_format.md create mode 100755 engine/src/flutter/tools/mk_hyb_file.py diff --git a/engine/src/flutter/app/Android.mk b/engine/src/flutter/app/Android.mk new file mode 100644 index 00000000000..20386830272 --- /dev/null +++ b/engine/src/flutter/app/Android.mk @@ -0,0 +1,36 @@ +# Copyright (C) 2015 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. + +# see how_to_run.txt for instructions on running these tests + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := hyphtool +LOCAL_MODULE_TAGS := optional + +LOCAL_STATIC_LIBRARIES := libminikin_host + +# Shared libraries which are dependencies of minikin; these are not automatically +# pulled in by the build system (and thus sadly must be repeated). + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libicuuc-host + +LOCAL_SRC_FILES += \ + HyphTool.cpp + +include $(BUILD_HOST_EXECUTABLE) diff --git a/engine/src/flutter/app/HyphTool.cpp b/engine/src/flutter/app/HyphTool.cpp new file mode 100644 index 00000000000..730abadcbaf --- /dev/null +++ b/engine/src/flutter/app/HyphTool.cpp @@ -0,0 +1,62 @@ +#include +#include +#include + +#include "utils/Log.h" + +#include +#include + +using android::Hyphenator; + +Hyphenator* loadHybFile(const char* fn) { + struct stat statbuf; + int status = stat(fn, &statbuf); + if (status < 0) { + fprintf(stderr, "error opening %s\n", fn); + return nullptr; + } + size_t size = statbuf.st_size; + FILE* f = fopen(fn, "rb"); + if (f == NULL) { + fprintf(stderr, "error opening %s\n", fn); + return nullptr; + } + uint8_t* buf = new uint8_t[size]; + size_t read_size = fread(buf, 1, size, f); + if (read_size < size) { + fprintf(stderr, "error reading %s\n", fn); + delete[] buf; + return nullptr; + } + return Hyphenator::loadBinary(buf); +} + +int main(int argc, char** argv) { + Hyphenator* hyph = loadHybFile("/tmp/en.hyb"); // should also be configurable + std::vector result; + std::vector word; + if (argc < 2) { + fprintf(stderr, "usage: hyphtool word\n"); + return 1; + } + char* asciiword = argv[1]; + size_t len = strlen(asciiword); + for (size_t i = 0; i < len; i++) { + uint32_t c = asciiword[i]; + if (c == '-') { + c = 0x00AD; + } + // ASCII (or possibly ISO Latin 1), but kinda painful to do utf conversion :( + word.push_back(c); + } + hyph->hyphenate(&result, word.data(), word.size()); + for (size_t i = 0; i < len; i++) { + if (result[i] != 0) { + printf("-"); + } + printf("%c", word[i]); + } + printf("\n"); + return 0; +} diff --git a/engine/src/flutter/doc/hyb_file_format.md b/engine/src/flutter/doc/hyb_file_format.md new file mode 100644 index 00000000000..3065a6f5cc4 --- /dev/null +++ b/engine/src/flutter/doc/hyb_file_format.md @@ -0,0 +1,135 @@ +# Hyb (hyphenation pattern binary) file format + +The hyb file format is how hyphenation patterns are stored in the system image. + +Goals include: + +* Concise (system image space is at a premium) +* Usable when mmap'ed, so it doesn't take significant physical RAM +* Fast to compute +* Simple + +It is _not_ intended as an interchange format, so there is no attempt to make the format +extensible or facilitate backward and forward compatibility. + +Further, at some point we will probably pack patterns for multiple languages into a single +physical file, to reduce number of open mmap'ed files. This document doesn't cover that. + +## Theoretical basis + +At heart, the file contains packed tries with suffix compression, actually quite similar +to the implementation in TeX. + +The file contains three sections. The first section represents the "alphabet," including +case folding. It is effectively a map from Unicode code point to a small integer. + +The second section contains the trie in packed form. It is an array of 3-tuples, packed +into a 32 bit integer. Each (suffix-compressed) trie node has a unique index within this +array, and the pattern field in the tuple is the pattern for that node. Further, each edge +in the trie has an entry in the array, and the character and link fields in the tuple +represent the label and destination of the edge. The packing strategy is as in +[Word Hy-phen-a-tion by Com-put-er](http://www.tug.org/docs/liang/liang-thesis.pdf) by +Franklin Mark Liang. + +The trie representation is similar but not identical to the "double-array trie". +The fundamental operation of lookup of the edge from `s` to `t` with label `c` is +to compare `c == character[s + c]`, and if so, `t = link[s + c]`. + +The third section contains the pattern strings. This section is in two parts: first, +an array with a 3-tuple for each pattern (length, number of trailing 0's, and offset +into the string pool); and second, the string pool. Each pattern is encoded as a byte +(packing 2 per byte would be possible but the space savings would not be signficant). + +As much as possible of the file is represented as 32 bit integers, as that is especially +efficent to access. All are little-endian (this could be revised if the code ever needs +to be ported to big-endian systems). + +## Header + +``` +uint32_t magic == 0x62ad7968 +uint32_t version = 0 +uint32_t alphabet_offset (in bytes) +uint32_t trie_offset (in bytes) +uint32_t pattern_offset (in bytes) +uint32_t file_size (in bytes) +``` + +Offsets are from the front of the file, and in bytes. + +## Alphabet + +The alphabet table comes in two versions. The first is well suited to dense Unicode +ranges and is limited to 256. The second is more general, but lookups will be slower. + +### Alphabet, direct version + +``` +uint32_t version = 0 +uint32_t min_codepoint +uint32_t max_codepoint (exclusive) +uint8_t[] data +``` + +The size of the data array is max_codepoint - min_codepoint. 0 represents an unmapped +character. Note that, in the current implementation, automatic hyphenation is disabled +for any word containing an unmapped character. + +In general, pad bytes follow this table, aligning the next table to a 4-byte boundary. + +### Alphabet, general version + +``` +uint32_t version = 1 +uint32_t n_entries +uint32_t[n_entries] data +``` + +Each element in the data table is `(codepoint << 11) | value`. Note that this is +restricted to 11 bits (2048 possible values). The largest known current value is 483 +(for Sanskrit). + +The entries are sorted by codepoint, to facilitate binary search. Another reasonable +implementation for consumers of the data would be to build a hash table at load time. + +## Trie + +``` +uint32_t version = 0 +uint32_t char_mask +uint32_t link_shift +uint32_t link_mask +uint32_t pattern_shift +uint32_t n_entries +uint32_t[n_entries] data +``` + +Each element in the data table is `(pattern << pattern_shift) | (link << link_shift) | char`. + +All known pattern tables fit in 32 bits total. If this is exceeded, there is a fairly +straightforward tweak, where each node occupies a slot by itself (as opposed to sharing +it with edge slots), which would require very minimal changes to the implementation (TODO +present in more detail). + +## Pattern + +``` +uint32_t version = 0 +uint32_t n_entries +uint32_t pattern_offset (in bytes) +uint32_t pattern_size (in bytes) +uint32_t[n_entries] data +uint8_t[] pattern_buf +``` + +Each element in data table is `(len << 26) | (shift << 20) | offset`, where an offset of 0 +points to the first byte of pattern_buf. + +Generally pattern_offset is `16 + 4 * n_entries`. + +For example, 'a4m5ato' would be represented as `[4, 5, 0, 0, 0]`, then len = 2, shift = 3, and +offset points to [4, 5] in the pattern buffer. + +Future extension: additional data representing nonstandard hyphenation. See +[Automatic non-standard hyphenation in OpenOffice.org](https://www.tug.org/TUGboat/tb27-1/tb86nemeth.pdf) +for more information about that issue. diff --git a/engine/src/flutter/include/minikin/Hyphenator.h b/engine/src/flutter/include/minikin/Hyphenator.h index 581c657fbe6..9605205a294 100644 --- a/engine/src/flutter/include/minikin/Hyphenator.h +++ b/engine/src/flutter/include/minikin/Hyphenator.h @@ -26,11 +26,8 @@ namespace android { -class Trie { -public: - std::vector result; - std::unordered_map succ; -}; +// hyb file header; implementation details are in the .cpp file +struct Header; class Hyphenator { public: @@ -44,19 +41,43 @@ public: // Example: word is "hyphen", result is [0 0 1 0 0 0], corresponding to "hy-phen". void hyphenate(std::vector* result, const uint16_t* word, size_t len); -private: - void addPattern(const uint16_t* pattern, size_t size); + // pattern data is in binary format, as described in doc/hyb_file_format.md. Note: + // the caller is responsible for ensuring that the lifetime of the pattern data is + // at least as long as the Hyphenator object. - void hyphenateSoft(std::vector* result, const uint16_t* word, size_t len); + // Note: nullptr is valid input, in which case the hyphenator only processes soft hyphens + static Hyphenator* loadBinary(const uint8_t* patternData); + +private: + // apply soft hyphens only, ignoring patterns + void hyphenateSoft(uint8_t* result, const uint16_t* word, size_t len); + + // try looking up word in alphabet table, return false if any code units fail to map + // Note that this methor writes len+2 entries into alpha_codes (including start and stop) + bool alphabetLookup(uint16_t* alpha_codes, const uint16_t* word, size_t len); + + // calculate hyphenation from patterns, assuming alphabet lookup has already been done + void hyphenateFromCodes(uint8_t* result, const uint16_t* codes, size_t len); // TODO: these should become parameters, as they might vary by locale, screen size, and // possibly explicit user control. static const int MIN_PREFIX = 2; static const int MIN_SUFFIX = 3; - Trie root; + // See also LONGEST_HYPHENATED_WORD in LineBreaker.cpp. Here the constant is used so + // that temporary buffers can be stack-allocated without waste, which is a slightly + // different use case. It measures UTF-16 code units. + static const size_t MAX_HYPHENATED_SIZE = 64; + + const uint8_t* patternData; + + // accessors for binary data + const Header* getHeader() const { + return reinterpret_cast(patternData); + } + }; } // namespace android -#endif // MINIKIN_HYPHENATOR_H \ No newline at end of file +#endif // MINIKIN_HYPHENATOR_H diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 765a3ddfd75..58baedc2f0a 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -63,3 +63,17 @@ LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) include $(BUILD_STATIC_LIBRARY) + +include $(CLEAR_VARS) + +# Reduced library (currently just hyphenation) for host + +LOCAL_MODULE := libminikin_host +LOCAL_MODULE_TAGS := optional +LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include +LOCAL_C_INCLUDES := $(minikin_c_includes) +LOCAL_SHARED_LIBRARIES := liblog libicuuc-host + +LOCAL_SRC_FILES := Hyphenator.cpp + +include $(BUILD_HOST_STATIC_LIBRARY) diff --git a/engine/src/flutter/libs/minikin/Hyphenator.cpp b/engine/src/flutter/libs/minikin/Hyphenator.cpp index 3eb151b9e02..c5eb60b8e50 100644 --- a/engine/src/flutter/libs/minikin/Hyphenator.cpp +++ b/engine/src/flutter/libs/minikin/Hyphenator.cpp @@ -34,130 +34,202 @@ namespace android { static const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; -void Hyphenator::addPattern(const uint16_t* pattern, size_t size) { - vector word; - vector result; +// The following are structs that correspond to tables inside the hyb file format - // start by parsing the Liang-format pattern into a word and a result vector, the - // vector right-aligned but without leading zeros. Examples: - // a1bc2d -> abcd [1, 0, 2, 0] - // abc1 -> abc [1] - // 1a2b3c4d5 -> abcd [1, 2, 3, 4, 5] - bool lastWasLetter = false; - bool haveSeenNumber = false; - for (size_t i = 0; i < size; i++) { - uint16_t c = pattern[i]; - if (isdigit(c)) { - result.push_back(c - '0'); - lastWasLetter = false; - haveSeenNumber = true; - } else { - word.push_back(c); - if (lastWasLetter && haveSeenNumber) { - result.push_back(0); - } - lastWasLetter = true; - } - } - if (lastWasLetter) { - result.push_back(0); - } - Trie* t = &root; - for (size_t i = 0; i < word.size(); i++) { - t = &t->succ[word[i]]; - } - t->result = result; -} +struct AlphabetTable0 { + uint32_t version; + uint32_t min_codepoint; + uint32_t max_codepoint; + uint8_t data[1]; // actually flexible array, size is known at runtime +}; -// If any soft hyphen is present in the word, use soft hyphens to decide hyphenation, -// as recommended in UAX #14 (Use of Soft Hyphen) -void Hyphenator::hyphenateSoft(vector* result, const uint16_t* word, size_t len) { - (*result)[0] = 0; - for (size_t i = 1; i < len; i++) { - (*result)[i] = word[i - 1] == CHAR_SOFT_HYPHEN; +struct AlphabetTable1 { + uint32_t version; + uint32_t n_entries; + uint32_t data[1]; // actually flexible array, size is known at runtime + + static uint32_t codepoint(uint32_t entry) { return entry >> 11; } + static uint32_t value(uint32_t entry) { return entry & 0x7ff; } +}; + +struct Trie { + uint32_t version; + uint32_t char_mask; + uint32_t link_shift; + uint32_t link_mask; + uint32_t pattern_shift; + uint32_t n_entries; + uint32_t data[1]; // actually flexible array, size is known at runtime +}; + +struct Pattern { + uint32_t version; + uint32_t n_entries; + uint32_t pattern_offset; + uint32_t pattern_size; + uint32_t data[1]; // actually flexible array, size is known at runtime + + // accessors + static uint32_t len(uint32_t entry) { return entry >> 26; } + static uint32_t shift(uint32_t entry) { return (entry >> 20) & 0x3f; } + const uint8_t* buf(uint32_t entry) const { + return reinterpret_cast(this) + pattern_offset + (entry & 0xfffff); } +}; + +struct Header { + uint32_t magic; + uint32_t version; + uint32_t alphabet_offset; + uint32_t trie_offset; + uint32_t pattern_offset; + uint32_t file_size; + + // accessors + const uint8_t* bytes() const { return reinterpret_cast(this); } + uint32_t alphabetVersion() const { + return *reinterpret_cast(bytes() + alphabet_offset); + } + const AlphabetTable0* alphabetTable0() const { + return reinterpret_cast(bytes() + alphabet_offset); + } + const AlphabetTable1* alphabetTable1() const { + return reinterpret_cast(bytes() + alphabet_offset); + } + const Trie* trieTable() const { + return reinterpret_cast(bytes() + trie_offset); + } + const Pattern* patternTable() const { + return reinterpret_cast(bytes() + pattern_offset); + } +}; + +Hyphenator* Hyphenator::loadBinary(const uint8_t* patternData) { + Hyphenator* result = new Hyphenator; + result->patternData = patternData; + return result; } void Hyphenator::hyphenate(vector* result, const uint16_t* word, size_t len) { result->clear(); result->resize(len); - if (len < MIN_PREFIX + MIN_SUFFIX) return; - size_t maxOffset = len - MIN_SUFFIX + 1; - for (size_t i = 0; i < len + 1; i++) { - const Trie* node = &root; - for (size_t j = i; j < len + 2; j++) { - uint16_t c; - if (j == 0 || j == len + 1) { - c = '.'; // word boundary character in pattern data files - } else { - c = word[j - 1]; - if (c == CHAR_SOFT_HYPHEN) { - hyphenateSoft(result, word, len); - return; - } - // TODO: This uses ICU's simple character to character lowercasing, which ignores - // the locale, and ignores cases when lowercasing a character results in more than - // one character. It should be fixed to consider the locale (in order for it to work - // correctly for Turkish and Azerbaijani), as well as support one-to-many, and - // many-to-many case conversions (including non-BMP cases). - if (c < 0x00C0) { // U+00C0 is the lowest uppercase non-ASCII character - // Convert uppercase ASCII to lowercase ASCII, but keep other characters as-is - if (0x0041 <= c && c <= 0x005A) { - c += 0x0020; - } - } else { - c = u_tolower(c); - } + const size_t paddedLen = len + 2; // start and stop code each count for 1 + if (patternData != nullptr && + (int)len >= MIN_PREFIX + MIN_SUFFIX && paddedLen <= MAX_HYPHENATED_SIZE) { + uint16_t alpha_codes[MAX_HYPHENATED_SIZE]; + if (alphabetLookup(alpha_codes, word, len)) { + hyphenateFromCodes(result->data(), alpha_codes, paddedLen); + return; + } + // TODO: try NFC normalization + // TODO: handle non-BMP Unicode (requires remapping of offsets) + } + hyphenateSoft(result->data(), word, len); +} + +// If any soft hyphen is present in the word, use soft hyphens to decide hyphenation, +// as recommended in UAX #14 (Use of Soft Hyphen) +void Hyphenator::hyphenateSoft(uint8_t* result, const uint16_t* word, size_t len) { + result[0] = 0; + for (size_t i = 1; i < len; i++) { + result[i] = word[i - 1] == CHAR_SOFT_HYPHEN; + } +} + +bool Hyphenator::alphabetLookup(uint16_t* alpha_codes, const uint16_t* word, size_t len) { + const Header* header = getHeader(); + // TODO: check header magic + uint32_t alphabetVersion = header->alphabetVersion(); + if (alphabetVersion == 0) { + const AlphabetTable0* alphabet = header->alphabetTable0(); + uint32_t min_codepoint = alphabet->min_codepoint; + uint32_t max_codepoint = alphabet->max_codepoint; + alpha_codes[0] = 0; // word start + for (size_t i = 0; i < len; i++) { + uint16_t c = word[i]; + if (c < min_codepoint || c >= max_codepoint) { + return false; } - auto search = node->succ.find(c); - if (search != node->succ.end()) { - node = &search->second; + uint8_t code = alphabet->data[c - min_codepoint]; + if (code == 0) { + return false; + } + alpha_codes[i + 1] = code; + } + alpha_codes[len + 1] = 0; // word termination + return true; + } else if (alphabetVersion == 1) { + const AlphabetTable1* alphabet = header->alphabetTable1(); + size_t n_entries = alphabet->n_entries; + const uint32_t* begin = alphabet->data; + const uint32_t* end = begin + n_entries; + alpha_codes[0] = 0; + for (size_t i = 0; i < len; i++) { + uint16_t c = word[i]; + auto p = std::lower_bound(begin, end, c << 11); + if (p == end) { + return false; + } + uint32_t entry = *p; + if (AlphabetTable1::codepoint(entry) != c) { + return false; + } + alpha_codes[i + 1] = AlphabetTable1::value(entry); + } + alpha_codes[len + 1] = 0; + return true; + } + return false; +} + +/** + * Internal implementation, after conversion to codes. All case folding and normalization + * has been done by now, and all characters have been found in the alphabet. + * Note: len here is the padded length including 0 codes at start and end. + **/ +void Hyphenator::hyphenateFromCodes(uint8_t* result, const uint16_t* codes, size_t len) { + const Header* header = getHeader(); + const Trie* trie = header->trieTable(); + const Pattern* pattern = header->patternTable(); + uint32_t char_mask = trie->char_mask; + uint32_t link_shift = trie->link_shift; + uint32_t link_mask = trie->link_mask; + uint32_t pattern_shift = trie->pattern_shift; + size_t maxOffset = len - MIN_SUFFIX - 1; + for (size_t i = 0; i < len - 1; i++) { + uint32_t node = 0; // index into Trie table + for (size_t j = i; j < len; j++) { + uint16_t c = codes[j]; + uint32_t entry = trie->data[node + c]; + if ((entry & char_mask) == c) { + node = (entry & link_mask) >> link_shift; } else { break; } - if (!node->result.empty()) { - int resultLen = node->result.size(); - int offset = j + 1 - resultLen; + uint32_t pat_ix = trie->data[node] >> pattern_shift; + // pat_ix contains a 3-tuple of length, shift (number of trailing zeros), and an offset + // into the buf pool. This is the pattern for the substring (i..j) we just matched, + // which we combine (via point-wise max) into the result vector. + if (pat_ix != 0) { + uint32_t pat_entry = pattern->data[pat_ix]; + int pat_len = Pattern::len(pat_entry); + int pat_shift = Pattern::shift(pat_entry); + const uint8_t* pat_buf = pattern->buf(pat_entry); + int offset = j + 1 - (pat_len + pat_shift); + // offset is the index within result that lines up with the start of pat_buf int start = std::max(MIN_PREFIX - offset, 0); - int end = std::min(resultLen, (int)maxOffset - offset); - // TODO performance: this inner loop can profitably be optimized + int end = std::min(pat_len, (int)maxOffset - offset); for (int k = start; k < end; k++) { - (*result)[offset + k] = std::max((*result)[offset + k], node->result[k]); + result[offset + k] = std::max(result[offset + k], pat_buf[k]); } -#if 0 - // debug printing of matched patterns - std::string dbg; - for (size_t k = i; k <= j + 1; k++) { - int off = k - j - 2 + resultLen; - if (off >= 0 && node->result[off] != 0) { - dbg.push_back((char)('0' + node->result[off])); - } - if (k < j + 1) { - uint16_t c = (k == 0 || k == len + 1) ? '.' : word[k - 1]; - dbg.push_back((char)c); - } - } - ALOGD("%d:%d %s", i, j, dbg.c_str()); -#endif } } } // Since the above calculation does not modify values outside // [MIN_PREFIX, len - MIN_SUFFIX], they are left as 0. for (size_t i = MIN_PREFIX; i < maxOffset; i++) { - (*result)[i] &= 1; + result[i] &= 1; } } -Hyphenator* Hyphenator::load(const uint16_t *patternData, size_t size) { - Hyphenator* result = new Hyphenator; - for (size_t i = 0; i < size; i++) { - size_t end = i; - while (patternData[end] != '\n') end++; - result->addPattern(patternData + i, end - i); - i = end; - } - return result; -} - } // namespace android diff --git a/engine/src/flutter/tools/mk_hyb_file.py b/engine/src/flutter/tools/mk_hyb_file.py new file mode 100755 index 00000000000..c078454e6b2 --- /dev/null +++ b/engine/src/flutter/tools/mk_hyb_file.py @@ -0,0 +1,567 @@ +#!/usr/bin/env python + +# Copyright (C) 2015 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. + +""" +Convert hyphen files in standard TeX format (a trio of pat, chr, and hyp) +into binary format. See doc/hyb_file_format.md for more information. + +Usage: mk_hyb_file.py [-v] hyph-foo.pat.txt hyph-foo.hyb + +Optional -v parameter turns on verbose debugging. + +""" + +from __future__ import print_function + +import io +import sys +import struct +import math +import getopt + + +VERBOSE = False + + +if sys.version_info[0] >= 3: + def unichr(x): + return chr(x) + + +# number of bits required to represent numbers up to n inclusive +def num_bits(n): + return 1 + int(math.log(n, 2)) if n > 0 else 0 + + +class Node: + + def __init__(self): + self.succ = {} + self.res = None + self.fsm_pat = None + self.fail = None + + +# List of free slots, implemented as doubly linked list +class Freelist: + + def __init__(self): + self.first = None + self.last = None + self.pred = [] + self.succ = [] + + def grow(self): + this = len(self.pred) + self.pred.append(self.last) + self.succ.append(None) + if self.last is None: + self.first = this + else: + self.succ[self.last] = this + self.last = this + + def next(self, cursor): + if cursor == 0: + cursor = self.first + if cursor is None: + self.grow() + result = self.last + else: + result = cursor + return result, self.succ[result] + + def is_free(self, ix): + while ix >= len(self.pred): + self.grow() + return self.pred[ix] != -1 + + def use(self, ix): + if self.pred[ix] is None: + self.first = self.succ[ix] + else: + self.succ[self.pred[ix]] = self.succ[ix] + if self.succ[ix] is None: + self.last = self.pred[ix] + else: + self.pred[self.succ[ix]] = self.pred[ix] + if self.pred[ix] == -1: + assert self.pred[ix] != -1, 'double free!' + self.pred[ix] = -1 + + +def combine(a, b): + if a is None: return b + if b is None: return a + if len(b) < len(a): a, b = b, a + res = b[:len(b) - len(a)] + for i in range(len(a)): + res.append(max(a[i], b[i + len(b) - len(a)])) + return res + + +def trim(pattern): + for ix in range(len(pattern)): + if pattern[ix] != 0: + return pattern[ix:] + + +def pat_to_binary(pattern): + return b''.join(struct.pack('B', x) for x in pattern) + + +class Hyph: + + def __init__(self): + self.root = Node() + self.root.str = '' + self.node_list = [self.root] + + # Add a pattern (word fragment with numeric codes, such as ".ad4der") + def add_pat(self, pat): + lastWasLetter = False + haveSeenNumber = False + result = [] + word = '' + for c in pat: + if c.isdigit(): + result.append(int(c)) + lastWasLetter = False + haveSeenNumber = True + else: + word += c + if lastWasLetter and haveSeenNumber: + result.append(0) + lastWasLetter = True + if lastWasLetter: + result.append(0) + + self.add_word_res(word, result) + + # Add an exception (word with hyphens, such as "ta-ble") + def add_exception(self, hyph_word): + res = [] + word = ['.'] + need_10 = False + for c in hyph_word: + if c == '-': + res.append(11) + need_10 = False + else: + if need_10: + res.append(10) + word.append(c) + need_10 = True + word.append('.') + res.append(0) + res.append(0) + if VERBOSE: + print(word, res) + self.add_word_res(''.join(word), res) + + def add_word_res(self, word, result): + if VERBOSE: + print(word, result) + + t = self.root + s = '' + for c in word: + s += c + if c not in t.succ: + new_node = Node() + new_node.str = s + self.node_list.append(new_node) + t.succ[c] = new_node + t = t.succ[c] + t.res = result + + def pack(self, node_list, ch_map, use_node=False): + size = 0 + self.node_map = {} + nodes = Freelist() + edges = Freelist() + edge_start = 1 if use_node else 0 + for node in node_list: + succ = sorted([ch_map[c] + edge_start for c in node.succ.keys()]) + if len(succ): + cursor = 0 + while True: + edge_ix, cursor = edges.next(cursor) + ix = edge_ix - succ[0] + if (ix >= 0 and nodes.is_free(ix) and + all(edges.is_free(ix + s) for s in succ) and + ((not use_node) or edges.is_free(ix))): + break + elif use_node: + ix, _ = edges.next(0) + nodes.is_free(ix) # actually don't need nodes at all when use_node, + # but keep it happy + else: + ix, _ = nodes.next(0) + node.ix = ix + self.node_map[ix] = node + nodes.use(ix) + size = max(size, ix) + if use_node: + edges.use(ix) + for s in succ: + edges.use(ix + s) + size += max(ch_map.values()) + 1 + return size + + # return list of nodes in bfs order + def bfs(self, ch_map): + result = [self.root] + ix = 0 + while ix < len(result): + node = result[ix] + node.bfs_ix = ix + mapped = {} + for c, next in node.succ.items(): + assert ch_map[c] not in mapped, 'duplicate edge ' + node.str + ' ' + hex(ord(c)) + mapped[ch_map[c]] = next + for i in sorted(mapped.keys()): + result.append(mapped[i]) + ix += 1 + self.bfs_order = result + return result + + # suffix compression - convert the trie into an acyclic digraph, merging nodes when + # the subtries are identical + def dedup(self): + uniques = [] + dupmap = {} + dedup_ix = [0] * len(self.bfs_order) + for ix in reversed(range(len(self.bfs_order))): + # construct string representation of node + node = self.bfs_order[ix] + if node.res is None: + s = '' + else: + s = ''.join(str(c) for c in node.res) + for c in sorted(node.succ.keys()): + succ = node.succ[c] + s += ' ' + c + str(dedup_ix[succ.bfs_ix]) + if s in dupmap: + dedup_ix[ix] = dupmap[s] + else: + uniques.append(node) + dedup_ix[ix] = ix + dupmap[s] = dedup_ix[ix] + uniques.reverse() + print(len(uniques), 'unique nodes,', len(self.bfs_order), 'total') + return dedup_ix, uniques + + +# load the ".pat" file, which contains patterns such as a1b2c3 +def load(fn): + hyph = Hyph() + with io.open(fn, encoding='UTF-8') as f: + for l in f: + pat = l.strip() + hyph.add_pat(pat) + return hyph + + +# load the ".chr" file, which contains the alphabet and case pairs, eg "aA", "bB" etc. +def load_chr(fn): + ch_map = {'.': 0} + with io.open(fn, encoding='UTF-8') as f: + for i, l in enumerate(f): + l = l.strip() + if len(l) > 2: + # lowercase maps to multi-character uppercase sequence, ignore uppercase for now + l = l[:1] + else: + assert len(l) == 2, 'expected 2 chars in chr' + for c in l: + ch_map[c] = i + 1 + return ch_map + + +# load exceptions with explicit hyphens +def load_hyp(hyph, fn): + with io.open(fn, encoding='UTF-8') as f: + for l in f: + hyph.add_exception(l.strip()) + + +def generate_header(alphabet, trie, pattern): + alphabet_off = 6 * 4 + trie_off = alphabet_off + len(alphabet) + pattern_off = trie_off + len(trie) + file_size = pattern_off + len(pattern) + data = [0x62ad7968, 0, alphabet_off, trie_off, pattern_off, file_size] + return struct.pack('<6I', *data) + + +def generate_alphabet(ch_map): + ch_map = ch_map.copy() + del ch_map['.'] + min_ch = ord(min(ch_map)) + max_ch = ord(max(ch_map)) + if max_ch - min_ch < 1024 and max(ch_map.values()) < 256: + # generate format 0 + data = [0] * (max_ch - min_ch + 1) + for c, val in ch_map.items(): + data[ord(c) - min_ch] = val + result = [struct.pack('<3I', 0, min_ch, max_ch + 1)] + for b in data: + result.append(struct.pack('> 26 + pat_shift = (entry >> 20) & 0x1f + offset = pattern_offset + (entry & 0xfffff) + return pattern_data[offset: offset + pat_len] + b'\0' * pat_shift + + +def traverse_trie(ix, s, trie_data, ch_map, pattern_data, patterns, exceptions): + (char_mask, link_shift, link_mask, pattern_shift) = struct.unpack('<4I', trie_data[4:20]) + node_entry = struct.unpack('> pattern_shift + if pattern: + result = [] + is_exception = False + pat = get_pattern(pattern_data, pattern) + for i in range(len(s) + 1): + pat_off = i - 1 + len(pat) - len(s) + if pat_off < 0: + code = 0 + else: + code = struct.unpack('B', pat[pat_off : pat_off + 1])[0] + if 1 <= code <= 9: + result.append('%d' % code) + elif code == 10: + is_exception = True + elif code == 11: + result.append('-') + is_exception = True + else: + assert code == 0, 'unexpected code' + if i < len(s): + result.append(s[i]) + pat_str = ''.join(result) + #print(`pat_str`, `pat`) + if is_exception: + assert pat_str[0] == '.', "expected leading '.'" + assert pat_str[-1] == '.', "expected trailing '.'" + exceptions.append(pat_str[1:-1]) # strip leading and trailing '.' + else: + patterns.append(pat_str) + for ch in ch_map: + edge_entry = struct.unpack('> link_shift + if link != 0 and ch == (edge_entry & char_mask): + sch = s + ch_map[ch] + traverse_trie(link, sch, trie_data, ch_map, pattern_data, patterns, exceptions) + + +# Verify the generated binary file by reconstructing the textual representations +# from the binary hyb file, then checking that they're identical (mod the order of +# lines within the file, which is irrelevant). This function makes assumptions that +# are stronger than absolutely necessary (in particular, that the patterns are in +# lowercase as defined by python islower). +def verify_hyb_file(hyb_fn, pat_fn, chr_fn, hyp_fn): + with open(hyb_fn, 'rb') as f: + hyb_data = f.read() + header = hyb_data[0: 6 * 4] + (magic, version, alphabet_off, trie_off, pattern_off, file_size) = struct.unpack('<6I', header) + alphabet_data = hyb_data[alphabet_off:trie_off] + trie_data = hyb_data[trie_off:pattern_off] + pattern_data = hyb_data[pattern_off:file_size] + + # reconstruct alphabet table + alphabet_version = struct.unpack('> 11)] = entry & 0x7ff + + ch_map, reconstructed_chr = map_to_chr(alphabet_map) + + # EXCEPTION for Armenian (hy), we don't really deal with the uppercase form of U+0587 + if u'\u0587' in reconstructed_chr: + reconstructed_chr.remove(u'\u0587') + reconstructed_chr.append(u'\u0587\u0535\u0552') + + assert verify_file_sorted(reconstructed_chr, chr_fn), 'alphabet table not verified' + + # reconstruct trie + patterns = [] + exceptions = [] + traverse_trie(0, '', trie_data, ch_map, pattern_data, patterns, exceptions) + assert verify_file_sorted(patterns, pat_fn), 'pattern table not verified' + assert verify_file_sorted(exceptions, hyp_fn), 'exception table not verified' + + +def main(): + global VERBOSE + try: + opts, args = getopt.getopt(sys.argv[1:], 'v') + except getopt.GetoptError as err: + print(str(err)) + sys.exit(1) + for o, _ in opts: + if o == '-v': + VERBOSE = True + pat_fn, out_fn = args + hyph = load(pat_fn) + if pat_fn.endswith('.pat.txt'): + chr_fn = pat_fn[:-8] + '.chr.txt' + ch_map = load_chr(chr_fn) + hyp_fn = pat_fn[:-8] + '.hyp.txt' + load_hyp(hyph, hyp_fn) + generate_hyb_file(hyph, ch_map, out_fn) + verify_hyb_file(out_fn, pat_fn, chr_fn, hyp_fn) + +if __name__ == '__main__': + main() From 179d763488f9e4ddcc94e3e844bfb0d796974f97 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 30 Sep 2015 23:26:54 -0700 Subject: [PATCH 107/364] Explicitly set utf-8 encoding for hyb file verification Not all platforms default to UTF-8 encoding, so we set it explicitly. This patch should fix build breakages resulting from failed verification of binary hyb files for hyphenation patterns. Change-Id: I65ac4536d3436586c2633e2b57554fc6ff16d3a8 --- engine/src/flutter/tools/mk_hyb_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/flutter/tools/mk_hyb_file.py b/engine/src/flutter/tools/mk_hyb_file.py index c078454e6b2..978c082b279 100755 --- a/engine/src/flutter/tools/mk_hyb_file.py +++ b/engine/src/flutter/tools/mk_hyb_file.py @@ -416,7 +416,7 @@ def generate_hyb_file(hyph, ch_map, hyb_fn): # Verify that the file contains the same lines as the lines argument, in arbitrary order def verify_file_sorted(lines, fn): - file_lines = [l.strip() for l in io.open(fn)] + file_lines = [l.strip() for l in io.open(fn, encoding='UTF-8')] line_set = set(lines) file_set = set(file_lines) if line_set == file_set: From ad9cb5909a84f8b8c298d8e0d78e7394fe4803d6 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 24 Sep 2015 18:41:41 +0900 Subject: [PATCH 108/364] Introduce FontFamily::hasVariationSelector This CL introduces new method hasVariationSelector into FontFamily but it is not used in production code. So no behavior changes are expected. This CL contains the following changes: - Introduce hasVariationSelector which returns true if the corresponding font has a glyph for a code point and variation selector pair. - Introduce purgeHbFontCache since hb_face_t won't be released by keeping hb_font_t. - Introduce unit tests with self-built font. Change-Id: I659a6d03d9ec446b409e1fba2758452abb9f44fa --- .../flutter/include/minikin/FontCollection.h | 4 + .../src/flutter/include/minikin/FontFamily.h | 17 ++- .../flutter/libs/minikin/FontCollection.cpp | 7 + .../src/flutter/libs/minikin/FontFamily.cpp | 25 ++++ engine/src/flutter/libs/minikin/Layout.cpp | 2 + engine/src/flutter/tests/Android.mk | 1 + engine/src/flutter/tests/FontFamilyTest.cpp | 122 ++++++++++++++++++ engine/src/flutter/tests/how_to_run.txt | 1 + 8 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 engine/src/flutter/tests/FontFamilyTest.cpp diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index ffdb4d18196..c4daf98fa68 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -47,6 +47,10 @@ public: FakedFont baseFontFaked(FontStyle style); uint32_t getId() const; + + // Calls each managed font family's FontFamily::purgeHbFontCache method. + // Caller should acquire a lock before calling the method. + void purgeFontFamilyHbFontCache() const; private: static const int kLogCharsPerPage = 8; static const int kPageMask = (1 << kLogCharsPerPage) - 1; diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index d21a20af718..b1994042e3c 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -19,6 +19,7 @@ #include #include +#include #include @@ -123,9 +124,9 @@ struct FakedFont { class FontFamily : public MinikinRefCounted { public: - FontFamily() { } + FontFamily() : mHbFont(nullptr) { } - FontFamily(FontLanguage lang, int variant) : mLang(lang), mVariant(variant) { + FontFamily(FontLanguage lang, int variant) : mLang(lang), mVariant(variant), mHbFont(nullptr) { } ~FontFamily(); @@ -147,6 +148,16 @@ public: // Get Unicode coverage. Lifetime of returned bitset is same as receiver. May return nullptr on // error. const SparseBitSet* getCoverage(); + + // Returns true if the font has a glyph for the code point and variation selector pair. + // Caller should acquire a lock before calling the method. + bool hasVariationSelector(uint32_t codepoint, uint32_t variationSelector); + + // Purges cached mHbFont. + // hb_font_t keeps a reference to hb_face_t which is managed by HbFaceCache. Thus, + // it is good to purge hb_font_t once it is no longer necessary. + // Caller should acquire a lock before calling the method. + void purgeHbFontCache(); private: void addFontLocked(MinikinFont* typeface, FontStyle style); @@ -163,6 +174,8 @@ private: SparseBitSet mCoverage; bool mCoverageValid; + + hb_font_t* mHbFont; }; } // namespace android diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index b4bfe313ba4..36d47ded9d5 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -233,4 +233,11 @@ uint32_t FontCollection::getId() const { return mId; } +void FontCollection::purgeFontFamilyHbFontCache() const { + assertMinikinLocked(); + for (size_t i = 0; i < mFamilies.size(); ++i) { + mFamilies[i]->purgeHbFontCache(); + } +} + } // namespace android diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index c70cf88023f..a6632e03398 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -20,6 +20,10 @@ #include #include +#include +#include + +#include "HbFaceCache.h" #include "MinikinInternal.h" #include #include @@ -229,4 +233,25 @@ const SparseBitSet* FontFamily::getCoverage() { return &mCoverage; } +bool FontFamily::hasVariationSelector(uint32_t codepoint, uint32_t variationSelector) { + assertMinikinLocked(); + if (!mHbFont) { + const FontStyle defaultStyle; + MinikinFont* minikinFont = getClosestMatch(defaultStyle).font; + hb_face_t* face = getHbFaceLocked(minikinFont); + mHbFont = hb_font_create(face); + hb_ot_font_set_funcs(mHbFont); + } + uint32_t unusedGlyph; + return hb_font_get_glyph(mHbFont, codepoint, variationSelector, &unusedGlyph); +} + +void FontFamily::purgeHbFontCache() { + assertMinikinLocked(); + if (mHbFont) { + hb_font_destroy(mHbFont); + mHbFont = nullptr; + } +} + } // namespace android diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 63841515bfa..6d62d5d7d8e 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -131,6 +131,7 @@ public: layout->setFontCollection(collection); layout->mAdvances.resize(mCount, 0); ctx->clearHbFonts(); + collection->purgeFontFamilyHbFontCache(); layout->doLayoutRun(mChars, mStart, mCount, mNchars, mIsRtl, ctx); } @@ -595,6 +596,7 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu start); } ctx.clearHbFonts(); + mCollection->purgeFontFamilyHbFontCache(); } void Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index b4d5e91bc34..b69b8f243f6 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -40,6 +40,7 @@ LOCAL_STATIC_LIBRARIES += \ LOCAL_SRC_FILES += \ FontCollectionItemizeTest.cpp \ + FontFamilyTest.cpp \ FontTestUtils.cpp \ MinikinFontForTest.cpp \ GraphemeBreakTests.cpp \ diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp new file mode 100644 index 00000000000..a6813f013b3 --- /dev/null +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2015 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 + +#include +#include "MinikinFontForTest.h" +#include "MinikinInternal.h" + +namespace android { + +// The test font has following glyphs. +// U+82A6 +// U+82A6 U+FE00 (VS1) +// U+82A6 U+E0100 (VS17) +// U+82A6 U+E0101 (VS18) +// U+82A6 U+E0102 (VS19) +// U+845B +// U+845B U+FE00 (VS2) +// U+845B U+E0101 (VS18) +// U+845B U+E0102 (VS19) +// U+845B U+E0103 (VS20) +// U+537F +// U+717D U+FE02 (VS3) +// U+717D U+E0102 (VS19) +// U+717D U+E0103 (VS20) +const char kVsTestFont[] = "/data/minikin/test/data/VarioationSelectorTest-Regular.ttf"; + +class FontFamilyTest : public testing::Test { +public: + virtual void SetUp() override { + if (access(kVsTestFont, R_OK) != 0) { + FAIL() << "Unable to read " << kVsTestFont << ". " + << "Please prepare the test data directory. " + << "For more details, please see how_to_run.txt."; + } + } +}; + +// Asserts that the font family has glyphs for and only for specified codepoint +// and variationSelector pairs. +void expectVSGlyphs(FontFamily* family, uint32_t codepoint, const std::set& vs) { + for (uint32_t i = 0xFE00; i <= 0xE01EF; ++i) { + // Move to variation selectors supplements after variation selectors. + if (i == 0xFF00) { + i = 0xE0100; + } + if (vs.find(i) == vs.end()) { + EXPECT_FALSE(family->hasVariationSelector(codepoint, i)) + << "Glyph for U+" << std::hex << codepoint << " U+" << i; + } else { + EXPECT_TRUE(family->hasVariationSelector(codepoint, i)) + << "Glyph for U+" << std::hex << codepoint << " U+" << i; + } + + } +} + +TEST_F(FontFamilyTest, hasVariationSelectorTest) { + MinikinFontForTest minikinFont(kVsTestFont); + FontFamily family; + family.addFont(&minikinFont); + + AutoMutex _l(gMinikinLock); + + const uint32_t kVS1 = 0xFE00; + const uint32_t kVS2 = 0xFE01; + const uint32_t kVS3 = 0xFE02; + const uint32_t kVS17 = 0xE0100; + const uint32_t kVS18 = 0xE0101; + const uint32_t kVS19 = 0xE0102; + const uint32_t kVS20 = 0xE0103; + + const uint32_t kSupportedChar1 = 0x82A6; + EXPECT_TRUE(family.getCoverage()->get(kSupportedChar1)); + expectVSGlyphs(&family, kSupportedChar1, std::set({kVS1, kVS17, kVS18, kVS19})); + + const uint32_t kSupportedChar2 = 0x845B; + EXPECT_TRUE(family.getCoverage()->get(kSupportedChar2)); + expectVSGlyphs(&family, kSupportedChar2, std::set({kVS2, kVS18, kVS19, kVS20})); + + const uint32_t kNoVsSupportedChar = 0x537F; + EXPECT_TRUE(family.getCoverage()->get(kNoVsSupportedChar)); + expectVSGlyphs(&family, kNoVsSupportedChar, std::set()); + + const uint32_t kVsOnlySupportedChar = 0x717D; + EXPECT_FALSE(family.getCoverage()->get(kVsOnlySupportedChar)); + expectVSGlyphs(&family, kVsOnlySupportedChar, std::set({kVS3, kVS19, kVS20})); + + const uint32_t kNotSupportedChar = 0x845C; + EXPECT_FALSE(family.getCoverage()->get(kNotSupportedChar)); + expectVSGlyphs(&family, kNotSupportedChar, std::set()); +} + +TEST_F(FontFamilyTest, hasVariationSelectorWorksAfterpurgeHbFontCache) { + MinikinFontForTest minikinFont(kVsTestFont); + FontFamily family; + family.addFont(&minikinFont); + + const uint32_t kVS1 = 0xFE00; + const uint32_t kSupportedChar1 = 0x82A6; + + AutoMutex _l(gMinikinLock); + EXPECT_TRUE(family.hasVariationSelector(kSupportedChar1, kVS1)); + + family.purgeHbFontCache(); + EXPECT_TRUE(family.hasVariationSelector(kSupportedChar1, kVS1)); +} +} // namespace android diff --git a/engine/src/flutter/tests/how_to_run.txt b/engine/src/flutter/tests/how_to_run.txt index a6b79528551..09c3b0614ef 100644 --- a/engine/src/flutter/tests/how_to_run.txt +++ b/engine/src/flutter/tests/how_to_run.txt @@ -1,4 +1,5 @@ mmm -j8 frameworks/minikin/tests && adb push $OUT/data/nativetest/minikin_tests/minikin_tests \ /data/nativetest/minikin_tests/minikin_tests && +adb push -p frameworks/minikin/tests/data /data/minikin/test/data && adb shell /data/nativetest/minikin_tests/minikin_tests From 9036c194b04f921f35a7b7c064f88bba565c63b3 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 27 Aug 2015 13:50:00 -0700 Subject: [PATCH 109/364] Binary format for hyphenation patterns In the current state, hyphenation in all languages than Sanskrit seems to work (case-folding edge cases). Thus, we just disable Sanskrit. Packed tries are implemented, but not the finite state machine (space/speed tradeoff). This commit contains a throw-away test app, which runs on the host. I think I want to replace it with unit tests, but I'm including it in the CL because it's useful during development. Bug: 21562869 Bug: 21826930 Bug: 23317038 Bug: 23317904 Bug: 24570591 Change-Id: I7479a565a4a062fa319651c2c14c0fa18c5ceaea (cherry picked from commit 96df754284ff81f0a25e7edd486bf7bd85a59fdf) --- engine/src/flutter/app/Android.mk | 36 ++ engine/src/flutter/app/HyphTool.cpp | 62 ++ engine/src/flutter/doc/hyb_file_format.md | 135 +++++ .../src/flutter/include/minikin/Hyphenator.h | 41 +- engine/src/flutter/libs/minikin/Android.mk | 25 + .../src/flutter/libs/minikin/Hyphenator.cpp | 276 +++++---- engine/src/flutter/tools/mk_hyb_file.py | 567 ++++++++++++++++++ 7 files changed, 1030 insertions(+), 112 deletions(-) create mode 100644 engine/src/flutter/app/Android.mk create mode 100644 engine/src/flutter/app/HyphTool.cpp create mode 100644 engine/src/flutter/doc/hyb_file_format.md create mode 100755 engine/src/flutter/tools/mk_hyb_file.py diff --git a/engine/src/flutter/app/Android.mk b/engine/src/flutter/app/Android.mk new file mode 100644 index 00000000000..20386830272 --- /dev/null +++ b/engine/src/flutter/app/Android.mk @@ -0,0 +1,36 @@ +# Copyright (C) 2015 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. + +# see how_to_run.txt for instructions on running these tests + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_MODULE := hyphtool +LOCAL_MODULE_TAGS := optional + +LOCAL_STATIC_LIBRARIES := libminikin_host + +# Shared libraries which are dependencies of minikin; these are not automatically +# pulled in by the build system (and thus sadly must be repeated). + +LOCAL_SHARED_LIBRARIES := \ + liblog \ + libicuuc-host + +LOCAL_SRC_FILES += \ + HyphTool.cpp + +include $(BUILD_HOST_EXECUTABLE) diff --git a/engine/src/flutter/app/HyphTool.cpp b/engine/src/flutter/app/HyphTool.cpp new file mode 100644 index 00000000000..730abadcbaf --- /dev/null +++ b/engine/src/flutter/app/HyphTool.cpp @@ -0,0 +1,62 @@ +#include +#include +#include + +#include "utils/Log.h" + +#include +#include + +using android::Hyphenator; + +Hyphenator* loadHybFile(const char* fn) { + struct stat statbuf; + int status = stat(fn, &statbuf); + if (status < 0) { + fprintf(stderr, "error opening %s\n", fn); + return nullptr; + } + size_t size = statbuf.st_size; + FILE* f = fopen(fn, "rb"); + if (f == NULL) { + fprintf(stderr, "error opening %s\n", fn); + return nullptr; + } + uint8_t* buf = new uint8_t[size]; + size_t read_size = fread(buf, 1, size, f); + if (read_size < size) { + fprintf(stderr, "error reading %s\n", fn); + delete[] buf; + return nullptr; + } + return Hyphenator::loadBinary(buf); +} + +int main(int argc, char** argv) { + Hyphenator* hyph = loadHybFile("/tmp/en.hyb"); // should also be configurable + std::vector result; + std::vector word; + if (argc < 2) { + fprintf(stderr, "usage: hyphtool word\n"); + return 1; + } + char* asciiword = argv[1]; + size_t len = strlen(asciiword); + for (size_t i = 0; i < len; i++) { + uint32_t c = asciiword[i]; + if (c == '-') { + c = 0x00AD; + } + // ASCII (or possibly ISO Latin 1), but kinda painful to do utf conversion :( + word.push_back(c); + } + hyph->hyphenate(&result, word.data(), word.size()); + for (size_t i = 0; i < len; i++) { + if (result[i] != 0) { + printf("-"); + } + printf("%c", word[i]); + } + printf("\n"); + return 0; +} diff --git a/engine/src/flutter/doc/hyb_file_format.md b/engine/src/flutter/doc/hyb_file_format.md new file mode 100644 index 00000000000..3065a6f5cc4 --- /dev/null +++ b/engine/src/flutter/doc/hyb_file_format.md @@ -0,0 +1,135 @@ +# Hyb (hyphenation pattern binary) file format + +The hyb file format is how hyphenation patterns are stored in the system image. + +Goals include: + +* Concise (system image space is at a premium) +* Usable when mmap'ed, so it doesn't take significant physical RAM +* Fast to compute +* Simple + +It is _not_ intended as an interchange format, so there is no attempt to make the format +extensible or facilitate backward and forward compatibility. + +Further, at some point we will probably pack patterns for multiple languages into a single +physical file, to reduce number of open mmap'ed files. This document doesn't cover that. + +## Theoretical basis + +At heart, the file contains packed tries with suffix compression, actually quite similar +to the implementation in TeX. + +The file contains three sections. The first section represents the "alphabet," including +case folding. It is effectively a map from Unicode code point to a small integer. + +The second section contains the trie in packed form. It is an array of 3-tuples, packed +into a 32 bit integer. Each (suffix-compressed) trie node has a unique index within this +array, and the pattern field in the tuple is the pattern for that node. Further, each edge +in the trie has an entry in the array, and the character and link fields in the tuple +represent the label and destination of the edge. The packing strategy is as in +[Word Hy-phen-a-tion by Com-put-er](http://www.tug.org/docs/liang/liang-thesis.pdf) by +Franklin Mark Liang. + +The trie representation is similar but not identical to the "double-array trie". +The fundamental operation of lookup of the edge from `s` to `t` with label `c` is +to compare `c == character[s + c]`, and if so, `t = link[s + c]`. + +The third section contains the pattern strings. This section is in two parts: first, +an array with a 3-tuple for each pattern (length, number of trailing 0's, and offset +into the string pool); and second, the string pool. Each pattern is encoded as a byte +(packing 2 per byte would be possible but the space savings would not be signficant). + +As much as possible of the file is represented as 32 bit integers, as that is especially +efficent to access. All are little-endian (this could be revised if the code ever needs +to be ported to big-endian systems). + +## Header + +``` +uint32_t magic == 0x62ad7968 +uint32_t version = 0 +uint32_t alphabet_offset (in bytes) +uint32_t trie_offset (in bytes) +uint32_t pattern_offset (in bytes) +uint32_t file_size (in bytes) +``` + +Offsets are from the front of the file, and in bytes. + +## Alphabet + +The alphabet table comes in two versions. The first is well suited to dense Unicode +ranges and is limited to 256. The second is more general, but lookups will be slower. + +### Alphabet, direct version + +``` +uint32_t version = 0 +uint32_t min_codepoint +uint32_t max_codepoint (exclusive) +uint8_t[] data +``` + +The size of the data array is max_codepoint - min_codepoint. 0 represents an unmapped +character. Note that, in the current implementation, automatic hyphenation is disabled +for any word containing an unmapped character. + +In general, pad bytes follow this table, aligning the next table to a 4-byte boundary. + +### Alphabet, general version + +``` +uint32_t version = 1 +uint32_t n_entries +uint32_t[n_entries] data +``` + +Each element in the data table is `(codepoint << 11) | value`. Note that this is +restricted to 11 bits (2048 possible values). The largest known current value is 483 +(for Sanskrit). + +The entries are sorted by codepoint, to facilitate binary search. Another reasonable +implementation for consumers of the data would be to build a hash table at load time. + +## Trie + +``` +uint32_t version = 0 +uint32_t char_mask +uint32_t link_shift +uint32_t link_mask +uint32_t pattern_shift +uint32_t n_entries +uint32_t[n_entries] data +``` + +Each element in the data table is `(pattern << pattern_shift) | (link << link_shift) | char`. + +All known pattern tables fit in 32 bits total. If this is exceeded, there is a fairly +straightforward tweak, where each node occupies a slot by itself (as opposed to sharing +it with edge slots), which would require very minimal changes to the implementation (TODO +present in more detail). + +## Pattern + +``` +uint32_t version = 0 +uint32_t n_entries +uint32_t pattern_offset (in bytes) +uint32_t pattern_size (in bytes) +uint32_t[n_entries] data +uint8_t[] pattern_buf +``` + +Each element in data table is `(len << 26) | (shift << 20) | offset`, where an offset of 0 +points to the first byte of pattern_buf. + +Generally pattern_offset is `16 + 4 * n_entries`. + +For example, 'a4m5ato' would be represented as `[4, 5, 0, 0, 0]`, then len = 2, shift = 3, and +offset points to [4, 5] in the pattern buffer. + +Future extension: additional data representing nonstandard hyphenation. See +[Automatic non-standard hyphenation in OpenOffice.org](https://www.tug.org/TUGboat/tb27-1/tb86nemeth.pdf) +for more information about that issue. diff --git a/engine/src/flutter/include/minikin/Hyphenator.h b/engine/src/flutter/include/minikin/Hyphenator.h index 581c657fbe6..9605205a294 100644 --- a/engine/src/flutter/include/minikin/Hyphenator.h +++ b/engine/src/flutter/include/minikin/Hyphenator.h @@ -26,11 +26,8 @@ namespace android { -class Trie { -public: - std::vector result; - std::unordered_map succ; -}; +// hyb file header; implementation details are in the .cpp file +struct Header; class Hyphenator { public: @@ -44,19 +41,43 @@ public: // Example: word is "hyphen", result is [0 0 1 0 0 0], corresponding to "hy-phen". void hyphenate(std::vector* result, const uint16_t* word, size_t len); -private: - void addPattern(const uint16_t* pattern, size_t size); + // pattern data is in binary format, as described in doc/hyb_file_format.md. Note: + // the caller is responsible for ensuring that the lifetime of the pattern data is + // at least as long as the Hyphenator object. - void hyphenateSoft(std::vector* result, const uint16_t* word, size_t len); + // Note: nullptr is valid input, in which case the hyphenator only processes soft hyphens + static Hyphenator* loadBinary(const uint8_t* patternData); + +private: + // apply soft hyphens only, ignoring patterns + void hyphenateSoft(uint8_t* result, const uint16_t* word, size_t len); + + // try looking up word in alphabet table, return false if any code units fail to map + // Note that this methor writes len+2 entries into alpha_codes (including start and stop) + bool alphabetLookup(uint16_t* alpha_codes, const uint16_t* word, size_t len); + + // calculate hyphenation from patterns, assuming alphabet lookup has already been done + void hyphenateFromCodes(uint8_t* result, const uint16_t* codes, size_t len); // TODO: these should become parameters, as they might vary by locale, screen size, and // possibly explicit user control. static const int MIN_PREFIX = 2; static const int MIN_SUFFIX = 3; - Trie root; + // See also LONGEST_HYPHENATED_WORD in LineBreaker.cpp. Here the constant is used so + // that temporary buffers can be stack-allocated without waste, which is a slightly + // different use case. It measures UTF-16 code units. + static const size_t MAX_HYPHENATED_SIZE = 64; + + const uint8_t* patternData; + + // accessors for binary data + const Header* getHeader() const { + return reinterpret_cast(patternData); + } + }; } // namespace android -#endif // MINIKIN_HYPHENATOR_H \ No newline at end of file +#endif // MINIKIN_HYPHENATOR_H diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 873f279f0c9..7558f83aa56 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -48,3 +48,28 @@ LOCAL_SHARED_LIBRARIES := \ libutils include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) + +LOCAL_MODULE := libminikin +LOCAL_MODULE_TAGS := optional +LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include +LOCAL_SRC_FILES := $(minikin_src_files) +LOCAL_C_INCLUDES := $(minikin_c_includes) +LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) + +include $(BUILD_STATIC_LIBRARY) + +include $(CLEAR_VARS) + +# Reduced library (currently just hyphenation) for host + +LOCAL_MODULE := libminikin_host +LOCAL_MODULE_TAGS := optional +LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include +LOCAL_C_INCLUDES := $(minikin_c_includes) +LOCAL_SHARED_LIBRARIES := liblog libicuuc-host + +LOCAL_SRC_FILES := Hyphenator.cpp + +include $(BUILD_HOST_STATIC_LIBRARY) diff --git a/engine/src/flutter/libs/minikin/Hyphenator.cpp b/engine/src/flutter/libs/minikin/Hyphenator.cpp index 3eb151b9e02..c5eb60b8e50 100644 --- a/engine/src/flutter/libs/minikin/Hyphenator.cpp +++ b/engine/src/flutter/libs/minikin/Hyphenator.cpp @@ -34,130 +34,202 @@ namespace android { static const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; -void Hyphenator::addPattern(const uint16_t* pattern, size_t size) { - vector word; - vector result; +// The following are structs that correspond to tables inside the hyb file format - // start by parsing the Liang-format pattern into a word and a result vector, the - // vector right-aligned but without leading zeros. Examples: - // a1bc2d -> abcd [1, 0, 2, 0] - // abc1 -> abc [1] - // 1a2b3c4d5 -> abcd [1, 2, 3, 4, 5] - bool lastWasLetter = false; - bool haveSeenNumber = false; - for (size_t i = 0; i < size; i++) { - uint16_t c = pattern[i]; - if (isdigit(c)) { - result.push_back(c - '0'); - lastWasLetter = false; - haveSeenNumber = true; - } else { - word.push_back(c); - if (lastWasLetter && haveSeenNumber) { - result.push_back(0); - } - lastWasLetter = true; - } - } - if (lastWasLetter) { - result.push_back(0); - } - Trie* t = &root; - for (size_t i = 0; i < word.size(); i++) { - t = &t->succ[word[i]]; - } - t->result = result; -} +struct AlphabetTable0 { + uint32_t version; + uint32_t min_codepoint; + uint32_t max_codepoint; + uint8_t data[1]; // actually flexible array, size is known at runtime +}; -// If any soft hyphen is present in the word, use soft hyphens to decide hyphenation, -// as recommended in UAX #14 (Use of Soft Hyphen) -void Hyphenator::hyphenateSoft(vector* result, const uint16_t* word, size_t len) { - (*result)[0] = 0; - for (size_t i = 1; i < len; i++) { - (*result)[i] = word[i - 1] == CHAR_SOFT_HYPHEN; +struct AlphabetTable1 { + uint32_t version; + uint32_t n_entries; + uint32_t data[1]; // actually flexible array, size is known at runtime + + static uint32_t codepoint(uint32_t entry) { return entry >> 11; } + static uint32_t value(uint32_t entry) { return entry & 0x7ff; } +}; + +struct Trie { + uint32_t version; + uint32_t char_mask; + uint32_t link_shift; + uint32_t link_mask; + uint32_t pattern_shift; + uint32_t n_entries; + uint32_t data[1]; // actually flexible array, size is known at runtime +}; + +struct Pattern { + uint32_t version; + uint32_t n_entries; + uint32_t pattern_offset; + uint32_t pattern_size; + uint32_t data[1]; // actually flexible array, size is known at runtime + + // accessors + static uint32_t len(uint32_t entry) { return entry >> 26; } + static uint32_t shift(uint32_t entry) { return (entry >> 20) & 0x3f; } + const uint8_t* buf(uint32_t entry) const { + return reinterpret_cast(this) + pattern_offset + (entry & 0xfffff); } +}; + +struct Header { + uint32_t magic; + uint32_t version; + uint32_t alphabet_offset; + uint32_t trie_offset; + uint32_t pattern_offset; + uint32_t file_size; + + // accessors + const uint8_t* bytes() const { return reinterpret_cast(this); } + uint32_t alphabetVersion() const { + return *reinterpret_cast(bytes() + alphabet_offset); + } + const AlphabetTable0* alphabetTable0() const { + return reinterpret_cast(bytes() + alphabet_offset); + } + const AlphabetTable1* alphabetTable1() const { + return reinterpret_cast(bytes() + alphabet_offset); + } + const Trie* trieTable() const { + return reinterpret_cast(bytes() + trie_offset); + } + const Pattern* patternTable() const { + return reinterpret_cast(bytes() + pattern_offset); + } +}; + +Hyphenator* Hyphenator::loadBinary(const uint8_t* patternData) { + Hyphenator* result = new Hyphenator; + result->patternData = patternData; + return result; } void Hyphenator::hyphenate(vector* result, const uint16_t* word, size_t len) { result->clear(); result->resize(len); - if (len < MIN_PREFIX + MIN_SUFFIX) return; - size_t maxOffset = len - MIN_SUFFIX + 1; - for (size_t i = 0; i < len + 1; i++) { - const Trie* node = &root; - for (size_t j = i; j < len + 2; j++) { - uint16_t c; - if (j == 0 || j == len + 1) { - c = '.'; // word boundary character in pattern data files - } else { - c = word[j - 1]; - if (c == CHAR_SOFT_HYPHEN) { - hyphenateSoft(result, word, len); - return; - } - // TODO: This uses ICU's simple character to character lowercasing, which ignores - // the locale, and ignores cases when lowercasing a character results in more than - // one character. It should be fixed to consider the locale (in order for it to work - // correctly for Turkish and Azerbaijani), as well as support one-to-many, and - // many-to-many case conversions (including non-BMP cases). - if (c < 0x00C0) { // U+00C0 is the lowest uppercase non-ASCII character - // Convert uppercase ASCII to lowercase ASCII, but keep other characters as-is - if (0x0041 <= c && c <= 0x005A) { - c += 0x0020; - } - } else { - c = u_tolower(c); - } + const size_t paddedLen = len + 2; // start and stop code each count for 1 + if (patternData != nullptr && + (int)len >= MIN_PREFIX + MIN_SUFFIX && paddedLen <= MAX_HYPHENATED_SIZE) { + uint16_t alpha_codes[MAX_HYPHENATED_SIZE]; + if (alphabetLookup(alpha_codes, word, len)) { + hyphenateFromCodes(result->data(), alpha_codes, paddedLen); + return; + } + // TODO: try NFC normalization + // TODO: handle non-BMP Unicode (requires remapping of offsets) + } + hyphenateSoft(result->data(), word, len); +} + +// If any soft hyphen is present in the word, use soft hyphens to decide hyphenation, +// as recommended in UAX #14 (Use of Soft Hyphen) +void Hyphenator::hyphenateSoft(uint8_t* result, const uint16_t* word, size_t len) { + result[0] = 0; + for (size_t i = 1; i < len; i++) { + result[i] = word[i - 1] == CHAR_SOFT_HYPHEN; + } +} + +bool Hyphenator::alphabetLookup(uint16_t* alpha_codes, const uint16_t* word, size_t len) { + const Header* header = getHeader(); + // TODO: check header magic + uint32_t alphabetVersion = header->alphabetVersion(); + if (alphabetVersion == 0) { + const AlphabetTable0* alphabet = header->alphabetTable0(); + uint32_t min_codepoint = alphabet->min_codepoint; + uint32_t max_codepoint = alphabet->max_codepoint; + alpha_codes[0] = 0; // word start + for (size_t i = 0; i < len; i++) { + uint16_t c = word[i]; + if (c < min_codepoint || c >= max_codepoint) { + return false; } - auto search = node->succ.find(c); - if (search != node->succ.end()) { - node = &search->second; + uint8_t code = alphabet->data[c - min_codepoint]; + if (code == 0) { + return false; + } + alpha_codes[i + 1] = code; + } + alpha_codes[len + 1] = 0; // word termination + return true; + } else if (alphabetVersion == 1) { + const AlphabetTable1* alphabet = header->alphabetTable1(); + size_t n_entries = alphabet->n_entries; + const uint32_t* begin = alphabet->data; + const uint32_t* end = begin + n_entries; + alpha_codes[0] = 0; + for (size_t i = 0; i < len; i++) { + uint16_t c = word[i]; + auto p = std::lower_bound(begin, end, c << 11); + if (p == end) { + return false; + } + uint32_t entry = *p; + if (AlphabetTable1::codepoint(entry) != c) { + return false; + } + alpha_codes[i + 1] = AlphabetTable1::value(entry); + } + alpha_codes[len + 1] = 0; + return true; + } + return false; +} + +/** + * Internal implementation, after conversion to codes. All case folding and normalization + * has been done by now, and all characters have been found in the alphabet. + * Note: len here is the padded length including 0 codes at start and end. + **/ +void Hyphenator::hyphenateFromCodes(uint8_t* result, const uint16_t* codes, size_t len) { + const Header* header = getHeader(); + const Trie* trie = header->trieTable(); + const Pattern* pattern = header->patternTable(); + uint32_t char_mask = trie->char_mask; + uint32_t link_shift = trie->link_shift; + uint32_t link_mask = trie->link_mask; + uint32_t pattern_shift = trie->pattern_shift; + size_t maxOffset = len - MIN_SUFFIX - 1; + for (size_t i = 0; i < len - 1; i++) { + uint32_t node = 0; // index into Trie table + for (size_t j = i; j < len; j++) { + uint16_t c = codes[j]; + uint32_t entry = trie->data[node + c]; + if ((entry & char_mask) == c) { + node = (entry & link_mask) >> link_shift; } else { break; } - if (!node->result.empty()) { - int resultLen = node->result.size(); - int offset = j + 1 - resultLen; + uint32_t pat_ix = trie->data[node] >> pattern_shift; + // pat_ix contains a 3-tuple of length, shift (number of trailing zeros), and an offset + // into the buf pool. This is the pattern for the substring (i..j) we just matched, + // which we combine (via point-wise max) into the result vector. + if (pat_ix != 0) { + uint32_t pat_entry = pattern->data[pat_ix]; + int pat_len = Pattern::len(pat_entry); + int pat_shift = Pattern::shift(pat_entry); + const uint8_t* pat_buf = pattern->buf(pat_entry); + int offset = j + 1 - (pat_len + pat_shift); + // offset is the index within result that lines up with the start of pat_buf int start = std::max(MIN_PREFIX - offset, 0); - int end = std::min(resultLen, (int)maxOffset - offset); - // TODO performance: this inner loop can profitably be optimized + int end = std::min(pat_len, (int)maxOffset - offset); for (int k = start; k < end; k++) { - (*result)[offset + k] = std::max((*result)[offset + k], node->result[k]); + result[offset + k] = std::max(result[offset + k], pat_buf[k]); } -#if 0 - // debug printing of matched patterns - std::string dbg; - for (size_t k = i; k <= j + 1; k++) { - int off = k - j - 2 + resultLen; - if (off >= 0 && node->result[off] != 0) { - dbg.push_back((char)('0' + node->result[off])); - } - if (k < j + 1) { - uint16_t c = (k == 0 || k == len + 1) ? '.' : word[k - 1]; - dbg.push_back((char)c); - } - } - ALOGD("%d:%d %s", i, j, dbg.c_str()); -#endif } } } // Since the above calculation does not modify values outside // [MIN_PREFIX, len - MIN_SUFFIX], they are left as 0. for (size_t i = MIN_PREFIX; i < maxOffset; i++) { - (*result)[i] &= 1; + result[i] &= 1; } } -Hyphenator* Hyphenator::load(const uint16_t *patternData, size_t size) { - Hyphenator* result = new Hyphenator; - for (size_t i = 0; i < size; i++) { - size_t end = i; - while (patternData[end] != '\n') end++; - result->addPattern(patternData + i, end - i); - i = end; - } - return result; -} - } // namespace android diff --git a/engine/src/flutter/tools/mk_hyb_file.py b/engine/src/flutter/tools/mk_hyb_file.py new file mode 100755 index 00000000000..c078454e6b2 --- /dev/null +++ b/engine/src/flutter/tools/mk_hyb_file.py @@ -0,0 +1,567 @@ +#!/usr/bin/env python + +# Copyright (C) 2015 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. + +""" +Convert hyphen files in standard TeX format (a trio of pat, chr, and hyp) +into binary format. See doc/hyb_file_format.md for more information. + +Usage: mk_hyb_file.py [-v] hyph-foo.pat.txt hyph-foo.hyb + +Optional -v parameter turns on verbose debugging. + +""" + +from __future__ import print_function + +import io +import sys +import struct +import math +import getopt + + +VERBOSE = False + + +if sys.version_info[0] >= 3: + def unichr(x): + return chr(x) + + +# number of bits required to represent numbers up to n inclusive +def num_bits(n): + return 1 + int(math.log(n, 2)) if n > 0 else 0 + + +class Node: + + def __init__(self): + self.succ = {} + self.res = None + self.fsm_pat = None + self.fail = None + + +# List of free slots, implemented as doubly linked list +class Freelist: + + def __init__(self): + self.first = None + self.last = None + self.pred = [] + self.succ = [] + + def grow(self): + this = len(self.pred) + self.pred.append(self.last) + self.succ.append(None) + if self.last is None: + self.first = this + else: + self.succ[self.last] = this + self.last = this + + def next(self, cursor): + if cursor == 0: + cursor = self.first + if cursor is None: + self.grow() + result = self.last + else: + result = cursor + return result, self.succ[result] + + def is_free(self, ix): + while ix >= len(self.pred): + self.grow() + return self.pred[ix] != -1 + + def use(self, ix): + if self.pred[ix] is None: + self.first = self.succ[ix] + else: + self.succ[self.pred[ix]] = self.succ[ix] + if self.succ[ix] is None: + self.last = self.pred[ix] + else: + self.pred[self.succ[ix]] = self.pred[ix] + if self.pred[ix] == -1: + assert self.pred[ix] != -1, 'double free!' + self.pred[ix] = -1 + + +def combine(a, b): + if a is None: return b + if b is None: return a + if len(b) < len(a): a, b = b, a + res = b[:len(b) - len(a)] + for i in range(len(a)): + res.append(max(a[i], b[i + len(b) - len(a)])) + return res + + +def trim(pattern): + for ix in range(len(pattern)): + if pattern[ix] != 0: + return pattern[ix:] + + +def pat_to_binary(pattern): + return b''.join(struct.pack('B', x) for x in pattern) + + +class Hyph: + + def __init__(self): + self.root = Node() + self.root.str = '' + self.node_list = [self.root] + + # Add a pattern (word fragment with numeric codes, such as ".ad4der") + def add_pat(self, pat): + lastWasLetter = False + haveSeenNumber = False + result = [] + word = '' + for c in pat: + if c.isdigit(): + result.append(int(c)) + lastWasLetter = False + haveSeenNumber = True + else: + word += c + if lastWasLetter and haveSeenNumber: + result.append(0) + lastWasLetter = True + if lastWasLetter: + result.append(0) + + self.add_word_res(word, result) + + # Add an exception (word with hyphens, such as "ta-ble") + def add_exception(self, hyph_word): + res = [] + word = ['.'] + need_10 = False + for c in hyph_word: + if c == '-': + res.append(11) + need_10 = False + else: + if need_10: + res.append(10) + word.append(c) + need_10 = True + word.append('.') + res.append(0) + res.append(0) + if VERBOSE: + print(word, res) + self.add_word_res(''.join(word), res) + + def add_word_res(self, word, result): + if VERBOSE: + print(word, result) + + t = self.root + s = '' + for c in word: + s += c + if c not in t.succ: + new_node = Node() + new_node.str = s + self.node_list.append(new_node) + t.succ[c] = new_node + t = t.succ[c] + t.res = result + + def pack(self, node_list, ch_map, use_node=False): + size = 0 + self.node_map = {} + nodes = Freelist() + edges = Freelist() + edge_start = 1 if use_node else 0 + for node in node_list: + succ = sorted([ch_map[c] + edge_start for c in node.succ.keys()]) + if len(succ): + cursor = 0 + while True: + edge_ix, cursor = edges.next(cursor) + ix = edge_ix - succ[0] + if (ix >= 0 and nodes.is_free(ix) and + all(edges.is_free(ix + s) for s in succ) and + ((not use_node) or edges.is_free(ix))): + break + elif use_node: + ix, _ = edges.next(0) + nodes.is_free(ix) # actually don't need nodes at all when use_node, + # but keep it happy + else: + ix, _ = nodes.next(0) + node.ix = ix + self.node_map[ix] = node + nodes.use(ix) + size = max(size, ix) + if use_node: + edges.use(ix) + for s in succ: + edges.use(ix + s) + size += max(ch_map.values()) + 1 + return size + + # return list of nodes in bfs order + def bfs(self, ch_map): + result = [self.root] + ix = 0 + while ix < len(result): + node = result[ix] + node.bfs_ix = ix + mapped = {} + for c, next in node.succ.items(): + assert ch_map[c] not in mapped, 'duplicate edge ' + node.str + ' ' + hex(ord(c)) + mapped[ch_map[c]] = next + for i in sorted(mapped.keys()): + result.append(mapped[i]) + ix += 1 + self.bfs_order = result + return result + + # suffix compression - convert the trie into an acyclic digraph, merging nodes when + # the subtries are identical + def dedup(self): + uniques = [] + dupmap = {} + dedup_ix = [0] * len(self.bfs_order) + for ix in reversed(range(len(self.bfs_order))): + # construct string representation of node + node = self.bfs_order[ix] + if node.res is None: + s = '' + else: + s = ''.join(str(c) for c in node.res) + for c in sorted(node.succ.keys()): + succ = node.succ[c] + s += ' ' + c + str(dedup_ix[succ.bfs_ix]) + if s in dupmap: + dedup_ix[ix] = dupmap[s] + else: + uniques.append(node) + dedup_ix[ix] = ix + dupmap[s] = dedup_ix[ix] + uniques.reverse() + print(len(uniques), 'unique nodes,', len(self.bfs_order), 'total') + return dedup_ix, uniques + + +# load the ".pat" file, which contains patterns such as a1b2c3 +def load(fn): + hyph = Hyph() + with io.open(fn, encoding='UTF-8') as f: + for l in f: + pat = l.strip() + hyph.add_pat(pat) + return hyph + + +# load the ".chr" file, which contains the alphabet and case pairs, eg "aA", "bB" etc. +def load_chr(fn): + ch_map = {'.': 0} + with io.open(fn, encoding='UTF-8') as f: + for i, l in enumerate(f): + l = l.strip() + if len(l) > 2: + # lowercase maps to multi-character uppercase sequence, ignore uppercase for now + l = l[:1] + else: + assert len(l) == 2, 'expected 2 chars in chr' + for c in l: + ch_map[c] = i + 1 + return ch_map + + +# load exceptions with explicit hyphens +def load_hyp(hyph, fn): + with io.open(fn, encoding='UTF-8') as f: + for l in f: + hyph.add_exception(l.strip()) + + +def generate_header(alphabet, trie, pattern): + alphabet_off = 6 * 4 + trie_off = alphabet_off + len(alphabet) + pattern_off = trie_off + len(trie) + file_size = pattern_off + len(pattern) + data = [0x62ad7968, 0, alphabet_off, trie_off, pattern_off, file_size] + return struct.pack('<6I', *data) + + +def generate_alphabet(ch_map): + ch_map = ch_map.copy() + del ch_map['.'] + min_ch = ord(min(ch_map)) + max_ch = ord(max(ch_map)) + if max_ch - min_ch < 1024 and max(ch_map.values()) < 256: + # generate format 0 + data = [0] * (max_ch - min_ch + 1) + for c, val in ch_map.items(): + data[ord(c) - min_ch] = val + result = [struct.pack('<3I', 0, min_ch, max_ch + 1)] + for b in data: + result.append(struct.pack('> 26 + pat_shift = (entry >> 20) & 0x1f + offset = pattern_offset + (entry & 0xfffff) + return pattern_data[offset: offset + pat_len] + b'\0' * pat_shift + + +def traverse_trie(ix, s, trie_data, ch_map, pattern_data, patterns, exceptions): + (char_mask, link_shift, link_mask, pattern_shift) = struct.unpack('<4I', trie_data[4:20]) + node_entry = struct.unpack('> pattern_shift + if pattern: + result = [] + is_exception = False + pat = get_pattern(pattern_data, pattern) + for i in range(len(s) + 1): + pat_off = i - 1 + len(pat) - len(s) + if pat_off < 0: + code = 0 + else: + code = struct.unpack('B', pat[pat_off : pat_off + 1])[0] + if 1 <= code <= 9: + result.append('%d' % code) + elif code == 10: + is_exception = True + elif code == 11: + result.append('-') + is_exception = True + else: + assert code == 0, 'unexpected code' + if i < len(s): + result.append(s[i]) + pat_str = ''.join(result) + #print(`pat_str`, `pat`) + if is_exception: + assert pat_str[0] == '.', "expected leading '.'" + assert pat_str[-1] == '.', "expected trailing '.'" + exceptions.append(pat_str[1:-1]) # strip leading and trailing '.' + else: + patterns.append(pat_str) + for ch in ch_map: + edge_entry = struct.unpack('> link_shift + if link != 0 and ch == (edge_entry & char_mask): + sch = s + ch_map[ch] + traverse_trie(link, sch, trie_data, ch_map, pattern_data, patterns, exceptions) + + +# Verify the generated binary file by reconstructing the textual representations +# from the binary hyb file, then checking that they're identical (mod the order of +# lines within the file, which is irrelevant). This function makes assumptions that +# are stronger than absolutely necessary (in particular, that the patterns are in +# lowercase as defined by python islower). +def verify_hyb_file(hyb_fn, pat_fn, chr_fn, hyp_fn): + with open(hyb_fn, 'rb') as f: + hyb_data = f.read() + header = hyb_data[0: 6 * 4] + (magic, version, alphabet_off, trie_off, pattern_off, file_size) = struct.unpack('<6I', header) + alphabet_data = hyb_data[alphabet_off:trie_off] + trie_data = hyb_data[trie_off:pattern_off] + pattern_data = hyb_data[pattern_off:file_size] + + # reconstruct alphabet table + alphabet_version = struct.unpack('> 11)] = entry & 0x7ff + + ch_map, reconstructed_chr = map_to_chr(alphabet_map) + + # EXCEPTION for Armenian (hy), we don't really deal with the uppercase form of U+0587 + if u'\u0587' in reconstructed_chr: + reconstructed_chr.remove(u'\u0587') + reconstructed_chr.append(u'\u0587\u0535\u0552') + + assert verify_file_sorted(reconstructed_chr, chr_fn), 'alphabet table not verified' + + # reconstruct trie + patterns = [] + exceptions = [] + traverse_trie(0, '', trie_data, ch_map, pattern_data, patterns, exceptions) + assert verify_file_sorted(patterns, pat_fn), 'pattern table not verified' + assert verify_file_sorted(exceptions, hyp_fn), 'exception table not verified' + + +def main(): + global VERBOSE + try: + opts, args = getopt.getopt(sys.argv[1:], 'v') + except getopt.GetoptError as err: + print(str(err)) + sys.exit(1) + for o, _ in opts: + if o == '-v': + VERBOSE = True + pat_fn, out_fn = args + hyph = load(pat_fn) + if pat_fn.endswith('.pat.txt'): + chr_fn = pat_fn[:-8] + '.chr.txt' + ch_map = load_chr(chr_fn) + hyp_fn = pat_fn[:-8] + '.hyp.txt' + load_hyp(hyph, hyp_fn) + generate_hyb_file(hyph, ch_map, out_fn) + verify_hyb_file(out_fn, pat_fn, chr_fn, hyp_fn) + +if __name__ == '__main__': + main() From 7635ac1324ebe58f21adc904185f446cec11a97d Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 30 Sep 2015 23:26:54 -0700 Subject: [PATCH 110/364] Explicitly set utf-8 encoding for hyb file verification Not all platforms default to UTF-8 encoding, so we set it explicitly. This patch should fix build breakages resulting from failed verification of binary hyb files for hyphenation patterns. Bug: 24570591 Change-Id: I65ac4536d3436586c2633e2b57554fc6ff16d3a8 (cherry picked from commit 179d763488f9e4ddcc94e3e844bfb0d796974f97) --- engine/src/flutter/tools/mk_hyb_file.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/flutter/tools/mk_hyb_file.py b/engine/src/flutter/tools/mk_hyb_file.py index c078454e6b2..978c082b279 100755 --- a/engine/src/flutter/tools/mk_hyb_file.py +++ b/engine/src/flutter/tools/mk_hyb_file.py @@ -416,7 +416,7 @@ def generate_hyb_file(hyph, ch_map, hyb_fn): # Verify that the file contains the same lines as the lines argument, in arbitrary order def verify_file_sorted(lines, fn): - file_lines = [l.strip() for l in io.open(fn)] + file_lines = [l.strip() for l in io.open(fn, encoding='UTF-8')] line_set = set(lines) file_set = set(file_lines) if line_set == file_set: From 4f26d114368939d06989de1e54c65227fdbfa843 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 14 Oct 2015 19:34:29 -0700 Subject: [PATCH 111/364] Complete half-done cherry-picking of Android.mk. DO NOT MERGE The previous commit, 9036c194b04f921f35a7b7c064f88bba565c63b3, was incompletely cherry-picked. This adds the missing parts. Bug: 24570591 Change-Id: I1097c60587fb8a88cfe6b8ffed5b1689d9bdd429 --- engine/src/flutter/libs/minikin/Android.mk | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 7558f83aa56..c3e70db2675 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -16,7 +16,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_SRC_FILES := \ +minikin_src_files := \ AnalyzeStyle.cpp \ CmapCoverage.cpp \ FontCollection.cpp \ @@ -31,14 +31,12 @@ LOCAL_SRC_FILES := \ MinikinFontFreeType.cpp \ SparseBitSet.cpp -LOCAL_MODULE := libminikin - -LOCAL_C_INCLUDES += \ +minikin_c_includes += \ external/harfbuzz_ng/src \ external/freetype/include \ frameworks/minikin/include -LOCAL_SHARED_LIBRARIES := \ +minikin_shared_libraries := \ libharfbuzz_ng \ libft2 \ liblog \ @@ -47,6 +45,12 @@ LOCAL_SHARED_LIBRARIES := \ libicuuc \ libutils +LOCAL_MODULE := libminikin +LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include +LOCAL_SRC_FILES := $(minikin_src_files) +LOCAL_C_INCLUDES := $(minikin_c_includes) +LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) + include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) From aaec3837bf0355869f1da14e1aacf2b29100a309 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 13 Oct 2015 19:35:05 +0900 Subject: [PATCH 112/364] Remove MinikinFont::GetGlyph interface. MinikinFont:GetGlyph is no longer used. No behavior chnages are expected with this CL. Change-Id: I13398503841ac06f930b04815017d4b33338efa1 --- engine/src/flutter/include/minikin/MinikinFont.h | 2 -- .../src/flutter/include/minikin/MinikinFontFreeType.h | 2 -- .../src/flutter/libs/minikin/MinikinFontFreeType.cpp | 6 ------ engine/src/flutter/sample/MinikinSkia.cpp | 11 ----------- engine/src/flutter/sample/MinikinSkia.h | 4 +--- engine/src/flutter/tests/HbFaceCacheTest.cpp | 5 ----- engine/src/flutter/tests/MinikinFontForTest.cpp | 5 ----- engine/src/flutter/tests/MinikinFontForTest.h | 1 - 8 files changed, 1 insertion(+), 35 deletions(-) diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 7f65cd7b0aa..2ad2151a311 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -96,8 +96,6 @@ class MinikinFontFreeType; class MinikinFont : public MinikinRefCounted { public: - virtual bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const = 0; - virtual float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const = 0; diff --git a/engine/src/flutter/include/minikin/MinikinFontFreeType.h b/engine/src/flutter/include/minikin/MinikinFontFreeType.h index 13a513982b3..a957d124c77 100644 --- a/engine/src/flutter/include/minikin/MinikinFontFreeType.h +++ b/engine/src/flutter/include/minikin/MinikinFontFreeType.h @@ -42,8 +42,6 @@ public: ~MinikinFontFreeType(); - bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const; - float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const; diff --git a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp index 972f3f1d14f..cbeed615932 100644 --- a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp @@ -38,12 +38,6 @@ MinikinFontFreeType::~MinikinFontFreeType() { FT_Done_Face(mTypeface); } -bool MinikinFontFreeType::GetGlyph(uint32_t codepoint, uint32_t *glyph) const { - FT_UInt glyph_index = FT_Get_Char_Index(mTypeface, codepoint); - *glyph = glyph_index; - return !!glyph_index; -} - float MinikinFontFreeType::GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const { FT_Set_Pixel_Sizes(mTypeface, 0, paint.size); diff --git a/engine/src/flutter/sample/MinikinSkia.cpp b/engine/src/flutter/sample/MinikinSkia.cpp index 8b499d81312..feda8adff19 100644 --- a/engine/src/flutter/sample/MinikinSkia.cpp +++ b/engine/src/flutter/sample/MinikinSkia.cpp @@ -14,17 +14,6 @@ MinikinFontSkia::~MinikinFontSkia() { SkSafeUnref(mTypeface); } -bool MinikinFontSkia::GetGlyph(uint32_t codepoint, uint32_t *glyph) const { - SkPaint paint; - paint.setTypeface(mTypeface); - paint.setTextEncoding(SkPaint::kUTF32_TextEncoding); - uint16_t glyph16; - paint.textToGlyphs(&codepoint, sizeof(codepoint), &glyph16); - *glyph = glyph16; - //printf("glyph for U+%04x = %d\n", codepoint, glyph16); - return !!glyph; -} - static void MinikinFontSkia_SetSkiaPaint(SkTypeface* typeface, SkPaint* skPaint, const MinikinPaint& paint) { skPaint->setTypeface(typeface); skPaint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); diff --git a/engine/src/flutter/sample/MinikinSkia.h b/engine/src/flutter/sample/MinikinSkia.h index fca6ca23228..25ac1b0c081 100644 --- a/engine/src/flutter/sample/MinikinSkia.h +++ b/engine/src/flutter/sample/MinikinSkia.h @@ -6,8 +6,6 @@ public: ~MinikinFontSkia(); - bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const; - float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const; @@ -26,4 +24,4 @@ private: }; -} // namespace android \ No newline at end of file +} // namespace android diff --git a/engine/src/flutter/tests/HbFaceCacheTest.cpp b/engine/src/flutter/tests/HbFaceCacheTest.cpp index 1b630738516..fbaf0eab150 100644 --- a/engine/src/flutter/tests/HbFaceCacheTest.cpp +++ b/engine/src/flutter/tests/HbFaceCacheTest.cpp @@ -35,11 +35,6 @@ public: MockMinikinFont(int32_t id) : mId(id) { } - virtual bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const { - LOG_ALWAYS_FATAL("MockMinikinFont::GetGlyph is not implemented."); - return false; - } - virtual float GetHorizontalAdvance( uint32_t glyph_id, const MinikinPaint &paint) const { LOG_ALWAYS_FATAL("MockMinikinFont::GetHorizontalAdvance is not implemented."); diff --git a/engine/src/flutter/tests/MinikinFontForTest.cpp b/engine/src/flutter/tests/MinikinFontForTest.cpp index 2d29e805aae..033241e26dc 100644 --- a/engine/src/flutter/tests/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/MinikinFontForTest.cpp @@ -29,11 +29,6 @@ MinikinFontForTest::MinikinFontForTest(const std::string& font_path) : mFontPath MinikinFontForTest::~MinikinFontForTest() { } -bool MinikinFontForTest::GetGlyph(uint32_t codepoint, uint32_t *glyph) const { - LOG_ALWAYS_FATAL("MinikinFontForTest::GetGlyph is not yet implemented"); - return false; -} - float MinikinFontForTest::GetHorizontalAdvance( uint32_t glyph_id, const android::MinikinPaint &paint) const { LOG_ALWAYS_FATAL("MinikinFontForTest::GetHorizontalAdvance is not yet implemented"); diff --git a/engine/src/flutter/tests/MinikinFontForTest.h b/engine/src/flutter/tests/MinikinFontForTest.h index ecebb7e2b81..5738666f77d 100644 --- a/engine/src/flutter/tests/MinikinFontForTest.h +++ b/engine/src/flutter/tests/MinikinFontForTest.h @@ -24,7 +24,6 @@ public: ~MinikinFontForTest(); // MinikinFont overrides. - bool GetGlyph(uint32_t codepoint, uint32_t *glyph) const; float GetHorizontalAdvance(uint32_t glyph_id, const android::MinikinPaint &paint) const; void GetBounds(android::MinikinRect* bounds, uint32_t glyph_id, const android::MinikinPaint& paint) const; From 2a099196e614d9b8be29b7eed60d7bf0ea54f750 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 1 Oct 2015 15:59:38 +0900 Subject: [PATCH 113/364] Support Variation Selector in font selection. This CL contains the following changes: - Add a variation selector argument into getFamilyForChar to be able to select fonts which support variation selector. - In case no fonts support the codepoint and variation selector pair, add a fallback rule which selects font family with ignoring variation selector. - Change FontCollection::itemize to not change the font family immediately preceding a variation selector. - Introduce unit tests for variation selectors. With this CL, TextView can render the variation selectors correctly. Bug: 11256006 Change-Id: I22ce0e9eadc941f84e3a9b23462f194e51dd7180 --- .../flutter/include/minikin/FontCollection.h | 2 +- .../flutter/libs/minikin/FontCollection.cpp | 79 ++++-- .../tests/FontCollectionItemizeTest.cpp | 250 +++++++++++++++++- 3 files changed, 306 insertions(+), 25 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index c4daf98fa68..ca24e386a03 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -60,7 +60,7 @@ private: size_t end; }; - FontFamily* getFamilyForChar(uint32_t ch, FontLanguage lang, int variant) const; + FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, FontLanguage lang, int variant) const; // static for allocating unique id's static uint32_t sNextId; diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 36d47ded9d5..4c0070c2b1e 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -103,7 +103,7 @@ FontCollection::~FontCollection() { // 3. If a font matches just language, it gets a score of 2. // 4. Matching the "compact" or "elegant" variant adds one to the score. // 5. Highest score wins, with ties resolved to the first font. -FontFamily* FontCollection::getFamilyForChar(uint32_t ch, +FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, FontLanguage lang, int variant) const { if (ch >= mMaxChar) { return NULL; @@ -112,11 +112,11 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, #ifdef VERBOSE_DEBUG ALOGD("querying range %d:%d\n", range.start, range.end); #endif - FontFamily* bestFamily = NULL; + FontFamily* bestFamily = nullptr; int bestScore = -1; for (size_t i = range.start; i < range.end; i++) { FontFamily* family = mFamilyVec[i]; - if (family->getCoverage()->get(ch)) { + if (vs == 0 ? family->getCoverage()->get(ch) : family->hasVariationSelector(ch, vs)) { // First font family in collection always matches if (mFamilies[0] == family) { return family; @@ -131,7 +131,13 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, } } } - if (bestFamily == NULL && !mFamilyVec.empty()) { + if (bestFamily == nullptr && vs != 0) { + // If no fonts support the codepoint and variation selector pair, + // fallback to select a font family that supports just the base + // character, ignoring the variation selector. + return getFamilyForChar(ch, 0, lang, variant); + } + if (bestFamily == nullptr && !mFamilyVec.empty()) { UErrorCode errorCode = U_ZERO_ERROR; const UNormalizer2* normalizer = unorm2_getNFDInstance(&errorCode); if (U_SUCCESS(errorCode)) { @@ -140,7 +146,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, if (U_SUCCESS(errorCode) && len > 0) { int off = 0; U16_NEXT_UNSAFE(decomposed, off, ch); - return getFamilyForChar(ch, lang, variant); + return getFamilyForChar(ch, vs, lang, variant); } } bestFamily = mFamilies[0]; @@ -167,35 +173,61 @@ static bool isStickyWhitelisted(uint32_t c) { return false; } +static bool isVariationSelector(uint32_t c) { + return (0xFE00 <= c && c <= 0xFE0F) || (0xE0100 <= c && c <= 0xE01EF); +} + void FontCollection::itemize(const uint16_t *string, size_t string_size, FontStyle style, vector* result) const { FontLanguage lang = style.getLanguage(); int variant = style.getVariant(); FontFamily* lastFamily = NULL; Run* run = NULL; - int nShorts; - for (size_t i = 0; i < string_size; i += nShorts) { - nShorts = 1; - uint32_t ch = string[i]; - // sigh, decode UTF-16 by hand here - if ((ch & 0xfc00) == 0xd800) { - if ((i + 1) < string_size) { - ch = 0x10000 + ((ch & 0x3ff) << 10) + (string[i + 1] & 0x3ff); - nShorts = 2; + + if (string_size == 0) { + return; + } + + const uint32_t kEndOfString = 0xFFFFFFFF; + + uint32_t nextCh = 0; + uint32_t prevCh = 0; + size_t nextUtf16Pos = 0; + size_t readLength = 0; + U16_NEXT(string, readLength, string_size, nextCh); + + do { + const uint32_t ch = nextCh; + const size_t utf16Pos = nextUtf16Pos; + nextUtf16Pos = readLength; + if (readLength < string_size) { + U16_NEXT(string, readLength, string_size, nextCh); + } else { + nextCh = kEndOfString; + } + + bool shouldContinueRun = false; + if (lastFamily != nullptr) { + if (isStickyWhitelisted(ch)) { + // Continue using existing font as long as it has coverage and is whitelisted + shouldContinueRun = lastFamily->getCoverage()->get(ch); + } else if (isVariationSelector(ch)) { + // Always continue if the character is a variation selector. + shouldContinueRun = true; } } - // Continue using existing font as long as it has coverage and is whitelisted - if (lastFamily == NULL - || !(isStickyWhitelisted(ch) && lastFamily->getCoverage()->get(ch))) { - FontFamily* family = getFamilyForChar(ch, lang, variant); - if (i == 0 || family != lastFamily) { - size_t start = i; + + if (!shouldContinueRun) { + FontFamily* family = + getFamilyForChar(ch, isVariationSelector(nextCh) ? nextCh : 0, lang, variant); + if (utf16Pos == 0 || family != lastFamily) { + size_t start = utf16Pos; // Workaround for Emoji keycap until we implement per-cluster font // selection: if keycap is found in a different font that also // supports previous char, attach previous char to the new run. // Only handles non-surrogate characters. // Bug 7557244. - if (ch == KEYCAP && i && family && family->getCoverage()->get(string[i - 1])) { + if (ch == KEYCAP && utf16Pos != 0 && family && family->getCoverage()->get(prevCh)) { run->end--; if (run->start == run->end) { result->pop_back(); @@ -214,8 +246,9 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty run->start = start; } } - run->end = i + nShorts; - } + prevCh = ch; + run->end = nextUtf16Pos; // exclusive + } while (nextCh != kEndOfString); } MinikinFont* FontCollection::baseFont(FontStyle style) { diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index cabc9679848..3c453f30621 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -277,6 +277,255 @@ TEST(FontCollectionItemizeTest, itemize_mixed) { EXPECT_FALSE(runs[4].fakedFont.fakery.isFakeItalic()); } +TEST(FontCollectionItemizeTest, itemize_variationSelector) { + std::unique_ptr collection = getFontCollection(); + std::vector runs; + + // A glyph for U+4FAE is provided by both Japanese font and Simplified + // Chinese font. Also a glyph for U+242EE is provided by both Japanese and + // Traditional Chinese font. To avoid effects of device default locale, + // explicitly specify the locale. + FontStyle kZH_HansStyle = FontStyle(FontLanguage("zh_Hans", 7)); + FontStyle kZH_HantStyle = FontStyle(FontLanguage("zh_Hant", 7)); + + // U+4FAE is available in both zh_Hans and ja font, but U+4FAE,U+FE00 is + // only available in ja font. + itemize(collection.get(), "U+4FAE", kZH_HansStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+4FAE U+FE00", kZH_HansStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+4FAE U+4FAE U+FE00", kZH_HansStyle, &runs); + ASSERT_EQ(2U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_EQ(1, runs[1].start); + EXPECT_EQ(3, runs[1].end); + EXPECT_EQ(kJAFont, getFontPath(runs[1])); + + itemize(collection.get(), "U+4FAE U+4FAE U+FE00 U+4FAE", kZH_HansStyle, &runs); + ASSERT_EQ(3U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_EQ(1, runs[1].start); + EXPECT_EQ(3, runs[1].end); + EXPECT_EQ(kJAFont, getFontPath(runs[1])); + EXPECT_EQ(3, runs[2].start); + EXPECT_EQ(4, runs[2].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[2])); + + // Validation selector after validation selector. + itemize(collection.get(), "U+4FAE U+FE00 U+FE00", kZH_HansStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(3, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[1])); + + // No font supports U+242EE U+FE0E. + itemize(collection.get(), "U+4FAE U+FE0E", kZH_HansStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + + // Surrogate pairs handling. + // U+242EE is available in ja font and zh_Hant font. + // U+242EE U+FE00 is available only in ja font. + itemize(collection.get(), "U+242EE", kZH_HantStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+242EE U+FE00", kZH_HantStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(3, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+242EE U+242EE U+FE00", kZH_HantStyle, &runs); + ASSERT_EQ(2U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + EXPECT_EQ(2, runs[1].start); + EXPECT_EQ(5, runs[1].end); + EXPECT_EQ(kJAFont, getFontPath(runs[1])); + + itemize(collection.get(), "U+242EE U+242EE U+FE00 U+242EE", kZH_HantStyle, &runs); + ASSERT_EQ(3U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + EXPECT_EQ(2, runs[1].start); + EXPECT_EQ(5, runs[1].end); + EXPECT_EQ(kJAFont, getFontPath(runs[1])); + EXPECT_EQ(5, runs[2].start); + EXPECT_EQ(7, runs[2].end); + EXPECT_EQ(kZH_HantFont, getFontPath(runs[2])); + + // Validation selector after validation selector. + itemize(collection.get(), "U+242EE U+FE00 U+FE00", kZH_HansStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(4, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); + + // No font supports U+242EE U+FE0E + itemize(collection.get(), "U+242EE U+FE0E", kZH_HantStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(3, runs[0].end); + EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + + // Isolated variation selector supplement. + itemize(collection.get(), "U+FE00", FontStyle(), &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+FE00", kZH_HantStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kLatinFont, getFontPath(runs[0])); +} + +TEST(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { + std::unique_ptr collection = getFontCollection(); + std::vector runs; + + // A glyph for U+845B is provided by both Japanese font and Simplified + // Chinese font. Also a glyph for U+242EE is provided by both Japanese and + // Traditional Chinese font. To avoid effects of device default locale, + // explicitly specify the locale. + FontStyle kZH_HansStyle = FontStyle(FontLanguage("zh_Hans", 7)); + FontStyle kZH_HantStyle = FontStyle(FontLanguage("zh_Hant", 7)); + + // U+845B is available in both zh_Hans and ja font, but U+845B,U+E0100 is + // only available in ja font. + itemize(collection.get(), "U+845B", kZH_HansStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+845B U+E0100", kZH_HansStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(3, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+845B U+845B U+E0100", kZH_HansStyle, &runs); + ASSERT_EQ(2U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_EQ(1, runs[1].start); + EXPECT_EQ(4, runs[1].end); + EXPECT_EQ(kJAFont, getFontPath(runs[1])); + + itemize(collection.get(), "U+845B U+845B U+E0100 U+845B", kZH_HansStyle, &runs); + ASSERT_EQ(3U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + EXPECT_EQ(1, runs[1].start); + EXPECT_EQ(4, runs[1].end); + EXPECT_EQ(kJAFont, getFontPath(runs[1])); + EXPECT_EQ(4, runs[2].start); + EXPECT_EQ(5, runs[2].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[2])); + + // Validation selector after validation selector. + itemize(collection.get(), "U+845B U+E0100 U+E0100", kZH_HansStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); + + // No font supports U+845B U+E01E0. + itemize(collection.get(), "U+845B U+E01E0", kZH_HansStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(3, runs[0].end); + EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); + + // Isolated variation selector supplement + // Surrogate pairs handling. + // U+242EE is available in ja font and zh_Hant font. + // U+242EE U+E0100 is available only in ja font. + itemize(collection.get(), "U+242EE", kZH_HantStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+242EE U+E0101", kZH_HantStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(4, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+242EE U+242EE U+E0101", kZH_HantStyle, &runs); + ASSERT_EQ(2U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + EXPECT_EQ(2, runs[1].start); + EXPECT_EQ(6, runs[1].end); + EXPECT_EQ(kJAFont, getFontPath(runs[1])); + + itemize(collection.get(), "U+242EE U+242EE U+E0101 U+242EE", kZH_HantStyle, &runs); + ASSERT_EQ(3U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + EXPECT_EQ(2, runs[1].start); + EXPECT_EQ(6, runs[1].end); + EXPECT_EQ(kJAFont, getFontPath(runs[1])); + EXPECT_EQ(6, runs[2].start); + EXPECT_EQ(8, runs[2].end); + EXPECT_EQ(kZH_HantFont, getFontPath(runs[2])); + + // Validation selector after validation selector. + itemize(collection.get(), "U+242EE U+E0100 U+E0100", kZH_HantStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(6, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); + + // No font supports U+242EE U+E01E0. + itemize(collection.get(), "U+242EE U+E01E0", kZH_HantStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(4, runs[0].end); + EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + + // Isolated variation selector supplement. + itemize(collection.get(), "U+E0100", FontStyle(), &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+E0100", kZH_HantStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kLatinFont, getFontPath(runs[0])); +} + TEST(FontCollectionItemizeTest, itemize_no_crash) { std::unique_ptr collection = getFontCollection(); std::vector runs; @@ -340,4 +589,3 @@ TEST(FontCollectionItemizeTest, itemize_fakery) { EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeItalic()); } -// TODO(11256006): Add Variation Selector test cases once it is supported. From 9a4c3535bef65b72cf8b4b7da3b19d5995e2c137 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Mon, 19 Oct 2015 22:16:08 -0700 Subject: [PATCH 114/364] Basic scaffolding for handling a language list. The behavior hasn't changed much yet: all languages are ignored for rendering text, except the very first supported language. Change-Id: I1695fb985927ae5e28e4f59c1b531e4993af8688 --- .../src/flutter/include/minikin/FontFamily.h | 23 +++++++++ .../src/flutter/libs/minikin/FontFamily.cpp | 33 +++++++++++++ engine/src/flutter/tests/FontFamilyTest.cpp | 48 +++++++++++++++++++ 3 files changed, 104 insertions(+) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index b1994042e3c..fc05e3b2196 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -35,6 +35,7 @@ class MinikinFont; // font rendering. class FontLanguage { friend class FontStyle; + friend class FontLanguages; public: FontLanguage() : mBits(0) { } @@ -46,6 +47,8 @@ public: } operator bool() const { return mBits != 0; } + bool isUnsupported() const { return mBits == kUnsupportedLanguage; } + std::string getString() const; // 0 = no match, 1 = language matches, 2 = language and script match @@ -64,6 +67,23 @@ private: uint32_t mBits; }; +// A list of zero or more instances of FontLanguage, in the order of +// preference. Used for further resolution of rendering results. +class FontLanguages { +public: + FontLanguages() { mLangs.clear(); } + + // Parse from string, which is a comma-separated list of languages + FontLanguages(const char* buf, size_t size); + + const FontLanguage& operator[](size_t index) const { return mLangs.at(index); } + + size_t size() const { return mLangs.size(); } + +private: + std::vector mLangs; +}; + // FontStyle represents all style information needed to select an actual font // from a collection. The implementation is packed into a single 32-bit word // so it can be efficiently copied, embedded in other objects, etc. @@ -76,6 +96,9 @@ public: bits = (weight & kWeightMask) | (italic ? kItalicMask : 0) | (variant << kVariantShift) | (lang.bits() << kLangShift); } + FontStyle(FontLanguages langs, int variant = 0, int weight = 4, bool italic = false) : + // TODO: Use all the languages in langs + FontStyle(langs[0], variant, weight, italic) { } int getWeight() const { return bits & kWeightMask; } bool getItalic() const { return (bits & kItalicMask) != 0; } int getVariant() const { return (bits >> kVariantShift) & kVariantMask; } diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index a6632e03398..dfd37fe5930 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -16,9 +16,12 @@ #define LOG_TAG "Minikin" +#include + #include #include #include +#include #include #include @@ -115,6 +118,36 @@ int FontLanguage::match(const FontLanguage other) const { return result; } +FontLanguages::FontLanguages(const char* buf, size_t size) { + std::unordered_set seen; + mLangs.clear(); + const char* bufEnd = buf + size; + const char* lastStart = buf; + bool isLastLang = false; + while (true) { + const char* commaLoc = static_cast( + memchr(lastStart, ',', bufEnd - lastStart)); + if (commaLoc == NULL) { + commaLoc = bufEnd; + isLastLang = true; + } + FontLanguage lang(lastStart, commaLoc - lastStart); + if (isLastLang && mLangs.size() == 0) { + // Make sure the list has at least one member + mLangs.push_back(lang); + return; + } + uint32_t bits = lang.bits(); + if (bits != FontLanguage::kUnsupportedLanguage && seen.count(bits) == 0) { + mLangs.push_back(lang); + if (isLastLang) return; + seen.insert(bits); + } + if (isLastLang) return; + lastStart = commaLoc + 1; + } +} + FontFamily::~FontFamily() { for (size_t i = 0; i < mFonts.size(); i++) { mFonts[i].typeface->UnrefLocked(); diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index a6813f013b3..78f286c0ca6 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -22,6 +22,54 @@ namespace android { +TEST(FontLanguagesTest, basicTests) { + FontLanguages emptyLangs; + EXPECT_EQ(0u, emptyLangs.size()); + + FontLanguage english("en", 2); + FontLanguages singletonLangs("en", 2); + EXPECT_EQ(1u, singletonLangs.size()); + EXPECT_EQ(english, singletonLangs[0]); + + FontLanguage french("fr", 2); + FontLanguages twoLangs("en,fr", 5); + EXPECT_EQ(2u, twoLangs.size()); + EXPECT_EQ(english, twoLangs[0]); + EXPECT_EQ(french, twoLangs[1]); +} + +TEST(FontLanguagesTest, unsupportedLanguageTests) { + FontLanguage unsupportedLang("x-example", 9); + ASSERT_TRUE(unsupportedLang.isUnsupported()); + + FontLanguages oneUnsupported("x-example", 9); + EXPECT_EQ(1u, oneUnsupported.size()); + EXPECT_TRUE(oneUnsupported[0].isUnsupported()); + + FontLanguages twoUnsupporteds("x-example,x-example", 19); + EXPECT_EQ(1u, twoUnsupporteds.size()); + EXPECT_TRUE(twoUnsupporteds[0].isUnsupported()); + + FontLanguage english("en", 2); + FontLanguages firstUnsupported("x-example,en", 12); + EXPECT_EQ(1u, firstUnsupported.size()); + EXPECT_EQ(english, firstUnsupported[0]); + + FontLanguages lastUnsupported("en,x-example", 12); + EXPECT_EQ(1u, lastUnsupported.size()); + EXPECT_EQ(english, lastUnsupported[0]); +} + +TEST(FontLanguagesTest, repeatedLanguageTests) { + FontLanguage english("en", 2); + FontLanguage englishInLatn("en-Latn", 2); + ASSERT_TRUE(english == englishInLatn); + + FontLanguages langs("en,en-Latn", 10); + EXPECT_EQ(1u, langs.size()); + EXPECT_EQ(english, langs[0]); +} + // The test font has following glyphs. // U+82A6 // U+82A6 U+FE00 (VS1) From a816dfb3fad6087a82e5d5843b5da0504ece34b9 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 27 Oct 2015 14:56:12 +0900 Subject: [PATCH 115/364] Add -Werror -Wall -Wextra to compiler option. - To suppress noisy unused parameter warnings, comment out unused arguments. - Add -Werror for suppressing further warning. - Add -Wall -Wextra for safety. Change-Id: I30a0914a4633bd93eb60957cdf378770f04d8428 --- engine/src/flutter/include/minikin/Layout.h | 2 +- engine/src/flutter/libs/minikin/Android.mk | 3 +++ engine/src/flutter/libs/minikin/HbFaceCache.cpp | 9 ++------- engine/src/flutter/libs/minikin/Layout.cpp | 9 +++++---- .../src/flutter/libs/minikin/MinikinFontFreeType.cpp | 8 ++++---- engine/src/flutter/tests/Android.mk | 2 ++ engine/src/flutter/tests/HbFaceCacheTest.cpp | 10 +++++----- engine/src/flutter/tests/MinikinFontForTest.cpp | 8 ++++---- 8 files changed, 26 insertions(+), 25 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 83eb963b717..cb68db9c3dd 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -59,7 +59,7 @@ struct LayoutGlyph { }; // Internal state used during layout operation -class LayoutContext; +struct LayoutContext; enum { kBidi_LTR = 0, diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 4d34c114702..c728b09b84e 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -50,6 +50,7 @@ LOCAL_MODULE := libminikin LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) +LOCAL_CPPFLAGS += -Werror -Wall -Wextra LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) include $(BUILD_SHARED_LIBRARY) @@ -61,6 +62,7 @@ LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) +LOCAL_CPPFLAGS += -Werror -Wall -Wextra LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) include $(BUILD_STATIC_LIBRARY) @@ -73,6 +75,7 @@ LOCAL_MODULE := libminikin_host LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_C_INCLUDES := $(minikin_c_includes) +LOCAL_CPPFLAGS += -Werror -Wall -Wextra LOCAL_SHARED_LIBRARIES := liblog libicuuc-host LOCAL_SRC_FILES := Hyphenator.cpp diff --git a/engine/src/flutter/libs/minikin/HbFaceCache.cpp b/engine/src/flutter/libs/minikin/HbFaceCache.cpp index fde2fa869f2..a12cd95a950 100644 --- a/engine/src/flutter/libs/minikin/HbFaceCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFaceCache.cpp @@ -26,7 +26,7 @@ namespace android { -static hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { +static hb_blob_t* referenceTable(hb_face_t* /* face */, hb_tag_t tag, void* userData) { MinikinFont* font = reinterpret_cast(userData); size_t length = 0; bool ok = font->GetTable(tag, NULL, &length); @@ -50,11 +50,6 @@ static hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) HB_MEMORY_MODE_WRITABLE, buffer, free); } -static unsigned int disabledDecomposeCompatibility( - hb_unicode_funcs_t*, hb_codepoint_t, hb_codepoint_t*, void*) { - return 0; -} - class HbFaceCache : private OnEntryRemoved { public: HbFaceCache() : mCache(kMaxEntries) { @@ -62,7 +57,7 @@ public: } // callback for OnEntryRemoved - void operator()(int32_t& key, hb_face_t*& value) { + void operator()(int32_t& /* key */, hb_face_t*& value) { hb_face_destroy(value); } diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 6d62d5d7d8e..9084ebafadc 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -276,16 +276,17 @@ void Layout::setFontCollection(const FontCollection* collection) { mCollection = collection; } -static hb_position_t harfbuzzGetGlyphHorizontalAdvance(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, void* userData) -{ +static hb_position_t harfbuzzGetGlyphHorizontalAdvance(hb_font_t* /* hbFont */, void* fontData, + hb_codepoint_t glyph, void* /* userData */) { MinikinPaint* paint = reinterpret_cast(fontData); MinikinFont* font = paint->font; float advance = font->GetHorizontalAdvance(glyph, *paint); return 256 * advance + 0.5; } -static hb_bool_t harfbuzzGetGlyphHorizontalOrigin(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, hb_position_t* x, hb_position_t* y, void* userData) -{ +static hb_bool_t harfbuzzGetGlyphHorizontalOrigin(hb_font_t* /* hbFont */, void* /* fontData */, + hb_codepoint_t /* glyph */, hb_position_t* /* x */, hb_position_t* /* y */, + void* /* userData */) { // Just return true, following the way that Harfbuzz-FreeType // implementation does. return true; diff --git a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp index cbeed615932..c9eb456be5f 100644 --- a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp @@ -47,8 +47,8 @@ float MinikinFontFreeType::GetHorizontalAdvance(uint32_t glyph_id, return advance * (1.0 / 65536); } -void MinikinFontFreeType::GetBounds(MinikinRect* bounds, uint32_t glyph_id, - const MinikinPaint& paint) const { +void MinikinFontFreeType::GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph_id*/, + const MinikinPaint& /* paint */) const { // TODO: NYI } @@ -66,8 +66,8 @@ int32_t MinikinFontFreeType::GetUniqueId() const { return mUniqueId; } -bool MinikinFontFreeType::Render(uint32_t glyph_id, - const MinikinPaint &paint, GlyphBitmap *result) { +bool MinikinFontFreeType::Render(uint32_t glyph_id, const MinikinPaint& /* paint */, + GlyphBitmap *result) { FT_Error error; FT_Int32 load_flags = FT_LOAD_DEFAULT; // TODO: respect hinting settings error = FT_Load_Glyph(mTypeface, glyph_id, load_flags); diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index b69b8f243f6..b6bc15c0dcf 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -54,4 +54,6 @@ LOCAL_C_INCLUDES := \ external/libxml2/include \ external/skia/src/core +LOCAL_CPPFLAGS += -Werror -Wall -Wextra + include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/HbFaceCacheTest.cpp b/engine/src/flutter/tests/HbFaceCacheTest.cpp index fbaf0eab150..76eec5b5a83 100644 --- a/engine/src/flutter/tests/HbFaceCacheTest.cpp +++ b/engine/src/flutter/tests/HbFaceCacheTest.cpp @@ -35,18 +35,18 @@ public: MockMinikinFont(int32_t id) : mId(id) { } - virtual float GetHorizontalAdvance( - uint32_t glyph_id, const MinikinPaint &paint) const { + virtual float GetHorizontalAdvance(uint32_t /* glyph_id */, + const MinikinPaint& /* paint */) const { LOG_ALWAYS_FATAL("MockMinikinFont::GetHorizontalAdvance is not implemented."); return 0.0f; } - virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id, - const MinikinPaint &paint) const { + virtual void GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph_id */, + const MinikinPaint& /* paint */) const { LOG_ALWAYS_FATAL("MockMinikinFont::GetBounds is not implemented."); } - virtual bool GetTable(uint32_t tag, uint8_t *buf, size_t *size) { + virtual bool GetTable(uint32_t /* tag */, uint8_t* /* buf */, size_t* /* size */) { LOG_ALWAYS_FATAL("MockMinikinFont::GetTable is not implemented."); return false; } diff --git a/engine/src/flutter/tests/MinikinFontForTest.cpp b/engine/src/flutter/tests/MinikinFontForTest.cpp index 033241e26dc..ed7075188b5 100644 --- a/engine/src/flutter/tests/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/MinikinFontForTest.cpp @@ -29,14 +29,14 @@ MinikinFontForTest::MinikinFontForTest(const std::string& font_path) : mFontPath MinikinFontForTest::~MinikinFontForTest() { } -float MinikinFontForTest::GetHorizontalAdvance( - uint32_t glyph_id, const android::MinikinPaint &paint) const { +float MinikinFontForTest::GetHorizontalAdvance(uint32_t /* glyph_id */, + const android::MinikinPaint& /* paint */) const { LOG_ALWAYS_FATAL("MinikinFontForTest::GetHorizontalAdvance is not yet implemented"); return 0.0f; } -void MinikinFontForTest::GetBounds(android::MinikinRect* bounds, uint32_t glyph_id, - const android::MinikinPaint& paint) const { +void MinikinFontForTest::GetBounds(android::MinikinRect* /* bounds */, uint32_t /* glyph_id */, + const android::MinikinPaint& /* paint */) const { LOG_ALWAYS_FATAL("MinikinFontForTest::GetBounds is not yet implemented"); } From 07c8ad2b85c6e653f5450dba0a7e4689d4ec2cd0 Mon Sep 17 00:00:00 2001 From: Bart Sears Date: Wed, 28 Oct 2015 03:16:55 +0000 Subject: [PATCH 116/364] Revert "Add -Werror -Wall -Wextra to compiler option." This reverts commit a816dfb3fad6087a82e5d5843b5da0504ece34b9. Change-Id: I2b4b10e8afedc85dbe2d07f3e47315652b65cd14 --- engine/src/flutter/include/minikin/Layout.h | 2 +- engine/src/flutter/libs/minikin/Android.mk | 3 --- engine/src/flutter/libs/minikin/HbFaceCache.cpp | 9 +++++++-- engine/src/flutter/libs/minikin/Layout.cpp | 9 ++++----- .../src/flutter/libs/minikin/MinikinFontFreeType.cpp | 8 ++++---- engine/src/flutter/tests/Android.mk | 2 -- engine/src/flutter/tests/HbFaceCacheTest.cpp | 10 +++++----- engine/src/flutter/tests/MinikinFontForTest.cpp | 8 ++++---- 8 files changed, 25 insertions(+), 26 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index cb68db9c3dd..83eb963b717 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -59,7 +59,7 @@ struct LayoutGlyph { }; // Internal state used during layout operation -struct LayoutContext; +class LayoutContext; enum { kBidi_LTR = 0, diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index c728b09b84e..4d34c114702 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -50,7 +50,6 @@ LOCAL_MODULE := libminikin LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) include $(BUILD_SHARED_LIBRARY) @@ -62,7 +61,6 @@ LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) include $(BUILD_STATIC_LIBRARY) @@ -75,7 +73,6 @@ LOCAL_MODULE := libminikin_host LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra LOCAL_SHARED_LIBRARIES := liblog libicuuc-host LOCAL_SRC_FILES := Hyphenator.cpp diff --git a/engine/src/flutter/libs/minikin/HbFaceCache.cpp b/engine/src/flutter/libs/minikin/HbFaceCache.cpp index a12cd95a950..fde2fa869f2 100644 --- a/engine/src/flutter/libs/minikin/HbFaceCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFaceCache.cpp @@ -26,7 +26,7 @@ namespace android { -static hb_blob_t* referenceTable(hb_face_t* /* face */, hb_tag_t tag, void* userData) { +static hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { MinikinFont* font = reinterpret_cast(userData); size_t length = 0; bool ok = font->GetTable(tag, NULL, &length); @@ -50,6 +50,11 @@ static hb_blob_t* referenceTable(hb_face_t* /* face */, hb_tag_t tag, void* user HB_MEMORY_MODE_WRITABLE, buffer, free); } +static unsigned int disabledDecomposeCompatibility( + hb_unicode_funcs_t*, hb_codepoint_t, hb_codepoint_t*, void*) { + return 0; +} + class HbFaceCache : private OnEntryRemoved { public: HbFaceCache() : mCache(kMaxEntries) { @@ -57,7 +62,7 @@ public: } // callback for OnEntryRemoved - void operator()(int32_t& /* key */, hb_face_t*& value) { + void operator()(int32_t& key, hb_face_t*& value) { hb_face_destroy(value); } diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 9084ebafadc..6d62d5d7d8e 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -276,17 +276,16 @@ void Layout::setFontCollection(const FontCollection* collection) { mCollection = collection; } -static hb_position_t harfbuzzGetGlyphHorizontalAdvance(hb_font_t* /* hbFont */, void* fontData, - hb_codepoint_t glyph, void* /* userData */) { +static hb_position_t harfbuzzGetGlyphHorizontalAdvance(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, void* userData) +{ MinikinPaint* paint = reinterpret_cast(fontData); MinikinFont* font = paint->font; float advance = font->GetHorizontalAdvance(glyph, *paint); return 256 * advance + 0.5; } -static hb_bool_t harfbuzzGetGlyphHorizontalOrigin(hb_font_t* /* hbFont */, void* /* fontData */, - hb_codepoint_t /* glyph */, hb_position_t* /* x */, hb_position_t* /* y */, - void* /* userData */) { +static hb_bool_t harfbuzzGetGlyphHorizontalOrigin(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, hb_position_t* x, hb_position_t* y, void* userData) +{ // Just return true, following the way that Harfbuzz-FreeType // implementation does. return true; diff --git a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp index c9eb456be5f..cbeed615932 100644 --- a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp @@ -47,8 +47,8 @@ float MinikinFontFreeType::GetHorizontalAdvance(uint32_t glyph_id, return advance * (1.0 / 65536); } -void MinikinFontFreeType::GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph_id*/, - const MinikinPaint& /* paint */) const { +void MinikinFontFreeType::GetBounds(MinikinRect* bounds, uint32_t glyph_id, + const MinikinPaint& paint) const { // TODO: NYI } @@ -66,8 +66,8 @@ int32_t MinikinFontFreeType::GetUniqueId() const { return mUniqueId; } -bool MinikinFontFreeType::Render(uint32_t glyph_id, const MinikinPaint& /* paint */, - GlyphBitmap *result) { +bool MinikinFontFreeType::Render(uint32_t glyph_id, + const MinikinPaint &paint, GlyphBitmap *result) { FT_Error error; FT_Int32 load_flags = FT_LOAD_DEFAULT; // TODO: respect hinting settings error = FT_Load_Glyph(mTypeface, glyph_id, load_flags); diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index b6bc15c0dcf..b69b8f243f6 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -54,6 +54,4 @@ LOCAL_C_INCLUDES := \ external/libxml2/include \ external/skia/src/core -LOCAL_CPPFLAGS += -Werror -Wall -Wextra - include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/HbFaceCacheTest.cpp b/engine/src/flutter/tests/HbFaceCacheTest.cpp index 76eec5b5a83..fbaf0eab150 100644 --- a/engine/src/flutter/tests/HbFaceCacheTest.cpp +++ b/engine/src/flutter/tests/HbFaceCacheTest.cpp @@ -35,18 +35,18 @@ public: MockMinikinFont(int32_t id) : mId(id) { } - virtual float GetHorizontalAdvance(uint32_t /* glyph_id */, - const MinikinPaint& /* paint */) const { + virtual float GetHorizontalAdvance( + uint32_t glyph_id, const MinikinPaint &paint) const { LOG_ALWAYS_FATAL("MockMinikinFont::GetHorizontalAdvance is not implemented."); return 0.0f; } - virtual void GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph_id */, - const MinikinPaint& /* paint */) const { + virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id, + const MinikinPaint &paint) const { LOG_ALWAYS_FATAL("MockMinikinFont::GetBounds is not implemented."); } - virtual bool GetTable(uint32_t /* tag */, uint8_t* /* buf */, size_t* /* size */) { + virtual bool GetTable(uint32_t tag, uint8_t *buf, size_t *size) { LOG_ALWAYS_FATAL("MockMinikinFont::GetTable is not implemented."); return false; } diff --git a/engine/src/flutter/tests/MinikinFontForTest.cpp b/engine/src/flutter/tests/MinikinFontForTest.cpp index ed7075188b5..033241e26dc 100644 --- a/engine/src/flutter/tests/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/MinikinFontForTest.cpp @@ -29,14 +29,14 @@ MinikinFontForTest::MinikinFontForTest(const std::string& font_path) : mFontPath MinikinFontForTest::~MinikinFontForTest() { } -float MinikinFontForTest::GetHorizontalAdvance(uint32_t /* glyph_id */, - const android::MinikinPaint& /* paint */) const { +float MinikinFontForTest::GetHorizontalAdvance( + uint32_t glyph_id, const android::MinikinPaint &paint) const { LOG_ALWAYS_FATAL("MinikinFontForTest::GetHorizontalAdvance is not yet implemented"); return 0.0f; } -void MinikinFontForTest::GetBounds(android::MinikinRect* /* bounds */, uint32_t /* glyph_id */, - const android::MinikinPaint& /* paint */) const { +void MinikinFontForTest::GetBounds(android::MinikinRect* bounds, uint32_t glyph_id, + const android::MinikinPaint& paint) const { LOG_ALWAYS_FATAL("MinikinFontForTest::GetBounds is not yet implemented"); } From ac88812115bd4232cb956582ae9fdbaf221d8cb7 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 27 Oct 2015 14:56:12 +0900 Subject: [PATCH 117/364] Add -Werror -Wall -Wextra to compiler option. This is 2nd trial of I30a0914a4633bd93eb60957cdf378770f04d8428 - To suppress noisy unused parameter warnings, comment out unused arguments. - Add -Werror for suppressing further warning. - Add -Wall -Wextra for safety. - Use "z" prefix for format string of size_t. Verified that compile succeeded on all arm,arm64,mips,x86,x86_64. Change-Id: I7ad208464486b8a35da53929cb1cfe541ed0052f --- engine/src/flutter/include/minikin/Layout.h | 2 +- engine/src/flutter/libs/minikin/Android.mk | 3 +++ engine/src/flutter/libs/minikin/FontCollection.cpp | 8 ++++---- engine/src/flutter/libs/minikin/FontFamily.cpp | 4 ++-- engine/src/flutter/libs/minikin/HbFaceCache.cpp | 12 ++++-------- engine/src/flutter/libs/minikin/Layout.cpp | 13 +++++++------ engine/src/flutter/libs/minikin/LineBreaker.cpp | 6 +++--- .../flutter/libs/minikin/MinikinFontFreeType.cpp | 8 ++++---- engine/src/flutter/tests/Android.mk | 2 ++ engine/src/flutter/tests/HbFaceCacheTest.cpp | 10 +++++----- engine/src/flutter/tests/MinikinFontForTest.cpp | 8 ++++---- 11 files changed, 39 insertions(+), 37 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 83eb963b717..cb68db9c3dd 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -59,7 +59,7 @@ struct LayoutGlyph { }; // Internal state used during layout operation -class LayoutContext; +struct LayoutContext; enum { kBidi_LTR = 0, diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 4d34c114702..c728b09b84e 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -50,6 +50,7 @@ LOCAL_MODULE := libminikin LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) +LOCAL_CPPFLAGS += -Werror -Wall -Wextra LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) include $(BUILD_SHARED_LIBRARY) @@ -61,6 +62,7 @@ LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) +LOCAL_CPPFLAGS += -Werror -Wall -Wextra LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) include $(BUILD_STATIC_LIBRARY) @@ -73,6 +75,7 @@ LOCAL_MODULE := libminikin_host LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_C_INCLUDES := $(minikin_c_includes) +LOCAL_CPPFLAGS += -Werror -Wall -Wextra LOCAL_SHARED_LIBRARIES := liblog libicuuc-host LOCAL_SRC_FILES := Hyphenator.cpp diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 4c0070c2b1e..2c228802597 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -43,7 +43,7 @@ FontCollection::FontCollection(const vector& typefaces) : vector lastChar; size_t nTypefaces = typefaces.size(); #ifdef VERBOSE_DEBUG - ALOGD("nTypefaces = %d\n", nTypefaces); + ALOGD("nTypefaces = %zd\n", nTypefaces); #endif const FontStyle defaultStyle; for (size_t i = 0; i < nTypefaces; i++) { @@ -72,7 +72,7 @@ FontCollection::FontCollection(const vector& typefaces) : mRanges.push_back(dummy); Range* range = &mRanges.back(); #ifdef VERBOSE_DEBUG - ALOGD("i=%d: range start = %d\n", i, offset); + ALOGD("i=%zd: range start = %zd\n", i, offset); #endif range->start = offset; for (size_t j = 0; j < nTypefaces; j++) { @@ -82,7 +82,7 @@ FontCollection::FontCollection(const vector& typefaces) : offset++; uint32_t nextChar = family->getCoverage()->nextSetBit((i + 1) << kLogCharsPerPage); #ifdef VERBOSE_DEBUG - ALOGD("nextChar = %d (j = %d)\n", nextChar, j); + ALOGD("nextChar = %d (j = %zd)\n", nextChar, j); #endif lastChar[j] = nextChar; } @@ -110,7 +110,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, } const Range& range = mRanges[ch >> kLogCharsPerPage]; #ifdef VERBOSE_DEBUG - ALOGD("querying range %d:%d\n", range.start, range.end); + ALOGD("querying range %zd:%zd\n", range.start, range.end); #endif FontFamily* bestFamily = nullptr; int bestScore = -1; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index dfd37fe5930..1ff5a6bce4b 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -258,8 +258,8 @@ const SparseBitSet* FontFamily::getCoverage() { } CmapCoverage::getCoverage(mCoverage, cmapData.get(), cmapSize); // TODO: Error check? #ifdef VERBOSE_DEBUG - ALOGD("font coverage length=%d, first ch=%x\n", mCoverage->length(), - mCoverage->nextSetBit(0)); + ALOGD("font coverage length=%d, first ch=%x\n", mCoverage.length(), + mCoverage.nextSetBit(0)); #endif mCoverageValid = true; } diff --git a/engine/src/flutter/libs/minikin/HbFaceCache.cpp b/engine/src/flutter/libs/minikin/HbFaceCache.cpp index fde2fa869f2..235f7f1b0c2 100644 --- a/engine/src/flutter/libs/minikin/HbFaceCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFaceCache.cpp @@ -18,6 +18,7 @@ #include "HbFaceCache.h" +#include #include #include @@ -26,7 +27,7 @@ namespace android { -static hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { +static hb_blob_t* referenceTable(hb_face_t* /* face */, hb_tag_t tag, void* userData) { MinikinFont* font = reinterpret_cast(userData); size_t length = 0; bool ok = font->GetTable(tag, NULL, &length); @@ -39,7 +40,7 @@ static hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) } ok = font->GetTable(tag, reinterpret_cast(buffer), &length); #ifdef VERBOSE_DEBUG - ALOGD("referenceTable %c%c%c%c length=%d %d", + ALOGD("referenceTable %c%c%c%c length=%zd %d", (tag >>24)&0xff, (tag>>16)&0xff, (tag>>8)&0xff, tag&0xff, length, ok); #endif if (!ok) { @@ -50,11 +51,6 @@ static hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) HB_MEMORY_MODE_WRITABLE, buffer, free); } -static unsigned int disabledDecomposeCompatibility( - hb_unicode_funcs_t*, hb_codepoint_t, hb_codepoint_t*, void*) { - return 0; -} - class HbFaceCache : private OnEntryRemoved { public: HbFaceCache() : mCache(kMaxEntries) { @@ -62,7 +58,7 @@ public: } // callback for OnEntryRemoved - void operator()(int32_t& key, hb_face_t*& value) { + void operator()(int32_t& /* key */, hb_face_t*& value) { hb_face_destroy(value); } diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 6d62d5d7d8e..3b140faa2b8 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -276,16 +276,17 @@ void Layout::setFontCollection(const FontCollection* collection) { mCollection = collection; } -static hb_position_t harfbuzzGetGlyphHorizontalAdvance(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, void* userData) -{ +static hb_position_t harfbuzzGetGlyphHorizontalAdvance(hb_font_t* /* hbFont */, void* fontData, + hb_codepoint_t glyph, void* /* userData */) { MinikinPaint* paint = reinterpret_cast(fontData); MinikinFont* font = paint->font; float advance = font->GetHorizontalAdvance(glyph, *paint); return 256 * advance + 0.5; } -static hb_bool_t harfbuzzGetGlyphHorizontalOrigin(hb_font_t* hbFont, void* fontData, hb_codepoint_t glyph, hb_position_t* x, hb_position_t* y, void* userData) -{ +static hb_bool_t harfbuzzGetGlyphHorizontalOrigin(hb_font_t* /* hbFont */, void* /* fontData */, + hb_codepoint_t /* glyph */, hb_position_t* /* x */, hb_position_t* /* y */, + void* /* userData */) { // Just return true, following the way that Harfbuzz-FreeType // implementation does. return true; @@ -709,7 +710,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t ctx->paint.fakery = mFaces[font_ix].fakery; hb_font_t* hbFont = ctx->hbFonts[font_ix]; #ifdef VERBOSE_DEBUG - ALOGD("Run %u, font %d [%d:%d]", run_ix, font_ix, run.start, run.end); + ALOGD("Run %zu, font %d [%d:%d]", run_ix, font_ix, run.start, run.end); #endif hb_font_set_ppem(hbFont, size * scaleX, size); @@ -804,7 +805,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t if (info[i].cluster - start < count) { mAdvances[info[i].cluster - start] += xAdvance; } else { - ALOGE("cluster %d (start %d) out of bounds of count %d", + ALOGE("cluster %zu (start %zu) out of bounds of count %zu", info[i].cluster - start, start, count); } x += xAdvance; diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index a832ca20e26..a2507e0ba87 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -249,7 +249,7 @@ void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth post cand.penalty = SCORE_DESPERATE; cand.hyphenEdit = 0; #if VERBOSE_DEBUG - ALOGD("desperate cand: %d %g:%g", + ALOGD("desperate cand: %zd %g:%g", mCandidates.size(), cand.postBreak, cand.preBreak); #endif addCandidate(cand); @@ -264,7 +264,7 @@ void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth post cand.penalty = penalty; cand.hyphenEdit = hyph; #if VERBOSE_DEBUG - ALOGD("cand: %d %g:%g", mCandidates.size(), cand.postBreak, cand.preBreak); + ALOGD("cand: %zd %g:%g", mCandidates.size(), cand.postBreak, cand.preBreak); #endif addCandidate(cand); } @@ -409,7 +409,7 @@ void LineBreaker::computeBreaksOptimal(bool isRectangle) { mCandidates[i].prev = bestPrev; mCandidates[i].lineNumber = mCandidates[bestPrev].lineNumber + 1; #if VERBOSE_DEBUG - ALOGD("break %d: score=%g, prev=%d", i, mCandidates[i].score, mCandidates[i].prev); + ALOGD("break %zd: score=%g, prev=%zd", i, mCandidates[i].score, mCandidates[i].prev); #endif } finishBreaksOptimal(); diff --git a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp index cbeed615932..c9eb456be5f 100644 --- a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp @@ -47,8 +47,8 @@ float MinikinFontFreeType::GetHorizontalAdvance(uint32_t glyph_id, return advance * (1.0 / 65536); } -void MinikinFontFreeType::GetBounds(MinikinRect* bounds, uint32_t glyph_id, - const MinikinPaint& paint) const { +void MinikinFontFreeType::GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph_id*/, + const MinikinPaint& /* paint */) const { // TODO: NYI } @@ -66,8 +66,8 @@ int32_t MinikinFontFreeType::GetUniqueId() const { return mUniqueId; } -bool MinikinFontFreeType::Render(uint32_t glyph_id, - const MinikinPaint &paint, GlyphBitmap *result) { +bool MinikinFontFreeType::Render(uint32_t glyph_id, const MinikinPaint& /* paint */, + GlyphBitmap *result) { FT_Error error; FT_Int32 load_flags = FT_LOAD_DEFAULT; // TODO: respect hinting settings error = FT_Load_Glyph(mTypeface, glyph_id, load_flags); diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index b69b8f243f6..b6bc15c0dcf 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -54,4 +54,6 @@ LOCAL_C_INCLUDES := \ external/libxml2/include \ external/skia/src/core +LOCAL_CPPFLAGS += -Werror -Wall -Wextra + include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/HbFaceCacheTest.cpp b/engine/src/flutter/tests/HbFaceCacheTest.cpp index fbaf0eab150..76eec5b5a83 100644 --- a/engine/src/flutter/tests/HbFaceCacheTest.cpp +++ b/engine/src/flutter/tests/HbFaceCacheTest.cpp @@ -35,18 +35,18 @@ public: MockMinikinFont(int32_t id) : mId(id) { } - virtual float GetHorizontalAdvance( - uint32_t glyph_id, const MinikinPaint &paint) const { + virtual float GetHorizontalAdvance(uint32_t /* glyph_id */, + const MinikinPaint& /* paint */) const { LOG_ALWAYS_FATAL("MockMinikinFont::GetHorizontalAdvance is not implemented."); return 0.0f; } - virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id, - const MinikinPaint &paint) const { + virtual void GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph_id */, + const MinikinPaint& /* paint */) const { LOG_ALWAYS_FATAL("MockMinikinFont::GetBounds is not implemented."); } - virtual bool GetTable(uint32_t tag, uint8_t *buf, size_t *size) { + virtual bool GetTable(uint32_t /* tag */, uint8_t* /* buf */, size_t* /* size */) { LOG_ALWAYS_FATAL("MockMinikinFont::GetTable is not implemented."); return false; } diff --git a/engine/src/flutter/tests/MinikinFontForTest.cpp b/engine/src/flutter/tests/MinikinFontForTest.cpp index 033241e26dc..ed7075188b5 100644 --- a/engine/src/flutter/tests/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/MinikinFontForTest.cpp @@ -29,14 +29,14 @@ MinikinFontForTest::MinikinFontForTest(const std::string& font_path) : mFontPath MinikinFontForTest::~MinikinFontForTest() { } -float MinikinFontForTest::GetHorizontalAdvance( - uint32_t glyph_id, const android::MinikinPaint &paint) const { +float MinikinFontForTest::GetHorizontalAdvance(uint32_t /* glyph_id */, + const android::MinikinPaint& /* paint */) const { LOG_ALWAYS_FATAL("MinikinFontForTest::GetHorizontalAdvance is not yet implemented"); return 0.0f; } -void MinikinFontForTest::GetBounds(android::MinikinRect* bounds, uint32_t glyph_id, - const android::MinikinPaint& paint) const { +void MinikinFontForTest::GetBounds(android::MinikinRect* /* bounds */, uint32_t /* glyph_id */, + const android::MinikinPaint& /* paint */) const { LOG_ALWAYS_FATAL("MinikinFontForTest::GetBounds is not yet implemented"); } From 34c39bcde69c8505fd72c460ee601dff1ad4c8c9 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 29 Oct 2015 11:39:58 -0700 Subject: [PATCH 118/364] Accept variation selector in emoji sequences - DO NOT MERGE This patch basically ignores variation selectors for the purpose of itemization into font runs. This allows GSUB to be applied when input sequences contain variation selectors. Bug: 25368653 Change-Id: I9c1d325ae0cd322c21b7e850d0ec4d73551b2372 --- engine/src/flutter/libs/minikin/FontCollection.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index b4bfe313ba4..2bcbc037793 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -167,6 +167,10 @@ static bool isStickyWhitelisted(uint32_t c) { return false; } +static bool isVariationSelector(uint32_t c) { + return (0xFE00 <= c && c <= 0xFE0F) || (0xE0100 <= c && c <= 0xE01EF); +} + void FontCollection::itemize(const uint16_t *string, size_t string_size, FontStyle style, vector* result) const { FontLanguage lang = style.getLanguage(); @@ -184,9 +188,11 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty nShorts = 2; } } - // Continue using existing font as long as it has coverage and is whitelisted + // Continue using existing font as long as it has coverage and is whitelisted; + // also variation sequences continue existing run. if (lastFamily == NULL - || !(isStickyWhitelisted(ch) && lastFamily->getCoverage()->get(ch))) { + || !((isStickyWhitelisted(ch) && lastFamily->getCoverage()->get(ch)) + || isVariationSelector(ch))) { FontFamily* family = getFamilyForChar(ch, lang, variant); if (i == 0 || family != lastFamily) { size_t start = i; From 5001f2ae481c3b77ffcb2b64803cc9e96e5cfeb9 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 2 Nov 2015 17:17:24 -0800 Subject: [PATCH 119/364] Suppress linebreaks in emoji ZWJ sequences - DO NOT MERGE Due to the way emoji ZWJ sequences are defined, the ICU line breaking algorithm determines that there are valid line breaks inside the sequence. This patch suppresses these line breaks. Bug: 25433289 Change-Id: I225ebebc0f4186e4b8f48fee399c4a62b3f0218a --- .../src/flutter/libs/minikin/LineBreaker.cpp | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index a832ca20e26..77374feaa0d 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -17,6 +17,7 @@ #define VERBOSE_DEBUG 0 #include +#include #define LOG_TAG "Minikin" #include @@ -30,6 +31,7 @@ namespace android { const int CHAR_TAB = 0x0009; const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; +const uint16_t CHAR_ZWJ = 0x200D; // Large scores in a hierarchy; we prefer desperate breaks to an overfull line. All these // constants are larger than any reasonable actual width score. @@ -123,6 +125,32 @@ static bool isLineBreakingHyphen(uint16_t c) { c == 0x2E40); // DOUBLE HYPHEN } +/** + * Determine whether a line break at position i within the buffer buf is valid. This + * represents customization beyond the ICU behavior, because plain ICU provides some + * line break opportunities that we don't want. + **/ +static bool isBreakValid(uint16_t codeUnit, const uint16_t* buf, size_t bufEnd, size_t i) { + if (codeUnit == CHAR_SOFT_HYPHEN) { + return false; + } + if (codeUnit == CHAR_ZWJ) { + // Possible emoji ZWJ sequence + uint32_t next_codepoint; + U16_NEXT(buf, i, bufEnd, next_codepoint); + if (next_codepoint == 0x2764 || // HEAVY BLACK HEART + next_codepoint == 0x1F466 || // BOY + next_codepoint == 0x1F467 || // GIRL + next_codepoint == 0x1F468 || // MAN + next_codepoint == 0x1F469 || // WOMAN + next_codepoint == 0x1F48B || // KISS MARK + next_codepoint == 0x1F5E8) { // LEFT SPEECH BUBBLE + return false; + } + } + return true; +} + // Ordinarily, this method measures the text in the range given. However, when paint // is nullptr, it assumes the widths have already been calculated and stored in the // width buffer. @@ -175,8 +203,9 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa } if (i + 1 == current) { // Override ICU's treatment of soft hyphen as a break opportunity, because we want it - // to be a hyphen break, with penalty and drawing behavior. - if (c != CHAR_SOFT_HYPHEN) { + // to be a hyphen break, with penalty and drawing behavior. Also, suppress line + // breaks within emoji ZWJ sequences. + if (isBreakValid(c, mTextBuf.data(), end, i + 1)) { // TODO: Add a new type of HyphenEdit for breaks whose hyphen already exists, so // we can pass the whole word down to Hyphenator like the soft hyphen case. bool wordEndsInHyphen = isLineBreakingHyphen(c); From 40ffbdf94c93487dcf86bf6e073a8272eb10ce09 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Fri, 30 Oct 2015 17:09:01 +0900 Subject: [PATCH 120/364] Fix invalid decrement range of KEYCAP handling in itemize. This issue was introduced by I22ce0e9eadc941f84e3a9b23462f194e51dd7180. Need to decrement the two utf16 chars in KEYCAP handling. To add unit tests, this CL also addresses the Bug: 24184208 by introducing self built fonts since there is no good example in system installed fonts. Bug: 24184208 Change-Id: I23fa008adbaced78a3cb96442a6bc8892ab84ce8 --- .../flutter/libs/minikin/FontCollection.cpp | 6 +- .../tests/FontCollectionItemizeTest.cpp | 67 +++++++++++++------ engine/src/flutter/tests/FontTestUtils.cpp | 17 ++--- engine/src/flutter/tests/FontTestUtils.h | 3 +- 4 files changed, 58 insertions(+), 35 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 2c228802597..9fe0686e29f 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -225,14 +225,14 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty // Workaround for Emoji keycap until we implement per-cluster font // selection: if keycap is found in a different font that also // supports previous char, attach previous char to the new run. - // Only handles non-surrogate characters. // Bug 7557244. if (ch == KEYCAP && utf16Pos != 0 && family && family->getCoverage()->get(prevCh)) { - run->end--; + const size_t prevChLength = U16_LENGTH(prevCh); + run->end -= prevChLength; if (run->start == run->end) { result->pop_back(); } - start--; + start -= prevChLength; } Run dummy; result->push_back(dummy); diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index 3c453f30621..ae1cbf47dbb 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -24,15 +24,18 @@ using android::FontCollection; using android::FontLanguage; using android::FontStyle; -const char kEmojiFont[] = "/system/fonts/NotoColorEmoji.ttf"; -const char kJAFont[] = "/system/fonts/NotoSansJP-Regular.otf"; -const char kKOFont[] = "/system/fonts/NotoSansKR-Regular.otf"; -const char kLatinBoldFont[] = "/system/fonts/Roboto-Bold.ttf"; -const char kLatinBoldItalicFont[] = "/system/fonts/Roboto-BoldItalic.ttf"; -const char kLatinFont[] = "/system/fonts/Roboto-Regular.ttf"; -const char kLatinItalicFont[] = "/system/fonts/Roboto-Italic.ttf"; -const char kZH_HansFont[] = "/system/fonts/NotoSansSC-Regular.otf"; -const char kZH_HantFont[] = "/system/fonts/NotoSansTC-Regular.otf"; +const char kItemizeFontXml[] = "/data/minikin/test/data/itemize.xml"; +#define kTestFontDir "/data/minikin/test/data/" + +const char kEmojiFont[] = kTestFontDir "Emoji.ttf"; +const char kJAFont[] = kTestFontDir "Ja.ttf"; +const char kKOFont[] = kTestFontDir "Ko.ttf"; +const char kLatinBoldFont[] = kTestFontDir "Bold.ttf"; +const char kLatinBoldItalicFont[] = kTestFontDir "BoldItalic.ttf"; +const char kLatinFont[] = kTestFontDir "Regular.ttf"; +const char kLatinItalicFont[] = kTestFontDir "Italic.ttf"; +const char kZH_HansFont[] = kTestFontDir "ZhHans.ttf"; +const char kZH_HantFont[] = kTestFontDir "ZhHant.ttf"; // Utility function for calling itemize function. void itemize(FontCollection* collection, const char* str, FontStyle style, @@ -52,7 +55,7 @@ const std::string& getFontPath(const FontCollection::Run& run) { } TEST(FontCollectionItemizeTest, itemize_latin) { - std::unique_ptr collection = getFontCollection(); + std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; const FontStyle kRegularStyle = FontStyle(); @@ -122,7 +125,7 @@ TEST(FontCollectionItemizeTest, itemize_latin) { } TEST(FontCollectionItemizeTest, itemize_emoji) { - std::unique_ptr collection = getFontCollection(); + std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; itemize(collection.get(), "U+1F469 U+1F467", FontStyle(), &runs); @@ -143,6 +146,28 @@ TEST(FontCollectionItemizeTest, itemize_emoji) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + itemize(collection.get(), "U+1F470 U+20E3", FontStyle(), &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(3, runs[0].end); + EXPECT_EQ(kEmojiFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + itemize(collection.get(), "U+242EE U+1F470 U+20E3", FontStyle(), &runs); + ASSERT_EQ(2U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + EXPECT_EQ(2, runs[1].start); + EXPECT_EQ(5, runs[1].end); + EXPECT_EQ(kEmojiFont, getFontPath(runs[1])); + EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeItalic()); + // Currently there is no fonts which has a glyph for 'a' + U+20E3, so they // are splitted into two. itemize(collection.get(), "'a' U+20E3", FontStyle(), &runs); @@ -161,7 +186,7 @@ TEST(FontCollectionItemizeTest, itemize_emoji) { } TEST(FontCollectionItemizeTest, itemize_non_latin) { - std::unique_ptr collection = getFontCollection(); + std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; FontStyle kJAStyle = FontStyle(FontLanguage("ja_JP", 5)); @@ -239,7 +264,7 @@ TEST(FontCollectionItemizeTest, itemize_non_latin) { } TEST(FontCollectionItemizeTest, itemize_mixed) { - std::unique_ptr collection = getFontCollection(); + std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; FontStyle kUSStyle = FontStyle(FontLanguage("en_US", 5)); @@ -278,7 +303,7 @@ TEST(FontCollectionItemizeTest, itemize_mixed) { } TEST(FontCollectionItemizeTest, itemize_variationSelector) { - std::unique_ptr collection = getFontCollection(); + std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; // A glyph for U+4FAE is provided by both Japanese font and Simplified @@ -392,17 +417,17 @@ TEST(FontCollectionItemizeTest, itemize_variationSelector) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); itemize(collection.get(), "U+FE00", kZH_HantStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); } TEST(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { - std::unique_ptr collection = getFontCollection(); + std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; // A glyph for U+845B is provided by both Japanese font and Simplified @@ -517,17 +542,17 @@ TEST(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); itemize(collection.get(), "U+E0100", kZH_HantStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kLatinFont, getFontPath(runs[0])); + EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); } TEST(FontCollectionItemizeTest, itemize_no_crash) { - std::unique_ptr collection = getFontCollection(); + std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; // Broken Surrogate pairs. Check only not crashing. @@ -551,7 +576,7 @@ TEST(FontCollectionItemizeTest, itemize_no_crash) { } TEST(FontCollectionItemizeTest, itemize_fakery) { - std::unique_ptr collection = getFontCollection(); + std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; FontStyle kJABoldStyle = FontStyle(FontLanguage("ja_JP", 5), 0, 7, false); diff --git a/engine/src/flutter/tests/FontTestUtils.cpp b/engine/src/flutter/tests/FontTestUtils.cpp index e5d6c2a4481..8e1d184adcc 100644 --- a/engine/src/flutter/tests/FontTestUtils.cpp +++ b/engine/src/flutter/tests/FontTestUtils.cpp @@ -19,13 +19,12 @@ #include #include +#include #include "MinikinFontForTest.h" -const char kFontDir[] = "/system/fonts/"; -const char kFontXml[] = "/system/etc/fonts.xml"; - -std::unique_ptr getFontCollection() { - xmlDoc* doc = xmlReadFile(kFontXml, NULL, 0); +std::unique_ptr getFontCollection( + const char* fontDir, const char* fontXml) { + xmlDoc* doc = xmlReadFile(fontXml, NULL, 0); xmlNode* familySet = xmlDocGetRootElement(doc); std::vector families; @@ -59,13 +58,11 @@ std::unique_ptr getFontCollection() { xmlGetProp(fontNode, (const xmlChar*)"style"), (const xmlChar*)"italic") == 0; xmlChar* fontFileName = xmlNodeListGetString(doc, fontNode->xmlChildrenNode, 1); - std::string fontPath = kFontDir + std::string((const char*)fontFileName); + std::string fontPath = fontDir + std::string((const char*)fontFileName); xmlFree(fontFileName); - if (access(fontPath.c_str(), R_OK) != 0) { - // Skip not accessible fonts. - continue; - } + LOG_ALWAYS_FATAL_IF(access(fontPath.c_str(), R_OK) != 0, + "%s is not found", fontPath.c_str()); family->addFont(new MinikinFontForTest(fontPath), android::FontStyle(weight, italic)); } diff --git a/engine/src/flutter/tests/FontTestUtils.h b/engine/src/flutter/tests/FontTestUtils.h index d53956f2d55..7c62c464074 100644 --- a/engine/src/flutter/tests/FontTestUtils.h +++ b/engine/src/flutter/tests/FontTestUtils.h @@ -25,6 +25,7 @@ * This function reads /system/etc/fonts.xml and make font families and * collections of them. MinikinFontForTest is used for FontFamily creation. */ -std::unique_ptr getFontCollection(); +std::unique_ptr getFontCollection( + const char* fontDir, const char* fontXml); #endif // MINIKIN_FONT_TEST_UTILS_H From 6e98debfaf50ad0d301fef2d2b656ba175b2e02c Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 29 Oct 2015 11:39:58 -0700 Subject: [PATCH 121/364] Accept variation selector in emoji sequences - DO NOT MERGE This patch basically ignores variation selectors for the purpose of itemization into font runs. This allows GSUB to be applied when input sequences contain variation selectors. Bug: 25368653 Change-Id: I9c1d325ae0cd322c21b7e850d0ec4d73551b2372 --- engine/src/flutter/libs/minikin/FontCollection.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index b4bfe313ba4..2bcbc037793 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -167,6 +167,10 @@ static bool isStickyWhitelisted(uint32_t c) { return false; } +static bool isVariationSelector(uint32_t c) { + return (0xFE00 <= c && c <= 0xFE0F) || (0xE0100 <= c && c <= 0xE01EF); +} + void FontCollection::itemize(const uint16_t *string, size_t string_size, FontStyle style, vector* result) const { FontLanguage lang = style.getLanguage(); @@ -184,9 +188,11 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty nShorts = 2; } } - // Continue using existing font as long as it has coverage and is whitelisted + // Continue using existing font as long as it has coverage and is whitelisted; + // also variation sequences continue existing run. if (lastFamily == NULL - || !(isStickyWhitelisted(ch) && lastFamily->getCoverage()->get(ch))) { + || !((isStickyWhitelisted(ch) && lastFamily->getCoverage()->get(ch)) + || isVariationSelector(ch))) { FontFamily* family = getFamilyForChar(ch, lang, variant); if (i == 0 || family != lastFamily) { size_t start = i; From d40c0c59e446196c0beff54968913205f7f6fe28 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 2 Nov 2015 17:17:24 -0800 Subject: [PATCH 122/364] Suppress linebreaks in emoji ZWJ sequences - DO NOT MERGE Due to the way emoji ZWJ sequences are defined, the ICU line breaking algorithm determines that there are valid line breaks inside the sequence. This patch suppresses these line breaks. Bug: 25433289 Change-Id: I225ebebc0f4186e4b8f48fee399c4a62b3f0218a --- .../src/flutter/libs/minikin/LineBreaker.cpp | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index a832ca20e26..77374feaa0d 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -17,6 +17,7 @@ #define VERBOSE_DEBUG 0 #include +#include #define LOG_TAG "Minikin" #include @@ -30,6 +31,7 @@ namespace android { const int CHAR_TAB = 0x0009; const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; +const uint16_t CHAR_ZWJ = 0x200D; // Large scores in a hierarchy; we prefer desperate breaks to an overfull line. All these // constants are larger than any reasonable actual width score. @@ -123,6 +125,32 @@ static bool isLineBreakingHyphen(uint16_t c) { c == 0x2E40); // DOUBLE HYPHEN } +/** + * Determine whether a line break at position i within the buffer buf is valid. This + * represents customization beyond the ICU behavior, because plain ICU provides some + * line break opportunities that we don't want. + **/ +static bool isBreakValid(uint16_t codeUnit, const uint16_t* buf, size_t bufEnd, size_t i) { + if (codeUnit == CHAR_SOFT_HYPHEN) { + return false; + } + if (codeUnit == CHAR_ZWJ) { + // Possible emoji ZWJ sequence + uint32_t next_codepoint; + U16_NEXT(buf, i, bufEnd, next_codepoint); + if (next_codepoint == 0x2764 || // HEAVY BLACK HEART + next_codepoint == 0x1F466 || // BOY + next_codepoint == 0x1F467 || // GIRL + next_codepoint == 0x1F468 || // MAN + next_codepoint == 0x1F469 || // WOMAN + next_codepoint == 0x1F48B || // KISS MARK + next_codepoint == 0x1F5E8) { // LEFT SPEECH BUBBLE + return false; + } + } + return true; +} + // Ordinarily, this method measures the text in the range given. However, when paint // is nullptr, it assumes the widths have already been calculated and stored in the // width buffer. @@ -175,8 +203,9 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa } if (i + 1 == current) { // Override ICU's treatment of soft hyphen as a break opportunity, because we want it - // to be a hyphen break, with penalty and drawing behavior. - if (c != CHAR_SOFT_HYPHEN) { + // to be a hyphen break, with penalty and drawing behavior. Also, suppress line + // breaks within emoji ZWJ sequences. + if (isBreakValid(c, mTextBuf.data(), end, i + 1)) { // TODO: Add a new type of HyphenEdit for breaks whose hyphen already exists, so // we can pass the whole word down to Hyphenator like the soft hyphen case. bool wordEndsInHyphen = isLineBreakingHyphen(c); From 77476fc5b9de291cacdeaccdf0f54300795a755a Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 21 Oct 2015 23:48:50 +0900 Subject: [PATCH 123/364] Introduce FontCollection::hasVariationSelector method. To implement Paint.hasGlyph(), we need a new method to ask the FontCollection if it has a glyph for the code point and variation selector pair. Bug: 11256006 Change-Id: Ie4185c91bcaa4d01aee6beb97784b1f9d2a88f12 --- .../flutter/include/minikin/FontCollection.h | 5 ++ .../flutter/libs/minikin/FontCollection.cpp | 22 ++++++ engine/src/flutter/tests/Android.mk | 1 + .../src/flutter/tests/FontCollectionTest.cpp | 78 +++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 engine/src/flutter/tests/FontCollectionTest.cpp diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index ca24e386a03..09c9356e094 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -40,6 +40,11 @@ public: void itemize(const uint16_t *string, size_t string_length, FontStyle style, std::vector* result) const; + // Returns true if there is a glyph for the code point and variation selector pair. + // Returns false if no fonts have a glyph for the code point and variation + // selector pair, or invalid variation selector is passed. + bool hasVariationSelector(uint32_t baseCodepoint, uint32_t variationSelector) const; + // Get the base font for the given style, useful for font-wide metrics. MinikinFont* baseFont(FontStyle style); diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 9fe0686e29f..74974137ecf 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -67,6 +67,10 @@ FontCollection::FontCollection(const vector& typefaces) : "Font collection must have at least one valid typeface"); size_t nPages = (mMaxChar + kPageMask) >> kLogCharsPerPage; size_t offset = 0; + // TODO: Use variation selector map for mRanges construction. + // A font can have a glyph for a base code point and variation selector pair but no glyph for + // the base code point without variation selector. The family won't be listed in the range in + // this case. for (size_t i = 0; i < nPages; i++) { Range dummy; mRanges.push_back(dummy); @@ -177,6 +181,24 @@ static bool isVariationSelector(uint32_t c) { return (0xFE00 <= c && c <= 0xFE0F) || (0xE0100 <= c && c <= 0xE01EF); } +bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, + uint32_t variationSelector) const { + if (!isVariationSelector(variationSelector)) { + return false; + } + if (baseCodepoint >= mMaxChar) { + return false; + } + // Currently mRanges can not be used here since it isn't aware of the variation sequence. + // TODO: Use mRanges for narrowing down the search range. + for (size_t i = 0; i < mFamilies.size(); i++) { + if (mFamilies[i]->hasVariationSelector(baseCodepoint, variationSelector)) { + return true; + } + } + return false; +} + void FontCollection::itemize(const uint16_t *string, size_t string_size, FontStyle style, vector* result) const { FontLanguage lang = style.getLanguage(); diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index b6bc15c0dcf..d12dca72e3b 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -39,6 +39,7 @@ LOCAL_STATIC_LIBRARIES += \ libxml2 LOCAL_SRC_FILES += \ + FontCollectionTest.cpp \ FontCollectionItemizeTest.cpp \ FontFamilyTest.cpp \ FontTestUtils.cpp \ diff --git a/engine/src/flutter/tests/FontCollectionTest.cpp b/engine/src/flutter/tests/FontCollectionTest.cpp new file mode 100644 index 00000000000..593575617f2 --- /dev/null +++ b/engine/src/flutter/tests/FontCollectionTest.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2015 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 + +#include +#include "MinikinFontForTest.h" +#include "MinikinInternal.h" + +namespace android { + +// The test font has following glyphs. +// U+82A6 +// U+82A6 U+FE00 (VS1) +// U+82A6 U+E0100 (VS17) +// U+82A6 U+E0101 (VS18) +// U+82A6 U+E0102 (VS19) +// U+845B +// U+845B U+FE01 (VS2) +// U+845B U+E0101 (VS18) +// U+845B U+E0102 (VS19) +// U+845B U+E0103 (VS20) +// U+537F +// U+717D U+FE02 (VS3) +// U+717D U+E0102 (VS19) +// U+717D U+E0103 (VS20) +const char kVsTestFont[] = "/data/minikin/test/data/VarioationSelectorTest-Regular.ttf"; + +void expectVSGlyphs(const FontCollection& fc, uint32_t codepoint, const std::set& vsSet) { + for (uint32_t vs = 0xFE00; vs <= 0xE01EF; ++vs) { + // Move to variation selectors supplements after variation selectors. + if (vs == 0xFF00) { + vs = 0xE0100; + } + if (vsSet.find(vs) == vsSet.end()) { + EXPECT_FALSE(fc.hasVariationSelector(codepoint, vs)) + << "Glyph for U+" << std::hex << codepoint << " U+" << vs; + } else { + EXPECT_TRUE(fc.hasVariationSelector(codepoint, vs)) + << "Glyph for U+" << std::hex << codepoint << " U+" << vs; + } + } +} + +TEST(FontCollectionTest, hasVariationSelectorTest) { + FontFamily* family = new FontFamily(); + family->addFont(new MinikinFontForTest(kVsTestFont)); + std::vector families({family}); + FontCollection fc(families); + family->Unref(); + + EXPECT_FALSE(fc.hasVariationSelector(0x82A6, 0)); + expectVSGlyphs(fc, 0x82A6, std::set({0xFE00, 0xE0100, 0xE0101, 0xE0102})); + + EXPECT_FALSE(fc.hasVariationSelector(0x845B, 0)); + expectVSGlyphs(fc, 0x845B, std::set({0xFE01, 0xE0101, 0xE0102, 0xE0103})); + + EXPECT_FALSE(fc.hasVariationSelector(0x537F, 0)); + expectVSGlyphs(fc, 0x537F, std::set({})); + + EXPECT_FALSE(fc.hasVariationSelector(0x717D, 0)); + expectVSGlyphs(fc, 0x717D, std::set({0xFE02, 0xE0102, 0xE0103})); +} + +} // namespace android From 3700f235084f994bac5f86ebdd874d3b85a0bdc6 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 18 Nov 2015 20:25:27 +0900 Subject: [PATCH 124/364] Search all families instead of using mRanges for variation sequence. To optimize the font family search, mRanges is used for narrowing down the search range. However, mRanges is constructed from format 4 or format 12 entries. So, if the font supports a variation sequence but doesn't support the base character of the sequence, the font may not be listed in mRanges. The proper way to fix this issue is using format 14 subtable information for mRanges construction. However, this is not a trivial work since currently we rely on HarfBuzz for variation sequence lookup and it doesn't provide any API for retrieving coverage information. Thus, as the quick fix, iterate all font families in font fallback chain if the variation sequence is specified. Change-Id: I278da84be8fb8f553590e2e42ed450b7e4a34eca --- .../flutter/libs/minikin/FontCollection.cpp | 15 ++++++++-- .../tests/FontCollectionItemizeTest.cpp | 29 +++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 9fe0686e29f..d2c5a3b9a9a 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -108,14 +108,25 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, if (ch >= mMaxChar) { return NULL; } - const Range& range = mRanges[ch >> kLogCharsPerPage]; + + // Even if the font supports variation sequence, mRanges isn't aware of the base character of + // the sequence. Search all FontFamilies if variation sequence is specified. + // TODO: Always use mRanges for font search. + const std::vector& familyVec = (vs == 0) ? mFamilyVec : mFamilies; + Range range; + if (vs == 0) { + range = mRanges[ch >> kLogCharsPerPage]; + } else { + range = { 0, mFamilies.size() }; + } + #ifdef VERBOSE_DEBUG ALOGD("querying range %zd:%zd\n", range.start, range.end); #endif FontFamily* bestFamily = nullptr; int bestScore = -1; for (size_t i = range.start; i < range.end; i++) { - FontFamily* family = mFamilyVec[i]; + FontFamily* family = familyVec[i]; if (vs == 0 ? family->getCoverage()->get(ch) : family->hasVariationSelector(ch, vs)) { // First font family in collection always matches if (mFamilies[0] == family) { diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index ae1cbf47dbb..47f5259c733 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -21,6 +21,7 @@ #include "UnicodeUtils.h" using android::FontCollection; +using android::FontFamily; using android::FontLanguage; using android::FontStyle; @@ -614,3 +615,31 @@ TEST(FontCollectionItemizeTest, itemize_fakery) { EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeItalic()); } +TEST(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { + // kVSTestFont supports U+717D U+FE02 but doesn't support U+717D. + // kVSTestFont should be selected for U+717D U+FE02 even if it does not support the base code + // point. + const std::string kVSTestFont = kTestFontDir "VarioationSelectorTest-Regular.ttf"; + + std::vector families; + FontFamily* family1 = new FontFamily(FontLanguage(), android::VARIANT_DEFAULT); + family1->addFont(new MinikinFontForTest(kLatinFont)); + families.push_back(family1); + + FontFamily* family2 = new FontFamily(FontLanguage(), android::VARIANT_DEFAULT); + family2->addFont(new MinikinFontForTest(kVSTestFont)); + families.push_back(family2); + + FontCollection collection(families); + + std::vector runs; + + itemize(&collection, "U+717D U+FE02", FontStyle(), &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kVSTestFont, getFontPath(runs[0])); + + family1->Unref(); + family2->Unref(); +} From 371e5dbb3f61fbfb653eed4fa2e452f8978419ff Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 30 Nov 2015 15:04:59 -0800 Subject: [PATCH 125/364] Avoid integer overflows in parsing fonts A malformed TTF can cause size calculations to overflow. This patch checks the maximum reasonable value so that the total size fits in 32 bits. It also adds some explicit casting to avoid possible technical undefined behavior when parsing sized unsigned values. Bug: 25645298 Change-Id: Id4716132041a6f4f1fbb73ec4e445391cf7d9616 --- engine/src/flutter/libs/minikin/CmapCoverage.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/CmapCoverage.cpp b/engine/src/flutter/libs/minikin/CmapCoverage.cpp index 75033729e31..64310006fd7 100644 --- a/engine/src/flutter/libs/minikin/CmapCoverage.cpp +++ b/engine/src/flutter/libs/minikin/CmapCoverage.cpp @@ -29,11 +29,12 @@ namespace android { // These could perhaps be optimized to use __builtin_bswap16 and friends. static uint32_t readU16(const uint8_t* data, size_t offset) { - return data[offset] << 8 | data[offset + 1]; + return ((uint32_t)data[offset]) << 8 | ((uint32_t)data[offset + 1]); } static uint32_t readU32(const uint8_t* data, size_t offset) { - return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]; + return ((uint32_t)data[offset]) << 24 | ((uint32_t)data[offset + 1]) << 16 | + ((uint32_t)data[offset + 2]) << 8 | ((uint32_t)data[offset + 3]); } static void addRange(vector &coverage, uint32_t start, uint32_t end) { @@ -101,11 +102,13 @@ static bool getCoverageFormat12(vector& coverage, const uint8_t* data, const size_t kGroupSize = 12; const size_t kStartCharCodeOffset = 0; const size_t kEndCharCodeOffset = 4; + const size_t kMaxNGroups = 0xfffffff0 / kGroupSize; // protection against overflow + // For all values < kMaxNGroups, kFirstGroupOffset + nGroups * kGroupSize fits in 32 bits. if (kFirstGroupOffset > size) { return false; } uint32_t nGroups = readU32(data, kNGroupsOffset); - if (kFirstGroupOffset + nGroups * kGroupSize > size) { + if (nGroups >= kMaxNGroups || kFirstGroupOffset + nGroups * kGroupSize > size) { return false; } for (uint32_t i = 0; i < nGroups; i++) { From 1fd1c390217da22a54b49e9a91bc79b0323e6a73 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 30 Nov 2015 15:04:59 -0800 Subject: [PATCH 126/364] Avoid integer overflows in parsing fonts A malformed TTF can cause size calculations to overflow. This patch checks the maximum reasonable value so that the total size fits in 32 bits. It also adds some explicit casting to avoid possible technical undefined behavior when parsing sized unsigned values. Bug: 25645298 Change-Id: Id4716132041a6f4f1fbb73ec4e445391cf7d9616 (cherry picked from commit 371e5dbb3f61fbfb653eed4fa2e452f8978419ff) --- engine/src/flutter/libs/minikin/CmapCoverage.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/CmapCoverage.cpp b/engine/src/flutter/libs/minikin/CmapCoverage.cpp index 4156d69d5a1..8be45d173c5 100644 --- a/engine/src/flutter/libs/minikin/CmapCoverage.cpp +++ b/engine/src/flutter/libs/minikin/CmapCoverage.cpp @@ -30,11 +30,12 @@ namespace android { // These could perhaps be optimized to use __builtin_bswap16 and friends. static uint32_t readU16(const uint8_t* data, size_t offset) { - return data[offset] << 8 | data[offset + 1]; + return ((uint32_t)data[offset]) << 8 | ((uint32_t)data[offset + 1]); } static uint32_t readU32(const uint8_t* data, size_t offset) { - return data[offset] << 24 | data[offset + 1] << 16 | data[offset + 2] << 8 | data[offset + 3]; + return ((uint32_t)data[offset]) << 24 | ((uint32_t)data[offset + 1]) << 16 | + ((uint32_t)data[offset + 2]) << 8 | ((uint32_t)data[offset + 3]); } static void addRange(vector &coverage, uint32_t start, uint32_t end) { @@ -101,11 +102,13 @@ static bool getCoverageFormat12(vector& coverage, const uint8_t* data, const size_t kGroupSize = 12; const size_t kStartCharCodeOffset = 0; const size_t kEndCharCodeOffset = 4; + const size_t kMaxNGroups = 0xfffffff0 / kGroupSize; // protection against overflow + // For all values < kMaxNGroups, kFirstGroupOffset + nGroups * kGroupSize fits in 32 bits. if (kFirstGroupOffset > size) { return false; } uint32_t nGroups = readU32(data, kNGroupsOffset); - if (kFirstGroupOffset + nGroups * kGroupSize > size) { + if (nGroups >= kMaxNGroups || kFirstGroupOffset + nGroups * kGroupSize > size) { return false; } for (uint32_t i = 0; i < nGroups; i++) { From c047506ec25e0ed90f77b0fa127ef5644b4e1b0e Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 29 Oct 2015 18:59:30 +0900 Subject: [PATCH 127/364] Select emoji font based on variation selectors. If U+FE0E is appended to the emoji code point, the glyph should have a text presentation. On the other hand, if U+FE0F is appended to the emoji code point, the glyph should have an emoji presentation. Bug: 11256006 Change-Id: I5187d44500b13a138e7ffbcf2c72e2da06374c8c --- .../src/flutter/include/minikin/FontFamily.h | 4 +- .../flutter/libs/minikin/FontCollection.cpp | 30 +- .../src/flutter/libs/minikin/FontFamily.cpp | 29 +- .../tests/FontCollectionItemizeTest.cpp | 261 +++++++++++++++++- engine/src/flutter/tests/FontFamilyTest.cpp | 13 + 5 files changed, 316 insertions(+), 21 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index fc05e3b2196..776bcc41beb 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -48,6 +48,7 @@ public: operator bool() const { return mBits != 0; } bool isUnsupported() const { return mBits == kUnsupportedLanguage; } + bool hasEmojiFlag() const { return isUnsupported() ? false : (mBits & kEmojiFlag); } std::string getString() const; @@ -61,9 +62,10 @@ private: static const uint32_t kUnsupportedLanguage = 0xFFFFFFFFu; static const uint32_t kBaseLangMask = 0xFFFFFFu; - static const uint32_t kScriptMask = (1u << 26) - (1u << 24); static const uint32_t kHansFlag = 1u << 24; static const uint32_t kHantFlag = 1u << 25; + static const uint32_t kEmojiFlag = 1u << 26; + static const uint32_t kScriptMask = kHansFlag | kHantFlag | kEmojiFlag; uint32_t mBits; }; diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index ea702226af2..d089e8b0d90 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -106,7 +106,15 @@ FontCollection::~FontCollection() { // 2. If a font matches both language and script, it gets a score of 4. // 3. If a font matches just language, it gets a score of 2. // 4. Matching the "compact" or "elegant" variant adds one to the score. -// 5. Highest score wins, with ties resolved to the first font. +// 5. If there is a variation selector and a font supports the complete variation sequence, we add +// 12 to the score. +// 6. If there is a color variation selector (U+FE0F), we add 6 to the score if the font is an emoji +// font. This additional score of 6 is only given if the base character is supported in the font, +// but not the whole variation sequence. +// 7. If there is a text variation selector (U+FE0E), we add 6 to the score if the font is not an +// emoji font. This additional score of 6 is only given if the base character is supported in the +// font, but not the whole variation sequence. +// 8. Highest score wins, with ties resolved to the first font. FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, FontLanguage lang, int variant) const { if (ch >= mMaxChar) { @@ -131,27 +139,29 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, int bestScore = -1; for (size_t i = range.start; i < range.end; i++) { FontFamily* family = familyVec[i]; - if (vs == 0 ? family->getCoverage()->get(ch) : family->hasVariationSelector(ch, vs)) { - // First font family in collection always matches - if (mFamilies[0] == family) { + const bool hasVSGlyph = (vs != 0) && family->hasVariationSelector(ch, vs); + if (hasVSGlyph || family->getCoverage()->get(ch)) { + if ((vs == 0 || hasVSGlyph) && mFamilies[0] == family) { + // If the first font family in collection supports the given character or sequence, + // always use it. return family; } int score = lang.match(family->lang()) * 2; if (family->variant() == 0 || family->variant() == variant) { score++; } + if (hasVSGlyph) { + score += 12; + } else if (((vs == 0xFE0F) && family->lang().hasEmojiFlag()) || + ((vs == 0xFE0E) && !family->lang().hasEmojiFlag())) { + score += 6; + } if (score > bestScore) { bestScore = score; bestFamily = family; } } } - if (bestFamily == nullptr && vs != 0) { - // If no fonts support the codepoint and variation selector pair, - // fallback to select a font family that supports just the base - // character, ignoring the variation selector. - return getFamilyForChar(ch, 0, lang, variant); - } if (bestFamily == nullptr && !mFamilyVec.empty()) { UErrorCode errorCode = U_ZERO_ERROR; const UNormalizer2* normalizer = unorm2_getNFDInstance(&errorCode); diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 1ff5a6bce4b..5adff57b6ec 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -62,11 +62,15 @@ FontLanguage::FontLanguage(const char* buf, size_t size) { uint16_t c = buf[next]; if (c == '-' || c == '_') break; } - if (next - i == 4 && buf[i] == 'H' && buf[i+1] == 'a' && buf[i+2] == 'n') { - if (buf[i+3] == 's') { - bits |= kHansFlag; - } else if (buf[i+3] == 't') { - bits |= kHantFlag; + if (next - i == 4) { + if (buf[i] == 'H' && buf[i+1] == 'a' && buf[i+2] == 'n') { + if (buf[i+3] == 's') { + bits |= kHansFlag; + } else if (buf[i+3] == 't') { + bits |= kHantFlag; + } + } else if (buf[i] == 'Q' && buf[i+1] == 'a' && buf[i+2] == 'a'&& buf[i+3] == 'e') { + bits |= kEmojiFlag; } } // TODO: this might be a good place to infer script from country (zh_TW -> Hant), @@ -96,10 +100,17 @@ std::string FontLanguage::getString() const { buf[i++] = 'd'; } buf[i++] = '-'; - buf[i++] = 'H'; - buf[i++] = 'a'; - buf[i++] = 'n'; - buf[i++] = (mBits & kHansFlag) ? 's' : 't'; + if (mBits & kEmojiFlag) { + buf[i++] = 'Q'; + buf[i++] = 'a'; + buf[i++] = 'a'; + buf[i++] = 'e'; + } else { + buf[i++] = 'H'; + buf[i++] = 'a'; + buf[i++] = 'n'; + buf[i++] = (mBits & kHansFlag) ? 's' : 't'; + } } return std::string(buf, i); } diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index 47f5259c733..a7da4269a69 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -25,9 +25,9 @@ using android::FontFamily; using android::FontLanguage; using android::FontStyle; -const char kItemizeFontXml[] = "/data/minikin/test/data/itemize.xml"; #define kTestFontDir "/data/minikin/test/data/" +const char kItemizeFontXml[] = kTestFontDir "itemize.xml"; const char kEmojiFont[] = kTestFontDir "Emoji.ttf"; const char kJAFont[] = kTestFontDir "Ja.ttf"; const char kKOFont[] = kTestFontDir "Ko.ttf"; @@ -38,6 +38,12 @@ const char kLatinItalicFont[] = kTestFontDir "Italic.ttf"; const char kZH_HansFont[] = kTestFontDir "ZhHans.ttf"; const char kZH_HantFont[] = kTestFontDir "ZhHant.ttf"; +const char kEmojiXmlFile[] = kTestFontDir "emoji.xml"; +const char kNoGlyphFont[] = kTestFontDir "NoGlyphFont.ttf"; +const char kColorEmojiFont[] = kTestFontDir "ColorEmojiFont.ttf"; +const char kTextEmojiFont[] = kTestFontDir "TextEmojiFont.ttf"; +const char kMixedEmojiFont[] = kTestFontDir "ColorTextMixedEmojiFont.ttf"; + // Utility function for calling itemize function. void itemize(FontCollection* collection, const char* str, FontStyle style, std::vector* result) { @@ -52,6 +58,7 @@ void itemize(FontCollection* collection, const char* str, FontStyle style, // Utility function to obtain font path associated with run. const std::string& getFontPath(const FontCollection::Run& run) { + EXPECT_NE(nullptr, run.fakedFont.font); return ((MinikinFontForTest*)run.fakedFont.font)->fontPath(); } @@ -425,6 +432,21 @@ TEST(FontCollectionItemizeTest, itemize_variationSelector) { EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); + + // First font family (Regular.ttf) supports U+203C but doesn't support U+203C U+FE0F. + // Emoji.ttf font supports supports U+203C U+FE0F. Emoji.ttf should be selected. + itemize(collection.get(), "U+203C U+FE0F", kZH_HantStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kEmojiFont, getFontPath(runs[0])); + + // First font family (Regular.ttf) supports U+203C U+FE0E. + itemize(collection.get(), "U+203C U+FE0E", kZH_HantStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kLatinFont, getFontPath(runs[0])); } TEST(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { @@ -643,3 +665,240 @@ TEST(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { family1->Unref(); family2->Unref(); } + +TEST(FontCollectionItemizeTest, itemize_emojiSelection) { + std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); + std::vector runs; + + const FontStyle kDefaultFontStyle; + + // U+00A9 is a text default emoji which is only available in TextEmojiFont.ttf. + // TextEmojiFont.ttf should be selected. + itemize(collection.get(), "U+00A9", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + + // U+00AE is a text default emoji which is only available in ColorEmojiFont.ttf. + // ColorEmojiFont.ttf should be selected. + itemize(collection.get(), "U+00AE", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + // U+203C is a text default emoji which is available in both TextEmojiFont.ttf and + // ColorEmojiFont.ttf. TextEmojiFont.ttf should be selected. + itemize(collection.get(), "U+203C", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + // TODO: use text font for text default emoji. + // EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + + // U+2049 is a text default emoji which is not available in either TextEmojiFont.ttf or + // ColorEmojiFont.ttf. No font should be selected. + itemize(collection.get(), "U+2049", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); + + // U+231A is a emoji default emoji which is available only in TextEmojiFont.ttf. + // TextEmojiFont.ttf should be selected. + itemize(collection.get(), "U+231A", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + + // U+231B is a emoji default emoji which is available only in ColorEmojiFont.ttf. + // ColorEmojiFont.ttf should be selected. + itemize(collection.get(), "U+231B", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + // U+23E9 is a emoji default emoji which is available in both TextEmojiFont.ttf and + // ColorEmojiFont.ttf. ColorEmojiFont should be selected. + itemize(collection.get(), "U+23E9", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + // U+23EA is a emoji default emoji which is not avaialble in either TextEmojiFont.ttf and + // ColorEmojiFont.ttf. No font should b e selected. + itemize(collection.get(), "U+23EA", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); +} + +TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { + std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); + std::vector runs; + + const FontStyle kDefaultFontStyle; + + // U+00A9 is a text default emoji which is only available in TextEmojiFont.ttf. + // TextEmojiFont.ttf should be selected. + itemize(collection.get(), "U+00A9 U+FE0E", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + + // U+00A9 is a text default emoji which is only available in ColorEmojiFont.ttf. + // ColorEmojiFont.ttf should be selected. + itemize(collection.get(), "U+00AE U+FE0E", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + // Text emoji is specified but it is not available. Use color emoji instead. + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + // U+203C is a text default emoji which is available in both TextEmojiFont.ttf and + // ColorEmojiFont.ttf. TextEmojiFont.ttf should be selected. + itemize(collection.get(), "U+203C U+FE0E", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + + // U+2049 is a text default emoji which is not available either TextEmojiFont.ttf or + // ColorEmojiFont.ttf. No font should be selected. + itemize(collection.get(), "U+2049 U+FE0E", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); + + // U+231A is a emoji default emoji which is available only in TextEmojifFont. + // TextEmojiFont.ttf sohuld be selected. + itemize(collection.get(), "U+231A U+FE0E", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + + // U+231B is a emoji default emoji which is available only in ColorEmojiFont.ttf. + // ColorEmojiFont.ttf should be selected. + itemize(collection.get(), "U+231B U+FE0E", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + // Text emoji is specified but it is not available. Use color emoji instead. + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + // U+23E9 is a emoji default emoji which is available in both TextEmojiFont.ttf and + // ColorEmojiFont.ttf. TextEmojiFont.ttf should be selected even if U+23E9 is emoji default + // emoji since U+FE0E is appended. + itemize(collection.get(), "U+23E9 U+FE0E", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + + // U+23EA is a emoji default emoji but which is not available in either TextEmojiFont.ttf or + // ColorEmojiFont.ttf. No font should be selected. + itemize(collection.get(), "U+23EA U+FE0E", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); + + // U+26FA U+FE0E is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F + // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. + itemize(collection.get(), "U+26FA U+FE0E", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kMixedEmojiFont, getFontPath(runs[0])); +} + +TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { + std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); + std::vector runs; + + const FontStyle kDefaultFontStyle; + + // U+00A9 is a text default emoji which is available only in TextEmojiFont.ttf. + // TextEmojiFont.ttf shoudl be selected. + itemize(collection.get(), "U+00A9 U+FE0F", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + // Color emoji is specified but it is not available. Use text representaion instead. + EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + + // U+00AE is a text default emoji which is available only in ColorEmojiFont.ttf. + // ColorEmojiFont.ttf should be selected. + itemize(collection.get(), "U+00AE U+FE0F", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + // U+203C is a text default emoji which is available in both TextEmojiFont.ttf and + // ColorEmojiFont.ttf. ColorEmojiFont.ttf should be selected even if U+203C is a text default + // emoji since U+FF0F is appended. + itemize(collection.get(), "U+203C U+FE0F", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + // U+2049 is a text default emoji which is not available in either TextEmojiFont.ttf or + // ColorEmojiFont.ttf. No font should be selected. + itemize(collection.get(), "U+2049 U+FE0F", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); + + // U+231A is a emoji default emoji which is available only in TextEmojiFont.ttf. + // TextEmojiFont.ttf should be selected. + itemize(collection.get(), "U+231A U+FE0F", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + // Color emoji is specified but it is not available. Use text representation instead. + EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + + // U+231B is a emoji default emoji which is available only in ColorEmojiFont.ttf. + // ColorEmojiFont.ttf should be selected. + itemize(collection.get(), "U+231B U+FE0F", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + // U+23E9 is a emoji default emoji which is available in both TextEmojiFont.ttf and + // ColorEmojiFont.ttf. ColorEmojiFont.ttf should be selected. + itemize(collection.get(), "U+23E9 U+FE0F", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + // U+23EA is a emoji default emoji which is not available in either TextEmojiFont.ttf or + // ColorEmojiFont.ttf. No font should be selected. + itemize(collection.get(), "U+23EA U+FE0F", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); + + // U+26F9 U+FE0F is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F + // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. + itemize(collection.get(), "U+26F9 U+FE0F", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kMixedEmojiFont, getFontPath(runs[0])); +} + diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index 78f286c0ca6..d46245cd1fd 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -70,6 +70,19 @@ TEST(FontLanguagesTest, repeatedLanguageTests) { EXPECT_EQ(english, langs[0]); } +TEST(FontLanguagesTest, undEmojiTests) { + FontLanguage emoji("und-Qaae", 8); + EXPECT_TRUE(emoji.hasEmojiFlag()); + + FontLanguage und("und", 3); + EXPECT_FALSE(und.hasEmojiFlag()); + EXPECT_FALSE(emoji == und); + + FontLanguage undExample("und-example", 10); + EXPECT_FALSE(undExample.hasEmojiFlag()); + EXPECT_FALSE(emoji == undExample); +} + // The test font has following glyphs. // U+82A6 // U+82A6 U+FE00 (VS1) From 091810c32bf9bd14db7749e957eb76d731527057 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 2 Dec 2015 11:07:29 +0900 Subject: [PATCH 128/364] Introduce FontLanguageListCache. FontLanguageListCache is an intentionally leaky singleton and its internal cache won't be purged. BUG: 25122318 Change-Id: I272097e979fe44b83fd86822235350e12eda8f51 --- .../flutter/include/minikin/FontCollection.h | 2 +- .../src/flutter/include/minikin/FontFamily.h | 37 ++++++----- engine/src/flutter/libs/minikin/Android.mk | 1 + .../flutter/libs/minikin/FontCollection.cpp | 21 ++++-- .../src/flutter/libs/minikin/FontFamily.cpp | 28 ++++++++ .../libs/minikin/FontLanguageListCache.cpp | 66 +++++++++++++++++++ .../libs/minikin/FontLanguageListCache.h | 55 ++++++++++++++++ engine/src/flutter/libs/minikin/Layout.cpp | 9 ++- engine/src/flutter/tests/Android.mk | 1 + .../tests/FontCollectionItemizeTest.cpp | 23 +++---- engine/src/flutter/tests/FontFamilyTest.cpp | 22 +++++++ .../tests/FontLanguageListCacheTest.cpp | 61 +++++++++++++++++ 12 files changed, 291 insertions(+), 35 deletions(-) create mode 100644 engine/src/flutter/libs/minikin/FontLanguageListCache.cpp create mode 100644 engine/src/flutter/libs/minikin/FontLanguageListCache.h create mode 100644 engine/src/flutter/tests/FontLanguageListCacheTest.cpp diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 09c9356e094..cd14261640c 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -65,7 +65,7 @@ private: size_t end; }; - FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, FontLanguage lang, int variant) const; + FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const; // static for allocating unique id's static uint32_t sNextId; diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 776bcc41beb..539a06cef01 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -87,35 +87,42 @@ private: }; // FontStyle represents all style information needed to select an actual font -// from a collection. The implementation is packed into a single 32-bit word +// from a collection. The implementation is packed into two 32-bit words // so it can be efficiently copied, embedded in other objects, etc. class FontStyle { public: - FontStyle(int weight = 4, bool italic = false) { - bits = (weight & kWeightMask) | (italic ? kItalicMask : 0); - } - FontStyle(FontLanguage lang, int variant = 0, int weight = 4, bool italic = false) { - bits = (weight & kWeightMask) | (italic ? kItalicMask : 0) - | (variant << kVariantShift) | (lang.bits() << kLangShift); - } - FontStyle(FontLanguages langs, int variant = 0, int weight = 4, bool italic = false) : - // TODO: Use all the languages in langs - FontStyle(langs[0], variant, weight, italic) { } + FontStyle() : FontStyle(0 /* variant */, 4 /* weight */, false /* italic */) {} + FontStyle(int weight, bool italic) : FontStyle(0 /* variant */, weight, italic) {} + FontStyle(uint32_t langListId) + : FontStyle(langListId, 0 /* variant */, 4 /* weight */, false /* italic */) {} + + FontStyle(int variant, int weight, bool italic); + FontStyle(uint32_t langListId, int variant, int weight, bool italic); + int getWeight() const { return bits & kWeightMask; } bool getItalic() const { return (bits & kItalicMask) != 0; } int getVariant() const { return (bits >> kVariantShift) & kVariantMask; } - FontLanguage getLanguage() const { return FontLanguage(bits >> kLangShift); } + uint32_t getLanguageListId() const { return mLanguageListId; } - bool operator==(const FontStyle other) const { return bits == other.bits; } + bool operator==(const FontStyle other) const { + return bits == other.bits && mLanguageListId == other.mLanguageListId; + } - hash_t hash() const { return bits; } + hash_t hash() const; + + // Looks up a language list from an internal cache and returns its ID. + // If the passed language list is not in the cache, registers it and returns newly assigned ID. + static uint32_t registerLanguageList(const std::string& languages); private: static const uint32_t kWeightMask = (1 << 4) - 1; static const uint32_t kItalicMask = 1 << 4; static const int kVariantShift = 5; static const uint32_t kVariantMask = (1 << 2) - 1; - static const int kLangShift = 7; + + static uint32_t pack(int variant, int weight, bool italic); + uint32_t bits; + uint32_t mLanguageListId; }; enum FontVariant { diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index c728b09b84e..4c945a60c9c 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -21,6 +21,7 @@ minikin_src_files := \ CmapCoverage.cpp \ FontCollection.cpp \ FontFamily.cpp \ + FontLanguageListCache.cpp \ GraphemeBreak.cpp \ HbFaceCache.cpp \ Hyphenator.cpp \ diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index d089e8b0d90..6201f7492f9 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -22,6 +22,7 @@ #include "unicode/unistr.h" #include "unicode/unorm2.h" +#include "FontLanguageListCache.h" #include "MinikinInternal.h" #include @@ -116,11 +117,15 @@ FontCollection::~FontCollection() { // font, but not the whole variation sequence. // 8. Highest score wins, with ties resolved to the first font. FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, - FontLanguage lang, int variant) const { + uint32_t langListId, int variant) const { if (ch >= mMaxChar) { return NULL; } + const FontLanguages& langList = FontLanguageListCache::getById(langListId); + // TODO: use all languages in langList. + const FontLanguage lang = (langList.size() == 0) ? FontLanguage() : langList[0]; + // Even if the font supports variation sequence, mRanges isn't aware of the base character of // the sequence. Search all FontFamilies if variation sequence is specified. // TODO: Always use mRanges for font search. @@ -162,6 +167,12 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, } } } + if (bestFamily == nullptr && vs != 0) { + // If no fonts support the codepoint and variation selector pair, + // fallback to select a font family that supports just the base + // character, ignoring the variation selector. + return getFamilyForChar(ch, 0, langListId, variant); + } if (bestFamily == nullptr && !mFamilyVec.empty()) { UErrorCode errorCode = U_ZERO_ERROR; const UNormalizer2* normalizer = unorm2_getNFDInstance(&errorCode); @@ -171,7 +182,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, if (U_SUCCESS(errorCode) && len > 0) { int off = 0; U16_NEXT_UNSAFE(decomposed, off, ch); - return getFamilyForChar(ch, vs, lang, variant); + return getFamilyForChar(ch, vs, langListId, variant); } } bestFamily = mFamilies[0]; @@ -222,7 +233,7 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, void FontCollection::itemize(const uint16_t *string, size_t string_size, FontStyle style, vector* result) const { - FontLanguage lang = style.getLanguage(); + const uint32_t langListId = style.getLanguageListId(); int variant = style.getVariant(); FontFamily* lastFamily = NULL; Run* run = NULL; @@ -261,8 +272,8 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } if (!shouldContinueRun) { - FontFamily* family = - getFamilyForChar(ch, isVariationSelector(nextCh) ? nextCh : 0, lang, variant); + FontFamily* family = getFamilyForChar(ch, isVariationSelector(nextCh) ? nextCh : 0, + langListId, variant); if (utf16Pos == 0 || family != lastFamily) { size_t start = utf16Pos; // Workaround for Emoji keycap until we implement per-cluster font diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 5adff57b6ec..5a3952437a3 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -26,6 +26,9 @@ #include #include +#include + +#include "FontLanguageListCache.h" #include "HbFaceCache.h" #include "MinikinInternal.h" #include @@ -159,6 +162,31 @@ FontLanguages::FontLanguages(const char* buf, size_t size) { } } +FontStyle::FontStyle(int variant, int weight, bool italic) + : FontStyle(FontLanguageListCache::kEmptyListId, variant, weight, italic) { +} + +FontStyle::FontStyle(uint32_t languageListId, int variant, int weight, bool italic) + : bits(pack(variant, weight, italic)), mLanguageListId(languageListId) { +} + +hash_t FontStyle::hash() const { + uint32_t hash = JenkinsHashMix(0, bits); + hash = JenkinsHashMix(hash, mLanguageListId); + return JenkinsHashWhiten(hash); +} + +// static +uint32_t FontStyle::registerLanguageList(const std::string& languages) { + AutoMutex _l(gMinikinLock); + return FontLanguageListCache::getId(languages); +} + +// static +uint32_t FontStyle::pack(int variant, int weight, bool italic) { + return (weight & kWeightMask) | (italic ? kItalicMask : 0) | (variant << kVariantShift); +} + FontFamily::~FontFamily() { for (size_t i = 0; i < mFonts.size(); i++) { mFonts[i].typeface->UnrefLocked(); diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp new file mode 100644 index 00000000000..e1c2343ddaa --- /dev/null +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2015 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. + */ + +#define LOG_TAG "Minikin" + +#include "FontLanguageListCache.h" + +#include + +#include "MinikinInternal.h" + +namespace android { + +const uint32_t FontLanguageListCache::kEmptyListId; + +// static +uint32_t FontLanguageListCache::getId(const std::string& languages) { + FontLanguageListCache* inst = FontLanguageListCache::getInstance(); + std::unordered_map::const_iterator it = + inst->mLanguageListLookupTable.find(languages); + if (it != inst->mLanguageListLookupTable.end()) { + return it->second; + } + + // Given language list is not in cache. Insert it and return newly assigned ID. + const uint32_t nextId = inst->mLanguageLists.size(); + inst->mLanguageLists.push_back(FontLanguages(languages.c_str(), languages.size())); + inst->mLanguageListLookupTable.insert(std::make_pair(languages, nextId)); + return nextId; +} + +// static +const FontLanguages& FontLanguageListCache::getById(uint32_t id) { + FontLanguageListCache* inst = FontLanguageListCache::getInstance(); + LOG_ALWAYS_FATAL_IF(id >= inst->mLanguageLists.size(), "Lookup by unknown language list ID."); + return inst->mLanguageLists[id]; +} + +// static +FontLanguageListCache* FontLanguageListCache::getInstance() { + assertMinikinLocked(); + static FontLanguageListCache* instance = nullptr; + if (instance == nullptr) { + instance = new FontLanguageListCache(); + + // Insert an empty language list for mapping empty language list to kEmptyListId. + instance->mLanguageLists.push_back(FontLanguages()); + instance->mLanguageListLookupTable.insert(std::make_pair("", kEmptyListId)); + } + return instance; +} + +} // namespace android diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.h b/engine/src/flutter/libs/minikin/FontLanguageListCache.h new file mode 100644 index 00000000000..7d627b562e3 --- /dev/null +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2015 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_LANGUAGE_LIST_CACHE_H +#define MINIKIN_FONT_LANGUAGE_LIST_CACHE_H + +#include + +#include + +namespace android { + +class FontLanguageListCache { +public: + // A special ID for the empty language list. + // This value must be 0 since the empty language list is inserted into mLanguageLists by + // default. + const static uint32_t kEmptyListId = 0; + + // Returns language list ID for the given string representation of FontLanguages. + // Caller should acquire a lock before calling the method. + static uint32_t getId(const std::string& languages); + + // Caller should acquire a lock before calling the method. + static const FontLanguages& getById(uint32_t id); + +private: + FontLanguageListCache() {} // Singleton + ~FontLanguageListCache() {} + + // Caller should acquire a lock before calling the method. + static FontLanguageListCache* getInstance(); + + std::vector mLanguageLists; + + // A map from string representation of the font language list to the ID. + std::unordered_map mLanguageListLookupTable; +}; + +} // namespace android + +#endif // MINIKIN_FONT_LANGUAGE_LIST_CACHE_H diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 3b140faa2b8..af5e6fe75a7 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -34,6 +34,7 @@ #include #include +#include "FontLanguageListCache.h" #include "LayoutUtils.h" #include "HbFaceCache.h" #include "MinikinInternal.h" @@ -742,9 +743,11 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t hb_buffer_clear_contents(buffer); hb_buffer_set_script(buffer, script); hb_buffer_set_direction(buffer, isRtl? HB_DIRECTION_RTL : HB_DIRECTION_LTR); - FontLanguage language = ctx->style.getLanguage(); - if (language) { - string lang = language.getString(); + const FontLanguages& langList = + FontLanguageListCache::getById(ctx->style.getLanguageListId()); + if (langList.size() != 0) { + // TODO: use all languages in langList. + string lang = langList[0].getString(); hb_buffer_set_language(buffer, hb_language_from_string(lang.c_str(), -1)); } hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart); diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index d12dca72e3b..2eb2abe2a22 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -42,6 +42,7 @@ LOCAL_SRC_FILES += \ FontCollectionTest.cpp \ FontCollectionItemizeTest.cpp \ FontFamilyTest.cpp \ + FontLanguageListCacheTest.cpp \ FontTestUtils.cpp \ MinikinFontForTest.cpp \ GraphemeBreakTests.cpp \ diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index a7da4269a69..d0dc39c9743 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -197,9 +197,9 @@ TEST(FontCollectionItemizeTest, itemize_non_latin) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; - FontStyle kJAStyle = FontStyle(FontLanguage("ja_JP", 5)); - FontStyle kUSStyle = FontStyle(FontLanguage("en_US", 5)); - FontStyle kZH_HansStyle = FontStyle(FontLanguage("zh_Hans", 7)); + FontStyle kJAStyle = FontStyle(FontStyle::registerLanguageList("ja_JP")); + FontStyle kUSStyle = FontStyle(FontStyle::registerLanguageList("en_US")); + FontStyle kZH_HansStyle = FontStyle(FontStyle::registerLanguageList("zh_Hans")); // All Japanese Hiragana characters. itemize(collection.get(), "U+3042 U+3044 U+3046 U+3048 U+304A", kUSStyle, &runs); @@ -275,7 +275,7 @@ TEST(FontCollectionItemizeTest, itemize_mixed) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; - FontStyle kUSStyle = FontStyle(FontLanguage("en_US", 5)); + FontStyle kUSStyle = FontStyle(FontStyle::registerLanguageList("en_US")); itemize(collection.get(), "'a' U+4F60 'b' U+4F60 'c'", kUSStyle, &runs); ASSERT_EQ(5U, runs.size()); @@ -318,8 +318,8 @@ TEST(FontCollectionItemizeTest, itemize_variationSelector) { // Chinese font. Also a glyph for U+242EE is provided by both Japanese and // Traditional Chinese font. To avoid effects of device default locale, // explicitly specify the locale. - FontStyle kZH_HansStyle = FontStyle(FontLanguage("zh_Hans", 7)); - FontStyle kZH_HantStyle = FontStyle(FontLanguage("zh_Hant", 7)); + FontStyle kZH_HansStyle = FontStyle(FontStyle::registerLanguageList("zh_Hans")); + FontStyle kZH_HantStyle = FontStyle(FontStyle::registerLanguageList("zh_Hant")); // U+4FAE is available in both zh_Hans and ja font, but U+4FAE,U+FE00 is // only available in ja font. @@ -457,8 +457,8 @@ TEST(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { // Chinese font. Also a glyph for U+242EE is provided by both Japanese and // Traditional Chinese font. To avoid effects of device default locale, // explicitly specify the locale. - FontStyle kZH_HansStyle = FontStyle(FontLanguage("zh_Hans", 7)); - FontStyle kZH_HantStyle = FontStyle(FontLanguage("zh_Hant", 7)); + FontStyle kZH_HansStyle = FontStyle(FontStyle::registerLanguageList("zh_Hans")); + FontStyle kZH_HantStyle = FontStyle(FontStyle::registerLanguageList("zh_Hant")); // U+845B is available in both zh_Hans and ja font, but U+845B,U+E0100 is // only available in ja font. @@ -602,9 +602,10 @@ TEST(FontCollectionItemizeTest, itemize_fakery) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; - FontStyle kJABoldStyle = FontStyle(FontLanguage("ja_JP", 5), 0, 7, false); - FontStyle kJAItalicStyle = FontStyle(FontLanguage("ja_JP", 5), 0, 5, true); - FontStyle kJABoldItalicStyle = FontStyle(FontLanguage("ja_JP", 5), 0, 7, true); + FontStyle kJABoldStyle = FontStyle(FontStyle::registerLanguageList("ja_JP"), 0, 7, false); + FontStyle kJAItalicStyle = FontStyle(FontStyle::registerLanguageList("ja_JP"), 0, 5, true); + FontStyle kJABoldItalicStyle = + FontStyle(FontStyle::registerLanguageList("ja_JP"), 0, 7, true); // Currently there is no italic or bold font for Japanese. FontFakery has // the differences between desired and actual font style. diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index d46245cd1fd..fa8302c60cc 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -17,6 +17,7 @@ #include #include +#include "FontLanguageListCache.h" #include "MinikinFontForTest.h" #include "MinikinInternal.h" @@ -83,6 +84,27 @@ TEST(FontLanguagesTest, undEmojiTests) { EXPECT_FALSE(emoji == undExample); } +TEST(FontLanguagesTest, registerLanguageListTest) { + EXPECT_EQ(0UL, FontStyle::registerLanguageList("")); + EXPECT_NE(0UL, FontStyle::registerLanguageList("en")); + EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); + EXPECT_NE(0UL, FontStyle::registerLanguageList("en,zh-Hans")); + + EXPECT_EQ(FontStyle::registerLanguageList("en"), FontStyle::registerLanguageList("en")); + EXPECT_NE(FontStyle::registerLanguageList("en"), FontStyle::registerLanguageList("jp")); + + EXPECT_EQ(FontStyle::registerLanguageList("en,zh-Hans"), + FontStyle::registerLanguageList("en,zh-Hans")); + EXPECT_NE(FontStyle::registerLanguageList("en,zh-Hans"), + FontStyle::registerLanguageList("zh-Hans,en")); + EXPECT_NE(FontStyle::registerLanguageList("en,zh-Hans"), + FontStyle::registerLanguageList("jp")); + EXPECT_NE(FontStyle::registerLanguageList("en,zh-Hans"), + FontStyle::registerLanguageList("en")); + EXPECT_NE(FontStyle::registerLanguageList("en,zh-Hans"), + FontStyle::registerLanguageList("en,zh-Hant")); +} + // The test font has following glyphs. // U+82A6 // U+82A6 U+FE00 (VS1) diff --git a/engine/src/flutter/tests/FontLanguageListCacheTest.cpp b/engine/src/flutter/tests/FontLanguageListCacheTest.cpp new file mode 100644 index 00000000000..29757fedceb --- /dev/null +++ b/engine/src/flutter/tests/FontLanguageListCacheTest.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2015 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 + +#include +#include "FontLanguageListCache.h" + +namespace android { + +TEST(FontLanguageListCacheTest, getId) { + EXPECT_EQ(0UL, FontLanguageListCache::getId("")); + EXPECT_NE(0UL, FontStyle::registerLanguageList("en")); + EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); + EXPECT_NE(0UL, FontStyle::registerLanguageList("en,zh-Hans")); + + EXPECT_EQ(FontLanguageListCache::getId("en"), FontLanguageListCache::getId("en")); + EXPECT_NE(FontLanguageListCache::getId("en"), FontLanguageListCache::getId("jp")); + + EXPECT_EQ(FontLanguageListCache::getId("en,zh-Hans"), + FontLanguageListCache::getId("en,zh-Hans")); + EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), + FontLanguageListCache::getId("zh-Hans,en")); + EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), + FontLanguageListCache::getId("jp")); + EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), + FontLanguageListCache::getId("en")); + EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), + FontLanguageListCache::getId("en,zh-Hant")); +} + +TEST(FontLanguageListCacheTest, getById) { + FontLanguage english("en", 2); + FontLanguage japanese("jp", 2); + + EXPECT_EQ(0UL, FontLanguageListCache::getById(0).size()); + + FontLanguages langs = FontLanguageListCache::getById(FontLanguageListCache::getId("en")); + ASSERT_EQ(1UL, langs.size()); + EXPECT_EQ(english, langs[0]); + + langs = FontLanguageListCache::getById(FontLanguageListCache::getId("en,jp")); + ASSERT_EQ(2UL, langs.size()); + EXPECT_EQ(english, langs[0]); + EXPECT_EQ(japanese, langs[1]); +} + +} // android From 01c7dcc124296b1fbf1abb8af115d92021b0e6cd Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Mon, 7 Dec 2015 10:28:31 -0800 Subject: [PATCH 129/364] Copy test font files into data directory. To work native tests with additional font related files, copy the files into /data/nativetest/minikin_tests/. This copy only happens when the minikin_tests is built. It is not an expected to copy the font files into the product image. Change-Id: I7d83abc077bce4e38fd93c7d607bc7e1f7871e6b --- engine/src/flutter/tests/Android.mk | 40 ++++++++++++++++++- .../tests/FontCollectionItemizeTest.cpp | 2 - .../src/flutter/tests/FontCollectionTest.cpp | 2 +- engine/src/flutter/tests/FontFamilyTest.cpp | 2 +- engine/src/flutter/tests/how_to_run.txt | 2 +- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index 2eb2abe2a22..044e65de2ea 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -16,12 +16,49 @@ LOCAL_PATH := $(call my-dir) +data_root_for_test_zip := $(TARGET_OUT_DATA)/DATA/ +minikin_tests_subpath_from_data := nativetest/minikin_tests +minikin_tests_root_in_device := /data/$(minikin_tests_subpath_from_data) +minikin_tests_root_for_test_zip := $(data_root_for_test_zip)/$(minikin_tests_subpath_from_data) + +define build-one-test-font-module +$(eval include $(CLEAR_VARS))\ +$(eval LOCAL_MODULE := $(1))\ +$(eval LOCAL_SRC_FILES := $(1))\ +$(eval LOCAL_MODULE_CLASS := ETC)\ +$(eval LOCAL_MODULE_TAGS := tests)\ +$(eval LOCAL_MODULE_PATH := $(minikin_tests_root_for_test_zip))\ +$(eval include $(BUILD_PREBUILT)) +endef + +font_src_files := \ + data/BoldItalic.ttf \ + data/Bold.ttf \ + data/ColorEmojiFont.ttf \ + data/ColorTextMixedEmojiFont.ttf \ + data/Emoji.ttf \ + data/Italic.ttf \ + data/Ja.ttf \ + data/Ko.ttf \ + data/NoGlyphFont.ttf \ + data/Regular.ttf \ + data/TextEmojiFont.ttf \ + data/VarioationSelectorTest-Regular.ttf \ + data/ZhHans.ttf \ + data/ZhHant.ttf \ + data/itemize.xml \ + data/emoji.xml + +$(foreach f, $(font_src_files), $(call build-one-test-font-module, $(f))) + include $(CLEAR_VARS) LOCAL_MODULE := minikin_tests LOCAL_MODULE_TAGS := tests LOCAL_STATIC_LIBRARIES := libminikin +LOCAL_ADDITIONAL_DEPENDENCIES = $(font_src_files) +LOCAL_PICKUP_FILES := $(data_root_for_test_zip) # Shared libraries which are dependencies of minikin; these are not automatically # pulled in by the build system (and thus sadly must be repeated). @@ -56,6 +93,7 @@ LOCAL_C_INCLUDES := \ external/libxml2/include \ external/skia/src/core -LOCAL_CPPFLAGS += -Werror -Wall -Wextra +LOCAL_CPPFLAGS += -Werror -Wall -Wextra \ + -DkTestFontDir="\"$(minikin_tests_root_in_device)/data/\"" include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index d0dc39c9743..57ed6ee33dd 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -25,8 +25,6 @@ using android::FontFamily; using android::FontLanguage; using android::FontStyle; -#define kTestFontDir "/data/minikin/test/data/" - const char kItemizeFontXml[] = kTestFontDir "itemize.xml"; const char kEmojiFont[] = kTestFontDir "Emoji.ttf"; const char kJAFont[] = kTestFontDir "Ja.ttf"; diff --git a/engine/src/flutter/tests/FontCollectionTest.cpp b/engine/src/flutter/tests/FontCollectionTest.cpp index 593575617f2..bbc53e3645f 100644 --- a/engine/src/flutter/tests/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/FontCollectionTest.cpp @@ -37,7 +37,7 @@ namespace android { // U+717D U+FE02 (VS3) // U+717D U+E0102 (VS19) // U+717D U+E0103 (VS20) -const char kVsTestFont[] = "/data/minikin/test/data/VarioationSelectorTest-Regular.ttf"; +const char kVsTestFont[] = kTestFontDir "/VarioationSelectorTest-Regular.ttf"; void expectVSGlyphs(const FontCollection& fc, uint32_t codepoint, const std::set& vsSet) { for (uint32_t vs = 0xFE00; vs <= 0xE01EF; ++vs) { diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index fa8302c60cc..fc44e6c6369 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -120,7 +120,7 @@ TEST(FontLanguagesTest, registerLanguageListTest) { // U+717D U+FE02 (VS3) // U+717D U+E0102 (VS19) // U+717D U+E0103 (VS20) -const char kVsTestFont[] = "/data/minikin/test/data/VarioationSelectorTest-Regular.ttf"; +const char kVsTestFont[] = kTestFontDir "VarioationSelectorTest-Regular.ttf"; class FontFamilyTest : public testing::Test { public: diff --git a/engine/src/flutter/tests/how_to_run.txt b/engine/src/flutter/tests/how_to_run.txt index 09c3b0614ef..a135c30e130 100644 --- a/engine/src/flutter/tests/how_to_run.txt +++ b/engine/src/flutter/tests/how_to_run.txt @@ -1,5 +1,5 @@ mmm -j8 frameworks/minikin/tests && adb push $OUT/data/nativetest/minikin_tests/minikin_tests \ /data/nativetest/minikin_tests/minikin_tests && -adb push -p frameworks/minikin/tests/data /data/minikin/test/data && +adb push frameworks/minikin/tests/data /data/nativetest/minikin_tests/data && adb shell /data/nativetest/minikin_tests/minikin_tests From eb3ba19800a187135045757193cd48a6599d5f15 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 9 Dec 2015 15:55:10 -0800 Subject: [PATCH 130/364] Remove script matching score from the font selection fallback. Removing the extra score of 2 for the script matching from the font fallback score calculation. If the two langauges have different scripts, we should treat them as different languages. Change-Id: Ie0d6f27bd1086248895935a7bd01b5d404044ad0 --- .../src/flutter/include/minikin/FontFamily.h | 2 +- .../flutter/libs/minikin/FontCollection.cpp | 23 +++++++++---------- .../src/flutter/libs/minikin/FontFamily.cpp | 12 +--------- .../tests/FontCollectionItemizeTest.cpp | 13 ++++++++++- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 539a06cef01..00130e6f5d0 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -52,7 +52,7 @@ public: std::string getString() const; - // 0 = no match, 1 = language matches, 2 = language and script match + // 0 = no match, 1 = language matches int match(const FontLanguage other) const; private: diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 6201f7492f9..bba2ef95359 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -104,18 +104,17 @@ FontCollection::~FontCollection() { // Implement heuristic for choosing best-match font. Here are the rules: // 1. If first font in the collection has the character, it wins. -// 2. If a font matches both language and script, it gets a score of 4. -// 3. If a font matches just language, it gets a score of 2. -// 4. Matching the "compact" or "elegant" variant adds one to the score. -// 5. If there is a variation selector and a font supports the complete variation sequence, we add -// 12 to the score. -// 6. If there is a color variation selector (U+FE0F), we add 6 to the score if the font is an emoji -// font. This additional score of 6 is only given if the base character is supported in the font, +// 2. If a font matches language, it gets a score of 2. +// 3. Matching the "compact" or "elegant" variant adds one to the score. +// 4. If there is a variation selector and a font supports the complete variation sequence, we add +// 8 to the score. +// 5. If there is a color variation selector (U+FE0F), we add 4 to the score if the font is an emoji +// font. This additional score of 4 is only given if the base character is supported in the font, // but not the whole variation sequence. -// 7. If there is a text variation selector (U+FE0E), we add 6 to the score if the font is not an -// emoji font. This additional score of 6 is only given if the base character is supported in the +// 6. If there is a text variation selector (U+FE0E), we add 4 to the score if the font is not an +// emoji font. This additional score of 4 is only given if the base character is supported in the // font, but not the whole variation sequence. -// 8. Highest score wins, with ties resolved to the first font. +// 7. Highest score wins, with ties resolved to the first font. FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const { if (ch >= mMaxChar) { @@ -156,10 +155,10 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, score++; } if (hasVSGlyph) { - score += 12; + score += 8; } else if (((vs == 0xFE0F) && family->lang().hasEmojiFlag()) || ((vs == 0xFE0E) && !family->lang().hasEmojiFlag())) { - score += 6; + score += 4; } if (score > bestScore) { bestScore = score; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 5a3952437a3..76398312406 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -119,17 +119,7 @@ std::string FontLanguage::getString() const { } int FontLanguage::match(const FontLanguage other) const { - if (mBits == kUnsupportedLanguage || other.mBits == kUnsupportedLanguage) - return 0; - - int result = 0; - if ((mBits & kBaseLangMask) == (other.mBits & kBaseLangMask)) { - result++; - if ((mBits & kScriptMask) != 0 && (mBits & kScriptMask) == (other.mBits & kScriptMask)) { - result++; - } - } - return result; + return *this == other; } FontLanguages::FontLanguages(const char* buf, size_t size) { diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index 57ed6ee33dd..85d76afccb8 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -164,7 +164,7 @@ TEST(FontCollectionItemizeTest, itemize_emoji) { ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); @@ -267,6 +267,17 @@ TEST(FontCollectionItemizeTest, itemize_non_latin) { EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); + + // Both zh-Hant and ja fonts support U+242EE, but zh-Hans doesn't. + // Here, ja and zh-Hant font should have the same score but ja should be selected since it is + // listed before zh-Hant. + itemize(collection.get(), "U+242EE", kZH_HansStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kJAFont, getFontPath(runs[0])); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); + EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); } TEST(FontCollectionItemizeTest, itemize_mixed) { From 10fbe684fbabfb51112bcd44e7f2a80d5c9807cb Mon Sep 17 00:00:00 2001 From: Dan Austin Date: Fri, 11 Dec 2015 16:33:23 -0800 Subject: [PATCH 131/364] Refactored unsigned long negations Replaced two instances of negating an unsigned long, which was resulting in aborts from unsigned integer sanitization with the equivalent logical not-add 1. Bug: 25884483 Change-Id: Ic7498e0af638dcd438ce69803021d3cdc3acd4f6 --- engine/src/flutter/libs/minikin/SparseBitSet.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/SparseBitSet.cpp b/engine/src/flutter/libs/minikin/SparseBitSet.cpp index 7acb7ba345b..9d1fd308bc5 100644 --- a/engine/src/flutter/libs/minikin/SparseBitSet.cpp +++ b/engine/src/flutter/libs/minikin/SparseBitSet.cpp @@ -90,13 +90,13 @@ void SparseBitSet::initFromRanges(const uint32_t* ranges, size_t nRanges) { size_t nElements = (end - (start & ~kElMask) + kElMask) >> kLogBitsPerEl; if (nElements == 1) { mBitmaps[index] |= (kElAllOnes >> (start & kElMask)) & - (kElAllOnes << ((-end) & kElMask)); + (kElAllOnes << ((~end + 1) & kElMask)); } else { mBitmaps[index] |= kElAllOnes >> (start & kElMask); for (size_t j = 1; j < nElements - 1; j++) { mBitmaps[index + j] = kElAllOnes; } - mBitmaps[index + nElements - 1] |= kElAllOnes << ((-end) & kElMask); + mBitmaps[index + nElements - 1] |= kElAllOnes << ((~end + 1) & kElMask); } for (size_t j = startPage + 1; j < endPage + 1; j++) { mIndices[j] = (currentPage++) << (kLogValuesPerPage - kLogBitsPerEl); From e745083812e73e180543f11b274d3b44c972350d Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 15 Dec 2015 16:01:51 -0800 Subject: [PATCH 132/364] No op build should not build minikin_tests Previous CL[1] adds module names into LOCAL_ADDITIONAL_DEPENDENCIES, but it was wrong. LOCAL_ADDITIONAL_DEPENDENCIES only accepts file path. However, BUILD_PREBUILT doesn't provide a file path of the installed font. So use custom tool and LOCAL_GENERATED_SOURCES instead. Confirmed no-op build doesn't built minikin_tests and continuous_native_tests.zip contains all necessary files. [1]: I7d83abc077bce4e38fd93c7d607bc7e1f7871e6b BUG: 26197092 Change-Id: I90e80036248ae72e0e0f9c6144a259f5f96ec9ce --- engine/src/flutter/tests/Android.mk | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index 044e65de2ea..2483b763c42 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -16,21 +16,13 @@ LOCAL_PATH := $(call my-dir) +include $(CLEAR_VARS) + data_root_for_test_zip := $(TARGET_OUT_DATA)/DATA/ minikin_tests_subpath_from_data := nativetest/minikin_tests minikin_tests_root_in_device := /data/$(minikin_tests_subpath_from_data) minikin_tests_root_for_test_zip := $(data_root_for_test_zip)/$(minikin_tests_subpath_from_data) -define build-one-test-font-module -$(eval include $(CLEAR_VARS))\ -$(eval LOCAL_MODULE := $(1))\ -$(eval LOCAL_SRC_FILES := $(1))\ -$(eval LOCAL_MODULE_CLASS := ETC)\ -$(eval LOCAL_MODULE_TAGS := tests)\ -$(eval LOCAL_MODULE_PATH := $(minikin_tests_root_for_test_zip))\ -$(eval include $(BUILD_PREBUILT)) -endef - font_src_files := \ data/BoldItalic.ttf \ data/Bold.ttf \ @@ -49,15 +41,17 @@ font_src_files := \ data/itemize.xml \ data/emoji.xml -$(foreach f, $(font_src_files), $(call build-one-test-font-module, $(f))) - -include $(CLEAR_VARS) - LOCAL_MODULE := minikin_tests LOCAL_MODULE_TAGS := tests +GEN := $(addprefix $(minikin_tests_root_for_test_zip)/, $(font_src_files)) +$(GEN): PRIVATE_PATH := $(LOCAL_PATH) +$(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@ +$(GEN): $(minikin_tests_root_for_test_zip)/data/% : $(LOCAL_PATH)/data/% + $(transform-generated-source) +LOCAL_GENERATED_SOURCES += $(GEN) + LOCAL_STATIC_LIBRARIES := libminikin -LOCAL_ADDITIONAL_DEPENDENCIES = $(font_src_files) LOCAL_PICKUP_FILES := $(data_root_for_test_zip) # Shared libraries which are dependencies of minikin; these are not automatically From bb5c10092c3ec3246a9f4c52cd6b620e86fa5bd8 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Mon, 14 Dec 2015 18:33:23 -0800 Subject: [PATCH 133/364] Save all kind of script tags into FontLanguage. The main purpose of this CL is expanding FontLanguage to be able to save full script tag. Previously, FontLangauge kept only limited script tags. With this CL, FontLanguage keeps all script tags. This CL contains the following changes: - FontLanguage changes: -- Moved to private directory not to be instantiated outside of Minikin. -- Removed bool(), bits(), FontLanguage(uint32_t) methods which are no longer used. -- Change the FontLanguage internal data structure. -- Introduces script match logic. - FontLanguages changes: -- Moved to private directory not to be instantiated outside of Minikin. -- This is now std::vector - FontLanguageListCache changes: -- Now FontLanguageListCache::getId through FontStyle::registerLanguageList is the only way to instantiate the FontLanguage. -- Normalize input to be BCP47 compliant identifier by ICU. Bug: 26168983 Change-Id: I8df992a6851021903478972601a9a5c9424b100c --- .../src/flutter/include/minikin/FontFamily.h | 64 +---- engine/src/flutter/libs/minikin/Android.mk | 1 + .../flutter/libs/minikin/FontCollection.cpp | 10 +- .../src/flutter/libs/minikin/FontFamily.cpp | 120 +-------- .../src/flutter/libs/minikin/FontLanguage.cpp | 135 ++++++++++ .../src/flutter/libs/minikin/FontLanguage.h | 89 +++++++ .../libs/minikin/FontLanguageListCache.cpp | 90 ++++++- .../libs/minikin/FontLanguageListCache.h | 1 + engine/src/flutter/libs/minikin/Layout.cpp | 13 +- .../tests/FontCollectionItemizeTest.cpp | 32 +-- engine/src/flutter/tests/FontFamilyTest.cpp | 232 ++++++++++++++++-- .../tests/FontLanguageListCacheTest.cpp | 18 +- engine/src/flutter/tests/FontTestUtils.cpp | 7 +- engine/src/flutter/tests/ICUTestBase.h | 52 ++++ 14 files changed, 639 insertions(+), 225 deletions(-) create mode 100644 engine/src/flutter/libs/minikin/FontLanguage.cpp create mode 100644 engine/src/flutter/libs/minikin/FontLanguage.h create mode 100644 engine/src/flutter/tests/ICUTestBase.h diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 00130e6f5d0..aa2e0ac2e4a 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -30,62 +30,6 @@ namespace android { class MinikinFont; -// FontLanguage is a compact representation of a bcp-47 language tag. It -// does not capture all possible information, only what directly affects -// font rendering. -class FontLanguage { - friend class FontStyle; - friend class FontLanguages; -public: - FontLanguage() : mBits(0) { } - - // Parse from string - FontLanguage(const char* buf, size_t size); - - bool operator==(const FontLanguage other) const { - return mBits != kUnsupportedLanguage && mBits == other.mBits; - } - operator bool() const { return mBits != 0; } - - bool isUnsupported() const { return mBits == kUnsupportedLanguage; } - bool hasEmojiFlag() const { return isUnsupported() ? false : (mBits & kEmojiFlag); } - - std::string getString() const; - - // 0 = no match, 1 = language matches - int match(const FontLanguage other) const; - -private: - explicit FontLanguage(uint32_t bits) : mBits(bits) { } - - uint32_t bits() const { return mBits; } - - static const uint32_t kUnsupportedLanguage = 0xFFFFFFFFu; - static const uint32_t kBaseLangMask = 0xFFFFFFu; - static const uint32_t kHansFlag = 1u << 24; - static const uint32_t kHantFlag = 1u << 25; - static const uint32_t kEmojiFlag = 1u << 26; - static const uint32_t kScriptMask = kHansFlag | kHantFlag | kEmojiFlag; - uint32_t mBits; -}; - -// A list of zero or more instances of FontLanguage, in the order of -// preference. Used for further resolution of rendering results. -class FontLanguages { -public: - FontLanguages() { mLangs.clear(); } - - // Parse from string, which is a comma-separated list of languages - FontLanguages(const char* buf, size_t size); - - const FontLanguage& operator[](size_t index) const { return mLangs.at(index); } - - size_t size() const { return mLangs.size(); } - -private: - std::vector mLangs; -}; - // FontStyle represents all style information needed to select an actual font // from a collection. The implementation is packed into two 32-bit words // so it can be efficiently copied, embedded in other objects, etc. @@ -158,7 +102,9 @@ class FontFamily : public MinikinRefCounted { public: FontFamily() : mHbFont(nullptr) { } - FontFamily(FontLanguage lang, int variant) : mLang(lang), mVariant(variant), mHbFont(nullptr) { + FontFamily(int variant); + + FontFamily(uint32_t langId, int variant) : mLangId(langId), mVariant(variant), mHbFont(nullptr) { } ~FontFamily(); @@ -169,7 +115,7 @@ public: void addFont(MinikinFont* typeface, FontStyle style); FakedFont getClosestMatch(FontStyle style) const; - FontLanguage lang() const { return mLang; } + uint32_t langId() const { return mLangId; } int variant() const { return mVariant; } // API's for enumerating the fonts in a family. These don't guarantee any particular order @@ -200,7 +146,7 @@ private: MinikinFont* typeface; FontStyle style; }; - FontLanguage mLang; + uint32_t mLangId; int mVariant; std::vector mFonts; diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 4c945a60c9c..42fdca39193 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -21,6 +21,7 @@ minikin_src_files := \ CmapCoverage.cpp \ FontCollection.cpp \ FontFamily.cpp \ + FontLanguage.cpp \ FontLanguageListCache.cpp \ GraphemeBreak.cpp \ HbFaceCache.cpp \ diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index bba2ef95359..62c70310c06 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -22,6 +22,7 @@ #include "unicode/unistr.h" #include "unicode/unorm2.h" +#include "FontLanguage.h" #include "FontLanguageListCache.h" #include "MinikinInternal.h" #include @@ -150,14 +151,17 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, // always use it. return family; } - int score = lang.match(family->lang()) * 2; + + // TODO use all language in the list. + FontLanguage fontLang = FontLanguageListCache::getById(family->langId())[0]; + int score = lang.match(fontLang) * 2; if (family->variant() == 0 || family->variant() == variant) { score++; } if (hasVSGlyph) { score += 8; - } else if (((vs == 0xFE0F) && family->lang().hasEmojiFlag()) || - ((vs == 0xFE0E) && !family->lang().hasEmojiFlag())) { + } else if (((vs == 0xFE0F) && fontLang.hasEmojiFlag()) || + ((vs == 0xFE0E) && !fontLang.hasEmojiFlag())) { score += 4; } if (score > bestScore) { diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 76398312406..14057890281 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -16,8 +16,6 @@ #define LOG_TAG "Minikin" -#include - #include #include #include @@ -28,6 +26,7 @@ #include +#include "FontLanguage.h" #include "FontLanguageListCache.h" #include "HbFaceCache.h" #include "MinikinInternal.h" @@ -41,117 +40,6 @@ using std::vector; namespace android { -// Parse bcp-47 language identifier into internal structure -FontLanguage::FontLanguage(const char* buf, size_t size) { - uint32_t bits = 0; - size_t i; - for (i = 0; i < size; i++) { - uint16_t c = buf[i]; - if (c == '-' || c == '_') break; - } - if (i == 2) { - bits = uint8_t(buf[0]) | (uint8_t(buf[1]) << 8); - } else if (i == 3) { - bits = uint8_t(buf[0]) | (uint8_t(buf[1]) << 8) | (uint8_t(buf[2]) << 16); - } else { - mBits = kUnsupportedLanguage; - // We don't understand anything other than two-letter or three-letter - // language codes, so we skip parsing the rest of the string. - return; - } - size_t next; - for (i++; i < size; i = next + 1) { - for (next = i; next < size; next++) { - uint16_t c = buf[next]; - if (c == '-' || c == '_') break; - } - if (next - i == 4) { - if (buf[i] == 'H' && buf[i+1] == 'a' && buf[i+2] == 'n') { - if (buf[i+3] == 's') { - bits |= kHansFlag; - } else if (buf[i+3] == 't') { - bits |= kHantFlag; - } - } else if (buf[i] == 'Q' && buf[i+1] == 'a' && buf[i+2] == 'a'&& buf[i+3] == 'e') { - bits |= kEmojiFlag; - } - } - // TODO: this might be a good place to infer script from country (zh_TW -> Hant), - // but perhaps it's up to the client to do that, before passing a string. - } - mBits = bits; -} - -std::string FontLanguage::getString() const { - if (mBits == kUnsupportedLanguage) { - return "und"; - } - char buf[16]; - size_t i = 0; - if (mBits & kBaseLangMask) { - buf[i++] = mBits & 0xFFu; - buf[i++] = (mBits >> 8) & 0xFFu; - char third_letter = (mBits >> 16) & 0xFFu; - if (third_letter != 0) buf[i++] = third_letter; - } - if (mBits & kScriptMask) { - if (!i) { - // This should not happen, but as it apparently has, we fill the language code part - // with "und". - buf[i++] = 'u'; - buf[i++] = 'n'; - buf[i++] = 'd'; - } - buf[i++] = '-'; - if (mBits & kEmojiFlag) { - buf[i++] = 'Q'; - buf[i++] = 'a'; - buf[i++] = 'a'; - buf[i++] = 'e'; - } else { - buf[i++] = 'H'; - buf[i++] = 'a'; - buf[i++] = 'n'; - buf[i++] = (mBits & kHansFlag) ? 's' : 't'; - } - } - return std::string(buf, i); -} - -int FontLanguage::match(const FontLanguage other) const { - return *this == other; -} - -FontLanguages::FontLanguages(const char* buf, size_t size) { - std::unordered_set seen; - mLangs.clear(); - const char* bufEnd = buf + size; - const char* lastStart = buf; - bool isLastLang = false; - while (true) { - const char* commaLoc = static_cast( - memchr(lastStart, ',', bufEnd - lastStart)); - if (commaLoc == NULL) { - commaLoc = bufEnd; - isLastLang = true; - } - FontLanguage lang(lastStart, commaLoc - lastStart); - if (isLastLang && mLangs.size() == 0) { - // Make sure the list has at least one member - mLangs.push_back(lang); - return; - } - uint32_t bits = lang.bits(); - if (bits != FontLanguage::kUnsupportedLanguage && seen.count(bits) == 0) { - mLangs.push_back(lang); - if (isLastLang) return; - seen.insert(bits); - } - if (isLastLang) return; - lastStart = commaLoc + 1; - } -} - FontStyle::FontStyle(int variant, int weight, bool italic) : FontStyle(FontLanguageListCache::kEmptyListId, variant, weight, italic) { } @@ -177,6 +65,9 @@ uint32_t FontStyle::pack(int variant, int weight, bool italic) { return (weight & kWeightMask) | (italic ? kItalicMask : 0) | (variant << kVariantShift); } +FontFamily::FontFamily(int variant) : FontFamily(FontLanguageListCache::kEmptyListId, variant) { +} + FontFamily::~FontFamily() { for (size_t i = 0; i < mFonts.size(); i++) { mFonts[i].typeface->UnrefLocked(); @@ -210,7 +101,8 @@ void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { addFontLocked(typeface, style); } -void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { typeface->RefLocked(); +void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { + typeface->RefLocked(); mFonts.push_back(Font(typeface, style)); mCoverageValid = false; } diff --git a/engine/src/flutter/libs/minikin/FontLanguage.cpp b/engine/src/flutter/libs/minikin/FontLanguage.cpp new file mode 100644 index 00000000000..3c12e06c6f1 --- /dev/null +++ b/engine/src/flutter/libs/minikin/FontLanguage.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2015 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. + */ + +#define LOG_TAG "Minikin" + +#include "FontLanguage.h" + +#include +#include + +namespace android { + +#define SCRIPT_TAG(c1, c2, c3, c4) \ + ((uint32_t)(c1)) << 24 | ((uint32_t)(c2)) << 16 | ((uint32_t)(c3)) << 8 | ((uint32_t)(c4)) + +// Parse BCP 47 language identifier into internal structure +FontLanguage::FontLanguage(const char* buf, size_t length) : FontLanguage() { + size_t i; + for (i = 0; i < length; i++) { + char c = buf[i]; + if (c == '-' || c == '_') break; + } + if (i == 2 || i == 3) { // only accept two or three letter language code. + mLanguage = buf[0] | (buf[1] << 8) | ((i == 3) ? (buf[2] << 16) : 0); + } else { + // We don't understand anything other than two-letter or three-letter + // language codes, so we skip parsing the rest of the string. + mLanguage = 0ul; + return; + } + + size_t next; + for (i++; i < length; i = next + 1) { + for (next = i; next < length; next++) { + char c = buf[next]; + if (c == '-' || c == '_') break; + } + if (next - i == 4 && 'A' <= buf[i] && buf[i] <= 'Z') { + mScript = SCRIPT_TAG(buf[i], buf[i + 1], buf[i + 2], buf[i + 3]); + } + } + + mSubScriptBits = scriptToSubScriptBits(mScript); +} + +//static +uint8_t FontLanguage::scriptToSubScriptBits(uint32_t script) { + uint8_t subScriptBits = 0u; + switch (script) { + case SCRIPT_TAG('H', 'a', 'n', 'g'): + subScriptBits = kHangulFlag; + break; + case SCRIPT_TAG('H', 'a', 'n', 'i'): + subScriptBits = kHanFlag; + break; + case SCRIPT_TAG('H', 'a', 'n', 's'): + subScriptBits = kHanFlag | kSimplifiedChineseFlag; + break; + case SCRIPT_TAG('H', 'a', 'n', 't'): + subScriptBits = kHanFlag | kTraditionalChineseFlag; + break; + case SCRIPT_TAG('H', 'i', 'r', 'a'): + subScriptBits = kHiraganaFlag; + break; + case SCRIPT_TAG('H', 'r', 'k', 't'): + subScriptBits = kKatakanaFlag | kHiraganaFlag; + break; + case SCRIPT_TAG('J', 'p', 'a', 'n'): + subScriptBits = kHanFlag | kKatakanaFlag | kHiraganaFlag; + break; + case SCRIPT_TAG('K', 'a', 'n', 'a'): + subScriptBits = kKatakanaFlag; + break; + case SCRIPT_TAG('K', 'o', 'r', 'e'): + subScriptBits = kHanFlag | kHangulFlag; + break; + case SCRIPT_TAG('Q', 'a', 'a', 'e'): + subScriptBits = kEmojiFlag; + break; + } + return subScriptBits; +} + +std::string FontLanguage::getString() const { + if (mLanguage == 0ul) { + return "und"; + } + char buf[16]; + size_t i = 0; + buf[i++] = mLanguage & 0xFF ; + buf[i++] = (mLanguage >> 8) & 0xFF; + char third_letter = (mLanguage >> 16) & 0xFF; + if (third_letter != 0) buf[i++] = third_letter; + if (mScript != 0) { + buf[i++] = '-'; + buf[i++] = (mScript >> 24) & 0xFFu; + buf[i++] = (mScript >> 16) & 0xFFu; + buf[i++] = (mScript >> 8) & 0xFFu; + buf[i++] = mScript & 0xFFu; + } + return std::string(buf, i); +} + +bool FontLanguage::isEqualScript(const FontLanguage other) const { + return other.mScript == mScript; +} + +bool FontLanguage::supportsHbScript(hb_script_t script) const { + static_assert(SCRIPT_TAG('J', 'p', 'a', 'n') == HB_TAG('J', 'p', 'a', 'n'), + "The Minikin script and HarfBuzz hb_script_t have different encodings."); + if (script == mScript) return true; + uint8_t requestedBits = scriptToSubScriptBits(script); + return requestedBits != 0 && (mSubScriptBits & requestedBits) == requestedBits; +} + +int FontLanguage::match(const FontLanguage other) const { + // TODO: Use script for matching. + return *this == other; +} + +#undef SCRIPT_TAG +} // namespace android diff --git a/engine/src/flutter/libs/minikin/FontLanguage.h b/engine/src/flutter/libs/minikin/FontLanguage.h new file mode 100644 index 00000000000..abe7d13179d --- /dev/null +++ b/engine/src/flutter/libs/minikin/FontLanguage.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2015 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_LANGUAGE_H +#define MINIKIN_FONT_LANGUAGE_H + +#include +#include + +#include + +namespace android { + +// FontLanguage is a compact representation of a BCP 47 language tag. It +// does not capture all possible information, only what directly affects +// font rendering. +struct FontLanguage { +public: + // Default constructor creates the unsupported language. + FontLanguage() : mScript(0ul), mLanguage(0ul), mSubScriptBits(0ul) {} + + // Parse from string + FontLanguage(const char* buf, size_t length); + + bool operator==(const FontLanguage other) const { + return !isUnsupported() && isEqualScript(other) && isEqualLanguage(other); + } + + bool operator!=(const FontLanguage other) const { + return !(*this == other); + } + + bool isUnsupported() const { return mLanguage == 0ul; } + bool hasEmojiFlag() const { return mSubScriptBits & kEmojiFlag; } + + bool isEqualLanguage(const FontLanguage other) const { return mLanguage == other.mLanguage; } + bool isEqualScript(const FontLanguage other) const; + + // Returns true if this script supports the given script. For example, ja-Jpan supports Hira, + // ja-Hira doesn't support Jpan. + bool supportsHbScript(hb_script_t script) const; + + std::string getString() const; + + // 0 = no match, 1 = language matches + int match(const FontLanguage other) const; + + uint64_t getIdentifier() const { return (uint64_t)mScript << 32 | (uint64_t)mLanguage; } + +private: + // ISO 15924 compliant script code. The 4 chars script code are packed into a 32 bit integer. + uint32_t mScript; + + // ISO 639-1 or ISO 639-2 compliant language code. + // The two or three letter language code is packed into 32 bit integer. + // mLanguage = 0 means the FontLanguage is unsupported. + uint32_t mLanguage; + + // For faster comparing, use 7 bits for specific scripts. + static const uint8_t kEmojiFlag = 1u; + static const uint8_t kHanFlag = 1u << 1; + static const uint8_t kHangulFlag = 1u << 2; + static const uint8_t kHiraganaFlag = 1u << 3; + static const uint8_t kKatakanaFlag = 1u << 4; + static const uint8_t kSimplifiedChineseFlag = 1u << 5; + static const uint8_t kTraditionalChineseFlag = 1u << 6; + uint8_t mSubScriptBits; + + static uint8_t scriptToSubScriptBits(uint32_t script); +}; + +typedef std::vector FontLanguages; + +} // namespace android + +#endif // MINIKIN_FONT_LANGUAGE_H diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp index e1c2343ddaa..2d64998e7a3 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp @@ -19,13 +19,92 @@ #include "FontLanguageListCache.h" #include +#include +#include #include "MinikinInternal.h" +#include "FontLanguage.h" namespace android { const uint32_t FontLanguageListCache::kEmptyListId; +// Returns the text length of output. +static size_t toLanguageTag(char* output, size_t outSize, const std::string& locale) { + output[0] = '\0'; + if (locale.empty()) { + return 0; + } + + size_t outLength = 0; + UErrorCode uErr = U_ZERO_ERROR; + outLength = uloc_canonicalize(locale.c_str(), output, outSize, &uErr); + if (U_FAILURE(uErr)) { + // unable to build a proper language identifier + ALOGD("uloc_canonicalize(\"%s\") failed: %s", locale.c_str(), u_errorName(uErr)); + output[0] = '\0'; + return 0; + } + + // Preserve "und" and "und-****" since uloc_addLikelySubtags changes "und" to "en-Latn-US". + if (strncmp(output, "und", 3) == 0 && + (outLength == 3 || (outLength == 8 && output[3] == '_'))) { + return outLength; + } + + char likelyChars[ULOC_FULLNAME_CAPACITY]; + uErr = U_ZERO_ERROR; + uloc_addLikelySubtags(output, likelyChars, ULOC_FULLNAME_CAPACITY, &uErr); + if (U_FAILURE(uErr)) { + // unable to build a proper language identifier + ALOGD("uloc_addLikelySubtags(\"%s\") failed: %s", output, u_errorName(uErr)); + output[0] = '\0'; + return 0; + } + + uErr = U_ZERO_ERROR; + outLength = uloc_toLanguageTag(likelyChars, output, outSize, FALSE, &uErr); + if (U_FAILURE(uErr)) { + // unable to build a proper language identifier + ALOGD("uloc_toLanguageTag(\"%s\") failed: %s", likelyChars, u_errorName(uErr)); + output[0] = '\0'; + return 0; + } +#ifdef VERBOSE_DEBUG + ALOGD("ICU normalized '%s' to '%s'", locale.c_str(), output); +#endif + return outLength; +} + +static FontLanguages constructFontLanguages(const std::string& input) { + FontLanguages result; + size_t currentIdx = 0; + size_t commaLoc = 0; + char langTag[ULOC_FULLNAME_CAPACITY]; + std::unordered_set seen; + std::string locale(input.size(), 0); + + while ((commaLoc = input.find_first_of(',', currentIdx)) != std::string::npos) { + locale.assign(input, currentIdx, commaLoc - currentIdx); + currentIdx = commaLoc + 1; + size_t length = toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, locale); + FontLanguage lang(langTag, length); + uint64_t identifier = lang.getIdentifier(); + if (!lang.isUnsupported() && seen.count(identifier) == 0) { + result.push_back(lang); + seen.insert(identifier); + } + } + locale.assign(input, currentIdx, input.size() - currentIdx); + size_t length = toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, locale); + FontLanguage lang(langTag, length); + uint64_t identifier = lang.getIdentifier(); + if (!lang.isUnsupported() && seen.count(identifier) == 0) { + result.push_back(lang); + } + return result; +} + // static uint32_t FontLanguageListCache::getId(const std::string& languages) { FontLanguageListCache* inst = FontLanguageListCache::getInstance(); @@ -37,7 +116,11 @@ uint32_t FontLanguageListCache::getId(const std::string& languages) { // Given language list is not in cache. Insert it and return newly assigned ID. const uint32_t nextId = inst->mLanguageLists.size(); - inst->mLanguageLists.push_back(FontLanguages(languages.c_str(), languages.size())); + FontLanguages fontLanguages = constructFontLanguages(languages); + if (fontLanguages.empty()) { + return kEmptyListId; + } + inst->mLanguageLists.push_back(fontLanguages); inst->mLanguageListLookupTable.insert(std::make_pair(languages, nextId)); return nextId; } @@ -56,8 +139,9 @@ FontLanguageListCache* FontLanguageListCache::getInstance() { if (instance == nullptr) { instance = new FontLanguageListCache(); - // Insert an empty language list for mapping empty language list to kEmptyListId. - instance->mLanguageLists.push_back(FontLanguages()); + // Insert an empty language list for mapping default language list to kEmptyListId. + // The default language list has only one FontLanguage and it is the unsupported language. + instance->mLanguageLists.push_back(FontLanguages({FontLanguage()})); instance->mLanguageListLookupTable.insert(std::make_pair("", kEmptyListId)); } return instance; diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.h b/engine/src/flutter/libs/minikin/FontLanguageListCache.h index 7d627b562e3..c961882f0a8 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.h +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.h @@ -20,6 +20,7 @@ #include #include +#include "FontLanguage.h" namespace android { diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index af5e6fe75a7..2e206a20fc3 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -34,6 +34,7 @@ #include #include +#include "FontLanguage.h" #include "FontLanguageListCache.h" #include "LayoutUtils.h" #include "HbFaceCache.h" @@ -746,9 +747,15 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t const FontLanguages& langList = FontLanguageListCache::getById(ctx->style.getLanguageListId()); if (langList.size() != 0) { - // TODO: use all languages in langList. - string lang = langList[0].getString(); - hb_buffer_set_language(buffer, hb_language_from_string(lang.c_str(), -1)); + const FontLanguage* hbLanguage = &langList[0]; + for (size_t i = 0; i < langList.size(); ++i) { + if (langList[i].supportsHbScript(script)) { + hbLanguage = &langList[i]; + break; + } + } + hb_buffer_set_language(buffer, + hb_language_from_string(hbLanguage->getString().c_str(), -1)); } hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart); if (ctx->paint.hyphenEdit.hasHyphen() && srunend > srunstart) { diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index 85d76afccb8..cf9b704efa2 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -16,7 +16,9 @@ #include +#include "FontLanguage.h" #include "FontTestUtils.h" +#include "ICUTestBase.h" #include "MinikinFontForTest.h" #include "UnicodeUtils.h" @@ -42,6 +44,8 @@ const char kColorEmojiFont[] = kTestFontDir "ColorEmojiFont.ttf"; const char kTextEmojiFont[] = kTestFontDir "TextEmojiFont.ttf"; const char kMixedEmojiFont[] = kTestFontDir "ColorTextMixedEmojiFont.ttf"; +typedef ICUTestBase FontCollectionItemizeTest; + // Utility function for calling itemize function. void itemize(FontCollection* collection, const char* str, FontStyle style, std::vector* result) { @@ -60,7 +64,7 @@ const std::string& getFontPath(const FontCollection::Run& run) { return ((MinikinFontForTest*)run.fakedFont.font)->fontPath(); } -TEST(FontCollectionItemizeTest, itemize_latin) { +TEST_F(FontCollectionItemizeTest, itemize_latin) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -130,7 +134,7 @@ TEST(FontCollectionItemizeTest, itemize_latin) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); } -TEST(FontCollectionItemizeTest, itemize_emoji) { +TEST_F(FontCollectionItemizeTest, itemize_emoji) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -191,7 +195,7 @@ TEST(FontCollectionItemizeTest, itemize_emoji) { EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeItalic()); } -TEST(FontCollectionItemizeTest, itemize_non_latin) { +TEST_F(FontCollectionItemizeTest, itemize_non_latin) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -280,7 +284,7 @@ TEST(FontCollectionItemizeTest, itemize_non_latin) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); } -TEST(FontCollectionItemizeTest, itemize_mixed) { +TEST_F(FontCollectionItemizeTest, itemize_mixed) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -319,7 +323,7 @@ TEST(FontCollectionItemizeTest, itemize_mixed) { EXPECT_FALSE(runs[4].fakedFont.fakery.isFakeItalic()); } -TEST(FontCollectionItemizeTest, itemize_variationSelector) { +TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -458,7 +462,7 @@ TEST(FontCollectionItemizeTest, itemize_variationSelector) { EXPECT_EQ(kLatinFont, getFontPath(runs[0])); } -TEST(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { +TEST_F(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -583,7 +587,7 @@ TEST(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); } -TEST(FontCollectionItemizeTest, itemize_no_crash) { +TEST_F(FontCollectionItemizeTest, itemize_no_crash) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -607,7 +611,7 @@ TEST(FontCollectionItemizeTest, itemize_no_crash) { itemize(collection.get(), "U+FE00 U+302D U+E0100", FontStyle(), &runs); } -TEST(FontCollectionItemizeTest, itemize_fakery) { +TEST_F(FontCollectionItemizeTest, itemize_fakery) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -647,18 +651,18 @@ TEST(FontCollectionItemizeTest, itemize_fakery) { EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeItalic()); } -TEST(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { +TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { // kVSTestFont supports U+717D U+FE02 but doesn't support U+717D. // kVSTestFont should be selected for U+717D U+FE02 even if it does not support the base code // point. const std::string kVSTestFont = kTestFontDir "VarioationSelectorTest-Regular.ttf"; std::vector families; - FontFamily* family1 = new FontFamily(FontLanguage(), android::VARIANT_DEFAULT); + FontFamily* family1 = new FontFamily(android::VARIANT_DEFAULT); family1->addFont(new MinikinFontForTest(kLatinFont)); families.push_back(family1); - FontFamily* family2 = new FontFamily(FontLanguage(), android::VARIANT_DEFAULT); + FontFamily* family2 = new FontFamily(android::VARIANT_DEFAULT); family2->addFont(new MinikinFontForTest(kVSTestFont)); families.push_back(family2); @@ -676,7 +680,7 @@ TEST(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { family2->Unref(); } -TEST(FontCollectionItemizeTest, itemize_emojiSelection) { +TEST_F(FontCollectionItemizeTest, itemize_emojiSelection) { std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); std::vector runs; @@ -748,7 +752,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection) { EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); } -TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { +TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); std::vector runs; @@ -830,7 +834,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { EXPECT_EQ(kMixedEmojiFont, getFontPath(runs[0])); } -TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { +TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); std::vector runs; diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index fc44e6c6369..ac7616fada3 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -17,74 +17,261 @@ #include #include + +#include + #include "FontLanguageListCache.h" +#include "ICUTestBase.h" #include "MinikinFontForTest.h" #include "MinikinInternal.h" namespace android { -TEST(FontLanguagesTest, basicTests) { +typedef ICUTestBase FontLanguagesTest; +typedef ICUTestBase FontLanguageTest; + +static FontLanguages createFontLanguages(const std::string& input) { + uint32_t langId = FontLanguageListCache::getId(input); + return FontLanguageListCache::getById(langId); +} + +static FontLanguage createFontLanguage(const std::string& input) { + uint32_t langId = FontLanguageListCache::getId(input); + return FontLanguageListCache::getById(langId)[0]; +} + +TEST_F(FontLanguageTest, basicTests) { + FontLanguage defaultLang; + FontLanguage emptyLang("", 0); + FontLanguage english = createFontLanguage("en"); + FontLanguage french = createFontLanguage("fr"); + FontLanguage und = createFontLanguage("und"); + FontLanguage undQaae = createFontLanguage("und-Qaae"); + + EXPECT_EQ(english, english); + EXPECT_EQ(french, french); + + EXPECT_TRUE(defaultLang != defaultLang); + EXPECT_TRUE(emptyLang != emptyLang); + EXPECT_TRUE(defaultLang != emptyLang); + EXPECT_TRUE(defaultLang != und); + EXPECT_TRUE(emptyLang != und); + EXPECT_TRUE(english != defaultLang); + EXPECT_TRUE(english != emptyLang); + EXPECT_TRUE(english != french); + EXPECT_TRUE(english != undQaae); + EXPECT_TRUE(und != undQaae); + EXPECT_TRUE(english != und); + + EXPECT_TRUE(defaultLang.isUnsupported()); + EXPECT_TRUE(emptyLang.isUnsupported()); + + EXPECT_FALSE(english.isUnsupported()); + EXPECT_FALSE(french.isUnsupported()); + EXPECT_FALSE(und.isUnsupported()); + EXPECT_FALSE(undQaae.isUnsupported()); +} + +TEST_F(FontLanguageTest, getStringTest) { + EXPECT_EQ("en-Latn", createFontLanguage("en").getString()); + EXPECT_EQ("en-Latn", createFontLanguage("en-Latn").getString()); + + // Capitalized language code or lowercased script should be normalized. + EXPECT_EQ("en-Latn", createFontLanguage("EN-LATN").getString()); + EXPECT_EQ("en-Latn", createFontLanguage("EN-latn").getString()); + EXPECT_EQ("en-Latn", createFontLanguage("en-latn").getString()); + + // Invalid script should be kept. + EXPECT_EQ("en-Xyzt", createFontLanguage("en-xyzt").getString()); + + EXPECT_EQ("en-Latn", createFontLanguage("en-Latn-US").getString()); + EXPECT_EQ("ja-Jpan", createFontLanguage("ja").getString()); + EXPECT_EQ("und", createFontLanguage("und").getString()); + EXPECT_EQ("und", createFontLanguage("UND").getString()); + EXPECT_EQ("und", createFontLanguage("Und").getString()); + EXPECT_EQ("und-Qaae", createFontLanguage("und-Qaae").getString()); + EXPECT_EQ("und-Qaae", createFontLanguage("Und-QAAE").getString()); + EXPECT_EQ("und-Qaae", createFontLanguage("Und-qaae").getString()); + + EXPECT_EQ("de-Latn", createFontLanguage("de-1901").getString()); + + // This is not a necessary desired behavior, just known behavior. + EXPECT_EQ("en-Latn", createFontLanguage("und-Abcdefgh").getString()); +} + +TEST_F(FontLanguageTest, ScriptEqualTest) { + EXPECT_TRUE(createFontLanguage("en").isEqualScript(createFontLanguage("en"))); + EXPECT_TRUE(createFontLanguage("en-Latn").isEqualScript(createFontLanguage("en"))); + EXPECT_TRUE(createFontLanguage("jp-Latn").isEqualScript(createFontLanguage("en-Latn"))); + EXPECT_TRUE(createFontLanguage("en-Jpan").isEqualScript(createFontLanguage("en-Jpan"))); + + EXPECT_FALSE(createFontLanguage("en-Jpan").isEqualScript(createFontLanguage("en-Hira"))); + EXPECT_FALSE(createFontLanguage("en-Jpan").isEqualScript(createFontLanguage("en-Hani"))); +} + +TEST_F(FontLanguageTest, ScriptMatchTest) { + const bool SUPPORTED = true; + const bool NOT_SUPPORTED = false; + + struct TestCase { + const std::string baseScript; + const std::string requestedScript; + bool isSupported; + } testCases[] = { + // Same scripts + { "en-Latn", "Latn", SUPPORTED }, + { "ja-Jpan", "Jpan", SUPPORTED }, + { "ja-Hira", "Hira", SUPPORTED }, + { "ja-Kana", "Kana", SUPPORTED }, + { "ja-Hrkt", "Hrkt", SUPPORTED }, + { "zh-Hans", "Hans", SUPPORTED }, + { "zh-Hant", "Hant", SUPPORTED }, + { "zh-Hani", "Hani", SUPPORTED }, + { "ko-Kore", "Kore", SUPPORTED }, + { "ko-Hang", "Hang", SUPPORTED }, + + // Japanese supports Hiragana, Katakanara, etc. + { "ja-Jpan", "Hira", SUPPORTED }, + { "ja-Jpan", "Kana", SUPPORTED }, + { "ja-Jpan", "Hrkt", SUPPORTED }, + { "ja-Hrkt", "Hira", SUPPORTED }, + { "ja-Hrkt", "Kana", SUPPORTED }, + + // Chinese supports Han. + { "zh-Hans", "Hani", SUPPORTED }, + { "zh-Hant", "Hani", SUPPORTED }, + + // Korean supports Hangul. + { "ko-Kore", "Hang", SUPPORTED }, + + // Different scripts + { "ja-Jpan", "Latn", NOT_SUPPORTED }, + { "en-Latn", "Jpan", NOT_SUPPORTED }, + { "ja-Jpan", "Hant", NOT_SUPPORTED }, + { "zh-Hant", "Jpan", NOT_SUPPORTED }, + { "ja-Jpan", "Hans", NOT_SUPPORTED }, + { "zh-Hans", "Jpan", NOT_SUPPORTED }, + { "ja-Jpan", "Kore", NOT_SUPPORTED }, + { "ko-Kore", "Jpan", NOT_SUPPORTED }, + { "zh-Hans", "Hant", NOT_SUPPORTED }, + { "zh-Hant", "Hans", NOT_SUPPORTED }, + { "zh-Hans", "Kore", NOT_SUPPORTED }, + { "ko-Kore", "Hans", NOT_SUPPORTED }, + { "zh-Hant", "Kore", NOT_SUPPORTED }, + { "ko-Kore", "Hant", NOT_SUPPORTED }, + + // Hiragana doesn't support Japanese, etc. + { "ja-Hira", "Jpan", NOT_SUPPORTED }, + { "ja-Kana", "Jpan", NOT_SUPPORTED }, + { "ja-Hrkt", "Jpan", NOT_SUPPORTED }, + { "ja-Hani", "Jpan", NOT_SUPPORTED }, + { "ja-Hira", "Hrkt", NOT_SUPPORTED }, + { "ja-Kana", "Hrkt", NOT_SUPPORTED }, + { "ja-Hani", "Hrkt", NOT_SUPPORTED }, + { "ja-Hani", "Hira", NOT_SUPPORTED }, + { "ja-Hani", "Kana", NOT_SUPPORTED }, + + // Kanji doesn't support Chinese, etc. + { "zh-Hani", "Hant", NOT_SUPPORTED }, + { "zh-Hani", "Hans", NOT_SUPPORTED }, + + // Hangul doesn't support Korean, etc. + { "ko-Hang", "Kore", NOT_SUPPORTED }, + { "ko-Hani", "Kore", NOT_SUPPORTED }, + { "ko-Hani", "Hang", NOT_SUPPORTED }, + { "ko-Hang", "Hani", NOT_SUPPORTED }, + }; + + for (auto testCase : testCases) { + hb_script_t script = hb_script_from_iso15924_tag( + HB_TAG(testCase.requestedScript[0], testCase.requestedScript[1], + testCase.requestedScript[2], testCase.requestedScript[3])); + if (testCase.isSupported) { + EXPECT_TRUE( + createFontLanguage(testCase.baseScript).supportsHbScript(script)) + << testCase.baseScript << " should support " << testCase.requestedScript; + } else { + EXPECT_FALSE( + createFontLanguage(testCase.baseScript).supportsHbScript(script)) + << testCase.baseScript << " shouldn't support " << testCase.requestedScript; + } + } +} + +TEST_F(FontLanguagesTest, basicTests) { FontLanguages emptyLangs; EXPECT_EQ(0u, emptyLangs.size()); - FontLanguage english("en", 2); - FontLanguages singletonLangs("en", 2); + FontLanguage english = createFontLanguage("en"); + FontLanguages singletonLangs = createFontLanguages("en"); EXPECT_EQ(1u, singletonLangs.size()); EXPECT_EQ(english, singletonLangs[0]); - FontLanguage french("fr", 2); - FontLanguages twoLangs("en,fr", 5); + FontLanguage french = createFontLanguage("fr"); + FontLanguages twoLangs = createFontLanguages("en,fr"); EXPECT_EQ(2u, twoLangs.size()); EXPECT_EQ(english, twoLangs[0]); EXPECT_EQ(french, twoLangs[1]); } -TEST(FontLanguagesTest, unsupportedLanguageTests) { - FontLanguage unsupportedLang("x-example", 9); +TEST_F(FontLanguagesTest, unsupportedLanguageTests) { + FontLanguage unsupportedLang = createFontLanguage("abcd"); ASSERT_TRUE(unsupportedLang.isUnsupported()); - FontLanguages oneUnsupported("x-example", 9); + FontLanguages oneUnsupported = createFontLanguages("abcd-example"); EXPECT_EQ(1u, oneUnsupported.size()); EXPECT_TRUE(oneUnsupported[0].isUnsupported()); - FontLanguages twoUnsupporteds("x-example,x-example", 19); + FontLanguages twoUnsupporteds = createFontLanguages("abcd-example,abcd-example"); EXPECT_EQ(1u, twoUnsupporteds.size()); EXPECT_TRUE(twoUnsupporteds[0].isUnsupported()); - FontLanguage english("en", 2); - FontLanguages firstUnsupported("x-example,en", 12); + FontLanguage english = createFontLanguage("en"); + FontLanguages firstUnsupported = createFontLanguages("abcd-example,en"); EXPECT_EQ(1u, firstUnsupported.size()); EXPECT_EQ(english, firstUnsupported[0]); - FontLanguages lastUnsupported("en,x-example", 12); + FontLanguages lastUnsupported = createFontLanguages("en,abcd-example"); EXPECT_EQ(1u, lastUnsupported.size()); EXPECT_EQ(english, lastUnsupported[0]); } -TEST(FontLanguagesTest, repeatedLanguageTests) { - FontLanguage english("en", 2); - FontLanguage englishInLatn("en-Latn", 2); +TEST_F(FontLanguagesTest, repeatedLanguageTests) { + FontLanguage english = createFontLanguage("en"); + FontLanguage french = createFontLanguage("fr"); + FontLanguage englishInLatn = createFontLanguage("en-Latn"); ASSERT_TRUE(english == englishInLatn); - FontLanguages langs("en,en-Latn", 10); + FontLanguages langs = createFontLanguages("en,en-Latn"); EXPECT_EQ(1u, langs.size()); EXPECT_EQ(english, langs[0]); + + // Country codes are ignored. + FontLanguages fr = createFontLanguages("fr,fr-CA,fr-FR"); + EXPECT_EQ(1u, fr.size()); + EXPECT_EQ(french, fr[0]); + + // The order should be kept. + langs = createFontLanguages("en,fr,en-Latn"); + EXPECT_EQ(2u, langs.size()); + EXPECT_EQ(english, langs[0]); + EXPECT_EQ(french, langs[1]); } -TEST(FontLanguagesTest, undEmojiTests) { - FontLanguage emoji("und-Qaae", 8); +TEST_F(FontLanguagesTest, undEmojiTests) { + FontLanguage emoji = createFontLanguage("und-Qaae"); EXPECT_TRUE(emoji.hasEmojiFlag()); - FontLanguage und("und", 3); + FontLanguage und = createFontLanguage("und"); EXPECT_FALSE(und.hasEmojiFlag()); EXPECT_FALSE(emoji == und); - FontLanguage undExample("und-example", 10); + FontLanguage undExample = createFontLanguage("und-example"); EXPECT_FALSE(undExample.hasEmojiFlag()); EXPECT_FALSE(emoji == undExample); } -TEST(FontLanguagesTest, registerLanguageListTest) { +TEST_F(FontLanguagesTest, registerLanguageListTest) { EXPECT_EQ(0UL, FontStyle::registerLanguageList("")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en")); EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); @@ -122,9 +309,10 @@ TEST(FontLanguagesTest, registerLanguageListTest) { // U+717D U+E0103 (VS20) const char kVsTestFont[] = kTestFontDir "VarioationSelectorTest-Regular.ttf"; -class FontFamilyTest : public testing::Test { +class FontFamilyTest : public ICUTestBase { public: virtual void SetUp() override { + ICUTestBase::SetUp(); if (access(kVsTestFont, R_OK) != 0) { FAIL() << "Unable to read " << kVsTestFont << ". " << "Please prepare the test data directory. " diff --git a/engine/src/flutter/tests/FontLanguageListCacheTest.cpp b/engine/src/flutter/tests/FontLanguageListCacheTest.cpp index 29757fedceb..f83988c1f50 100644 --- a/engine/src/flutter/tests/FontLanguageListCacheTest.cpp +++ b/engine/src/flutter/tests/FontLanguageListCacheTest.cpp @@ -17,11 +17,15 @@ #include #include + #include "FontLanguageListCache.h" +#include "ICUTestBase.h" namespace android { -TEST(FontLanguageListCacheTest, getId) { +typedef ICUTestBase FontLanguageListCacheTest; + +TEST_F(FontLanguageListCacheTest, getId) { EXPECT_EQ(0UL, FontLanguageListCache::getId("")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en")); EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); @@ -42,11 +46,15 @@ TEST(FontLanguageListCacheTest, getId) { FontLanguageListCache::getId("en,zh-Hant")); } -TEST(FontLanguageListCacheTest, getById) { - FontLanguage english("en", 2); - FontLanguage japanese("jp", 2); +TEST_F(FontLanguageListCacheTest, getById) { + uint32_t enLangId = FontLanguageListCache::getId("en"); + uint32_t jpLangId = FontLanguageListCache::getId("jp"); + FontLanguage english = FontLanguageListCache::getById(enLangId)[0]; + FontLanguage japanese = FontLanguageListCache::getById(jpLangId)[0]; - EXPECT_EQ(0UL, FontLanguageListCache::getById(0).size()); + FontLanguages defLangs = FontLanguageListCache::getById(0); + EXPECT_EQ(1UL, defLangs.size()); + EXPECT_TRUE(defLangs[0].isUnsupported()); FontLanguages langs = FontLanguageListCache::getById(FontLanguageListCache::getId("en")); ASSERT_EQ(1UL, langs.size()); diff --git a/engine/src/flutter/tests/FontTestUtils.cpp b/engine/src/flutter/tests/FontTestUtils.cpp index 8e1d184adcc..98dab5121b0 100644 --- a/engine/src/flutter/tests/FontTestUtils.cpp +++ b/engine/src/flutter/tests/FontTestUtils.cpp @@ -20,6 +20,8 @@ #include #include + +#include "FontLanguage.h" #include "MinikinFontForTest.h" std::unique_ptr getFontCollection( @@ -44,9 +46,10 @@ std::unique_ptr getFontCollection( } xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); + uint32_t langId = android::FontStyle::registerLanguageList( + std::string((const char*)lang, xmlStrlen(lang))); - android::FontFamily* family = new android::FontFamily( - android::FontLanguage((const char*)lang, xmlStrlen(lang)), variant); + android::FontFamily* family = new android::FontFamily(langId, variant); for (xmlNode* fontNode = familyNode->children; fontNode; fontNode = fontNode->next) { if (xmlStrcmp(fontNode->name, (const xmlChar*)"font") != 0) { diff --git a/engine/src/flutter/tests/ICUTestBase.h b/engine/src/flutter/tests/ICUTestBase.h new file mode 100644 index 00000000000..3bcfaf36945 --- /dev/null +++ b/engine/src/flutter/tests/ICUTestBase.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2015 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_TEST_ICU_TEST_BASE_H +#define MINIKIN_TEST_ICU_TEST_BASE_H + +#include +#include +#include + +// low level file access for mapping ICU data +#include +#include +#include + +class ICUTestBase : public testing::Test { +protected: + virtual void SetUp() override { + const char* fn = "/system/usr/icu/" U_ICUDATA_NAME ".dat"; + int fd = open(fn, O_RDONLY); + ASSERT_NE(-1, fd); + struct stat sb; + ASSERT_EQ(0, fstat(fd, &sb)); + void* data = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0); + + UErrorCode errorCode = U_ZERO_ERROR; + udata_setCommonData(data, &errorCode); + ASSERT_TRUE(U_SUCCESS(errorCode)); + u_init(&errorCode); + ASSERT_TRUE(U_SUCCESS(errorCode)); + } + + virtual void TearDown() override { + u_cleanup(); + } +}; + + +#endif // MINIKIN_TEST_ICU_TEST_BASE_H From 40c8b088bdcb459b6eae9359aeca10b30e9bec58 Mon Sep 17 00:00:00 2001 From: Bart Sears Date: Tue, 22 Dec 2015 09:06:03 +0000 Subject: [PATCH 134/364] Revert "Save all kind of script tags into FontLanguage." This reverts commit bb5c10092c3ec3246a9f4c52cd6b620e86fa5bd8. Change-Id: I761e0e41906742fbe3d3ac34170af3101e18042a --- .../src/flutter/include/minikin/FontFamily.h | 64 ++++- engine/src/flutter/libs/minikin/Android.mk | 1 - .../flutter/libs/minikin/FontCollection.cpp | 10 +- .../src/flutter/libs/minikin/FontFamily.cpp | 120 ++++++++- .../src/flutter/libs/minikin/FontLanguage.cpp | 135 ---------- .../src/flutter/libs/minikin/FontLanguage.h | 89 ------- .../libs/minikin/FontLanguageListCache.cpp | 90 +------ .../libs/minikin/FontLanguageListCache.h | 1 - engine/src/flutter/libs/minikin/Layout.cpp | 13 +- .../tests/FontCollectionItemizeTest.cpp | 32 ++- engine/src/flutter/tests/FontFamilyTest.cpp | 232 ++---------------- .../tests/FontLanguageListCacheTest.cpp | 18 +- engine/src/flutter/tests/FontTestUtils.cpp | 7 +- engine/src/flutter/tests/ICUTestBase.h | 52 ---- 14 files changed, 225 insertions(+), 639 deletions(-) delete mode 100644 engine/src/flutter/libs/minikin/FontLanguage.cpp delete mode 100644 engine/src/flutter/libs/minikin/FontLanguage.h delete mode 100644 engine/src/flutter/tests/ICUTestBase.h diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index aa2e0ac2e4a..00130e6f5d0 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -30,6 +30,62 @@ namespace android { class MinikinFont; +// FontLanguage is a compact representation of a bcp-47 language tag. It +// does not capture all possible information, only what directly affects +// font rendering. +class FontLanguage { + friend class FontStyle; + friend class FontLanguages; +public: + FontLanguage() : mBits(0) { } + + // Parse from string + FontLanguage(const char* buf, size_t size); + + bool operator==(const FontLanguage other) const { + return mBits != kUnsupportedLanguage && mBits == other.mBits; + } + operator bool() const { return mBits != 0; } + + bool isUnsupported() const { return mBits == kUnsupportedLanguage; } + bool hasEmojiFlag() const { return isUnsupported() ? false : (mBits & kEmojiFlag); } + + std::string getString() const; + + // 0 = no match, 1 = language matches + int match(const FontLanguage other) const; + +private: + explicit FontLanguage(uint32_t bits) : mBits(bits) { } + + uint32_t bits() const { return mBits; } + + static const uint32_t kUnsupportedLanguage = 0xFFFFFFFFu; + static const uint32_t kBaseLangMask = 0xFFFFFFu; + static const uint32_t kHansFlag = 1u << 24; + static const uint32_t kHantFlag = 1u << 25; + static const uint32_t kEmojiFlag = 1u << 26; + static const uint32_t kScriptMask = kHansFlag | kHantFlag | kEmojiFlag; + uint32_t mBits; +}; + +// A list of zero or more instances of FontLanguage, in the order of +// preference. Used for further resolution of rendering results. +class FontLanguages { +public: + FontLanguages() { mLangs.clear(); } + + // Parse from string, which is a comma-separated list of languages + FontLanguages(const char* buf, size_t size); + + const FontLanguage& operator[](size_t index) const { return mLangs.at(index); } + + size_t size() const { return mLangs.size(); } + +private: + std::vector mLangs; +}; + // FontStyle represents all style information needed to select an actual font // from a collection. The implementation is packed into two 32-bit words // so it can be efficiently copied, embedded in other objects, etc. @@ -102,9 +158,7 @@ class FontFamily : public MinikinRefCounted { public: FontFamily() : mHbFont(nullptr) { } - FontFamily(int variant); - - FontFamily(uint32_t langId, int variant) : mLangId(langId), mVariant(variant), mHbFont(nullptr) { + FontFamily(FontLanguage lang, int variant) : mLang(lang), mVariant(variant), mHbFont(nullptr) { } ~FontFamily(); @@ -115,7 +169,7 @@ public: void addFont(MinikinFont* typeface, FontStyle style); FakedFont getClosestMatch(FontStyle style) const; - uint32_t langId() const { return mLangId; } + FontLanguage lang() const { return mLang; } int variant() const { return mVariant; } // API's for enumerating the fonts in a family. These don't guarantee any particular order @@ -146,7 +200,7 @@ private: MinikinFont* typeface; FontStyle style; }; - uint32_t mLangId; + FontLanguage mLang; int mVariant; std::vector mFonts; diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 42fdca39193..4c945a60c9c 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -21,7 +21,6 @@ minikin_src_files := \ CmapCoverage.cpp \ FontCollection.cpp \ FontFamily.cpp \ - FontLanguage.cpp \ FontLanguageListCache.cpp \ GraphemeBreak.cpp \ HbFaceCache.cpp \ diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 62c70310c06..bba2ef95359 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -22,7 +22,6 @@ #include "unicode/unistr.h" #include "unicode/unorm2.h" -#include "FontLanguage.h" #include "FontLanguageListCache.h" #include "MinikinInternal.h" #include @@ -151,17 +150,14 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, // always use it. return family; } - - // TODO use all language in the list. - FontLanguage fontLang = FontLanguageListCache::getById(family->langId())[0]; - int score = lang.match(fontLang) * 2; + int score = lang.match(family->lang()) * 2; if (family->variant() == 0 || family->variant() == variant) { score++; } if (hasVSGlyph) { score += 8; - } else if (((vs == 0xFE0F) && fontLang.hasEmojiFlag()) || - ((vs == 0xFE0E) && !fontLang.hasEmojiFlag())) { + } else if (((vs == 0xFE0F) && family->lang().hasEmojiFlag()) || + ((vs == 0xFE0E) && !family->lang().hasEmojiFlag())) { score += 4; } if (score > bestScore) { diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 14057890281..76398312406 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -16,6 +16,8 @@ #define LOG_TAG "Minikin" +#include + #include #include #include @@ -26,7 +28,6 @@ #include -#include "FontLanguage.h" #include "FontLanguageListCache.h" #include "HbFaceCache.h" #include "MinikinInternal.h" @@ -40,6 +41,117 @@ using std::vector; namespace android { +// Parse bcp-47 language identifier into internal structure +FontLanguage::FontLanguage(const char* buf, size_t size) { + uint32_t bits = 0; + size_t i; + for (i = 0; i < size; i++) { + uint16_t c = buf[i]; + if (c == '-' || c == '_') break; + } + if (i == 2) { + bits = uint8_t(buf[0]) | (uint8_t(buf[1]) << 8); + } else if (i == 3) { + bits = uint8_t(buf[0]) | (uint8_t(buf[1]) << 8) | (uint8_t(buf[2]) << 16); + } else { + mBits = kUnsupportedLanguage; + // We don't understand anything other than two-letter or three-letter + // language codes, so we skip parsing the rest of the string. + return; + } + size_t next; + for (i++; i < size; i = next + 1) { + for (next = i; next < size; next++) { + uint16_t c = buf[next]; + if (c == '-' || c == '_') break; + } + if (next - i == 4) { + if (buf[i] == 'H' && buf[i+1] == 'a' && buf[i+2] == 'n') { + if (buf[i+3] == 's') { + bits |= kHansFlag; + } else if (buf[i+3] == 't') { + bits |= kHantFlag; + } + } else if (buf[i] == 'Q' && buf[i+1] == 'a' && buf[i+2] == 'a'&& buf[i+3] == 'e') { + bits |= kEmojiFlag; + } + } + // TODO: this might be a good place to infer script from country (zh_TW -> Hant), + // but perhaps it's up to the client to do that, before passing a string. + } + mBits = bits; +} + +std::string FontLanguage::getString() const { + if (mBits == kUnsupportedLanguage) { + return "und"; + } + char buf[16]; + size_t i = 0; + if (mBits & kBaseLangMask) { + buf[i++] = mBits & 0xFFu; + buf[i++] = (mBits >> 8) & 0xFFu; + char third_letter = (mBits >> 16) & 0xFFu; + if (third_letter != 0) buf[i++] = third_letter; + } + if (mBits & kScriptMask) { + if (!i) { + // This should not happen, but as it apparently has, we fill the language code part + // with "und". + buf[i++] = 'u'; + buf[i++] = 'n'; + buf[i++] = 'd'; + } + buf[i++] = '-'; + if (mBits & kEmojiFlag) { + buf[i++] = 'Q'; + buf[i++] = 'a'; + buf[i++] = 'a'; + buf[i++] = 'e'; + } else { + buf[i++] = 'H'; + buf[i++] = 'a'; + buf[i++] = 'n'; + buf[i++] = (mBits & kHansFlag) ? 's' : 't'; + } + } + return std::string(buf, i); +} + +int FontLanguage::match(const FontLanguage other) const { + return *this == other; +} + +FontLanguages::FontLanguages(const char* buf, size_t size) { + std::unordered_set seen; + mLangs.clear(); + const char* bufEnd = buf + size; + const char* lastStart = buf; + bool isLastLang = false; + while (true) { + const char* commaLoc = static_cast( + memchr(lastStart, ',', bufEnd - lastStart)); + if (commaLoc == NULL) { + commaLoc = bufEnd; + isLastLang = true; + } + FontLanguage lang(lastStart, commaLoc - lastStart); + if (isLastLang && mLangs.size() == 0) { + // Make sure the list has at least one member + mLangs.push_back(lang); + return; + } + uint32_t bits = lang.bits(); + if (bits != FontLanguage::kUnsupportedLanguage && seen.count(bits) == 0) { + mLangs.push_back(lang); + if (isLastLang) return; + seen.insert(bits); + } + if (isLastLang) return; + lastStart = commaLoc + 1; + } +} + FontStyle::FontStyle(int variant, int weight, bool italic) : FontStyle(FontLanguageListCache::kEmptyListId, variant, weight, italic) { } @@ -65,9 +177,6 @@ uint32_t FontStyle::pack(int variant, int weight, bool italic) { return (weight & kWeightMask) | (italic ? kItalicMask : 0) | (variant << kVariantShift); } -FontFamily::FontFamily(int variant) : FontFamily(FontLanguageListCache::kEmptyListId, variant) { -} - FontFamily::~FontFamily() { for (size_t i = 0; i < mFonts.size(); i++) { mFonts[i].typeface->UnrefLocked(); @@ -101,8 +210,7 @@ void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { addFontLocked(typeface, style); } -void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { - typeface->RefLocked(); +void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { typeface->RefLocked(); mFonts.push_back(Font(typeface, style)); mCoverageValid = false; } diff --git a/engine/src/flutter/libs/minikin/FontLanguage.cpp b/engine/src/flutter/libs/minikin/FontLanguage.cpp deleted file mode 100644 index 3c12e06c6f1..00000000000 --- a/engine/src/flutter/libs/minikin/FontLanguage.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2015 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. - */ - -#define LOG_TAG "Minikin" - -#include "FontLanguage.h" - -#include -#include - -namespace android { - -#define SCRIPT_TAG(c1, c2, c3, c4) \ - ((uint32_t)(c1)) << 24 | ((uint32_t)(c2)) << 16 | ((uint32_t)(c3)) << 8 | ((uint32_t)(c4)) - -// Parse BCP 47 language identifier into internal structure -FontLanguage::FontLanguage(const char* buf, size_t length) : FontLanguage() { - size_t i; - for (i = 0; i < length; i++) { - char c = buf[i]; - if (c == '-' || c == '_') break; - } - if (i == 2 || i == 3) { // only accept two or three letter language code. - mLanguage = buf[0] | (buf[1] << 8) | ((i == 3) ? (buf[2] << 16) : 0); - } else { - // We don't understand anything other than two-letter or three-letter - // language codes, so we skip parsing the rest of the string. - mLanguage = 0ul; - return; - } - - size_t next; - for (i++; i < length; i = next + 1) { - for (next = i; next < length; next++) { - char c = buf[next]; - if (c == '-' || c == '_') break; - } - if (next - i == 4 && 'A' <= buf[i] && buf[i] <= 'Z') { - mScript = SCRIPT_TAG(buf[i], buf[i + 1], buf[i + 2], buf[i + 3]); - } - } - - mSubScriptBits = scriptToSubScriptBits(mScript); -} - -//static -uint8_t FontLanguage::scriptToSubScriptBits(uint32_t script) { - uint8_t subScriptBits = 0u; - switch (script) { - case SCRIPT_TAG('H', 'a', 'n', 'g'): - subScriptBits = kHangulFlag; - break; - case SCRIPT_TAG('H', 'a', 'n', 'i'): - subScriptBits = kHanFlag; - break; - case SCRIPT_TAG('H', 'a', 'n', 's'): - subScriptBits = kHanFlag | kSimplifiedChineseFlag; - break; - case SCRIPT_TAG('H', 'a', 'n', 't'): - subScriptBits = kHanFlag | kTraditionalChineseFlag; - break; - case SCRIPT_TAG('H', 'i', 'r', 'a'): - subScriptBits = kHiraganaFlag; - break; - case SCRIPT_TAG('H', 'r', 'k', 't'): - subScriptBits = kKatakanaFlag | kHiraganaFlag; - break; - case SCRIPT_TAG('J', 'p', 'a', 'n'): - subScriptBits = kHanFlag | kKatakanaFlag | kHiraganaFlag; - break; - case SCRIPT_TAG('K', 'a', 'n', 'a'): - subScriptBits = kKatakanaFlag; - break; - case SCRIPT_TAG('K', 'o', 'r', 'e'): - subScriptBits = kHanFlag | kHangulFlag; - break; - case SCRIPT_TAG('Q', 'a', 'a', 'e'): - subScriptBits = kEmojiFlag; - break; - } - return subScriptBits; -} - -std::string FontLanguage::getString() const { - if (mLanguage == 0ul) { - return "und"; - } - char buf[16]; - size_t i = 0; - buf[i++] = mLanguage & 0xFF ; - buf[i++] = (mLanguage >> 8) & 0xFF; - char third_letter = (mLanguage >> 16) & 0xFF; - if (third_letter != 0) buf[i++] = third_letter; - if (mScript != 0) { - buf[i++] = '-'; - buf[i++] = (mScript >> 24) & 0xFFu; - buf[i++] = (mScript >> 16) & 0xFFu; - buf[i++] = (mScript >> 8) & 0xFFu; - buf[i++] = mScript & 0xFFu; - } - return std::string(buf, i); -} - -bool FontLanguage::isEqualScript(const FontLanguage other) const { - return other.mScript == mScript; -} - -bool FontLanguage::supportsHbScript(hb_script_t script) const { - static_assert(SCRIPT_TAG('J', 'p', 'a', 'n') == HB_TAG('J', 'p', 'a', 'n'), - "The Minikin script and HarfBuzz hb_script_t have different encodings."); - if (script == mScript) return true; - uint8_t requestedBits = scriptToSubScriptBits(script); - return requestedBits != 0 && (mSubScriptBits & requestedBits) == requestedBits; -} - -int FontLanguage::match(const FontLanguage other) const { - // TODO: Use script for matching. - return *this == other; -} - -#undef SCRIPT_TAG -} // namespace android diff --git a/engine/src/flutter/libs/minikin/FontLanguage.h b/engine/src/flutter/libs/minikin/FontLanguage.h deleted file mode 100644 index abe7d13179d..00000000000 --- a/engine/src/flutter/libs/minikin/FontLanguage.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2015 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_LANGUAGE_H -#define MINIKIN_FONT_LANGUAGE_H - -#include -#include - -#include - -namespace android { - -// FontLanguage is a compact representation of a BCP 47 language tag. It -// does not capture all possible information, only what directly affects -// font rendering. -struct FontLanguage { -public: - // Default constructor creates the unsupported language. - FontLanguage() : mScript(0ul), mLanguage(0ul), mSubScriptBits(0ul) {} - - // Parse from string - FontLanguage(const char* buf, size_t length); - - bool operator==(const FontLanguage other) const { - return !isUnsupported() && isEqualScript(other) && isEqualLanguage(other); - } - - bool operator!=(const FontLanguage other) const { - return !(*this == other); - } - - bool isUnsupported() const { return mLanguage == 0ul; } - bool hasEmojiFlag() const { return mSubScriptBits & kEmojiFlag; } - - bool isEqualLanguage(const FontLanguage other) const { return mLanguage == other.mLanguage; } - bool isEqualScript(const FontLanguage other) const; - - // Returns true if this script supports the given script. For example, ja-Jpan supports Hira, - // ja-Hira doesn't support Jpan. - bool supportsHbScript(hb_script_t script) const; - - std::string getString() const; - - // 0 = no match, 1 = language matches - int match(const FontLanguage other) const; - - uint64_t getIdentifier() const { return (uint64_t)mScript << 32 | (uint64_t)mLanguage; } - -private: - // ISO 15924 compliant script code. The 4 chars script code are packed into a 32 bit integer. - uint32_t mScript; - - // ISO 639-1 or ISO 639-2 compliant language code. - // The two or three letter language code is packed into 32 bit integer. - // mLanguage = 0 means the FontLanguage is unsupported. - uint32_t mLanguage; - - // For faster comparing, use 7 bits for specific scripts. - static const uint8_t kEmojiFlag = 1u; - static const uint8_t kHanFlag = 1u << 1; - static const uint8_t kHangulFlag = 1u << 2; - static const uint8_t kHiraganaFlag = 1u << 3; - static const uint8_t kKatakanaFlag = 1u << 4; - static const uint8_t kSimplifiedChineseFlag = 1u << 5; - static const uint8_t kTraditionalChineseFlag = 1u << 6; - uint8_t mSubScriptBits; - - static uint8_t scriptToSubScriptBits(uint32_t script); -}; - -typedef std::vector FontLanguages; - -} // namespace android - -#endif // MINIKIN_FONT_LANGUAGE_H diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp index 2d64998e7a3..e1c2343ddaa 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp @@ -19,92 +19,13 @@ #include "FontLanguageListCache.h" #include -#include -#include #include "MinikinInternal.h" -#include "FontLanguage.h" namespace android { const uint32_t FontLanguageListCache::kEmptyListId; -// Returns the text length of output. -static size_t toLanguageTag(char* output, size_t outSize, const std::string& locale) { - output[0] = '\0'; - if (locale.empty()) { - return 0; - } - - size_t outLength = 0; - UErrorCode uErr = U_ZERO_ERROR; - outLength = uloc_canonicalize(locale.c_str(), output, outSize, &uErr); - if (U_FAILURE(uErr)) { - // unable to build a proper language identifier - ALOGD("uloc_canonicalize(\"%s\") failed: %s", locale.c_str(), u_errorName(uErr)); - output[0] = '\0'; - return 0; - } - - // Preserve "und" and "und-****" since uloc_addLikelySubtags changes "und" to "en-Latn-US". - if (strncmp(output, "und", 3) == 0 && - (outLength == 3 || (outLength == 8 && output[3] == '_'))) { - return outLength; - } - - char likelyChars[ULOC_FULLNAME_CAPACITY]; - uErr = U_ZERO_ERROR; - uloc_addLikelySubtags(output, likelyChars, ULOC_FULLNAME_CAPACITY, &uErr); - if (U_FAILURE(uErr)) { - // unable to build a proper language identifier - ALOGD("uloc_addLikelySubtags(\"%s\") failed: %s", output, u_errorName(uErr)); - output[0] = '\0'; - return 0; - } - - uErr = U_ZERO_ERROR; - outLength = uloc_toLanguageTag(likelyChars, output, outSize, FALSE, &uErr); - if (U_FAILURE(uErr)) { - // unable to build a proper language identifier - ALOGD("uloc_toLanguageTag(\"%s\") failed: %s", likelyChars, u_errorName(uErr)); - output[0] = '\0'; - return 0; - } -#ifdef VERBOSE_DEBUG - ALOGD("ICU normalized '%s' to '%s'", locale.c_str(), output); -#endif - return outLength; -} - -static FontLanguages constructFontLanguages(const std::string& input) { - FontLanguages result; - size_t currentIdx = 0; - size_t commaLoc = 0; - char langTag[ULOC_FULLNAME_CAPACITY]; - std::unordered_set seen; - std::string locale(input.size(), 0); - - while ((commaLoc = input.find_first_of(',', currentIdx)) != std::string::npos) { - locale.assign(input, currentIdx, commaLoc - currentIdx); - currentIdx = commaLoc + 1; - size_t length = toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, locale); - FontLanguage lang(langTag, length); - uint64_t identifier = lang.getIdentifier(); - if (!lang.isUnsupported() && seen.count(identifier) == 0) { - result.push_back(lang); - seen.insert(identifier); - } - } - locale.assign(input, currentIdx, input.size() - currentIdx); - size_t length = toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, locale); - FontLanguage lang(langTag, length); - uint64_t identifier = lang.getIdentifier(); - if (!lang.isUnsupported() && seen.count(identifier) == 0) { - result.push_back(lang); - } - return result; -} - // static uint32_t FontLanguageListCache::getId(const std::string& languages) { FontLanguageListCache* inst = FontLanguageListCache::getInstance(); @@ -116,11 +37,7 @@ uint32_t FontLanguageListCache::getId(const std::string& languages) { // Given language list is not in cache. Insert it and return newly assigned ID. const uint32_t nextId = inst->mLanguageLists.size(); - FontLanguages fontLanguages = constructFontLanguages(languages); - if (fontLanguages.empty()) { - return kEmptyListId; - } - inst->mLanguageLists.push_back(fontLanguages); + inst->mLanguageLists.push_back(FontLanguages(languages.c_str(), languages.size())); inst->mLanguageListLookupTable.insert(std::make_pair(languages, nextId)); return nextId; } @@ -139,9 +56,8 @@ FontLanguageListCache* FontLanguageListCache::getInstance() { if (instance == nullptr) { instance = new FontLanguageListCache(); - // Insert an empty language list for mapping default language list to kEmptyListId. - // The default language list has only one FontLanguage and it is the unsupported language. - instance->mLanguageLists.push_back(FontLanguages({FontLanguage()})); + // Insert an empty language list for mapping empty language list to kEmptyListId. + instance->mLanguageLists.push_back(FontLanguages()); instance->mLanguageListLookupTable.insert(std::make_pair("", kEmptyListId)); } return instance; diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.h b/engine/src/flutter/libs/minikin/FontLanguageListCache.h index c961882f0a8..7d627b562e3 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.h +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.h @@ -20,7 +20,6 @@ #include #include -#include "FontLanguage.h" namespace android { diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 2e206a20fc3..af5e6fe75a7 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -34,7 +34,6 @@ #include #include -#include "FontLanguage.h" #include "FontLanguageListCache.h" #include "LayoutUtils.h" #include "HbFaceCache.h" @@ -747,15 +746,9 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t const FontLanguages& langList = FontLanguageListCache::getById(ctx->style.getLanguageListId()); if (langList.size() != 0) { - const FontLanguage* hbLanguage = &langList[0]; - for (size_t i = 0; i < langList.size(); ++i) { - if (langList[i].supportsHbScript(script)) { - hbLanguage = &langList[i]; - break; - } - } - hb_buffer_set_language(buffer, - hb_language_from_string(hbLanguage->getString().c_str(), -1)); + // TODO: use all languages in langList. + string lang = langList[0].getString(); + hb_buffer_set_language(buffer, hb_language_from_string(lang.c_str(), -1)); } hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart); if (ctx->paint.hyphenEdit.hasHyphen() && srunend > srunstart) { diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index cf9b704efa2..85d76afccb8 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -16,9 +16,7 @@ #include -#include "FontLanguage.h" #include "FontTestUtils.h" -#include "ICUTestBase.h" #include "MinikinFontForTest.h" #include "UnicodeUtils.h" @@ -44,8 +42,6 @@ const char kColorEmojiFont[] = kTestFontDir "ColorEmojiFont.ttf"; const char kTextEmojiFont[] = kTestFontDir "TextEmojiFont.ttf"; const char kMixedEmojiFont[] = kTestFontDir "ColorTextMixedEmojiFont.ttf"; -typedef ICUTestBase FontCollectionItemizeTest; - // Utility function for calling itemize function. void itemize(FontCollection* collection, const char* str, FontStyle style, std::vector* result) { @@ -64,7 +60,7 @@ const std::string& getFontPath(const FontCollection::Run& run) { return ((MinikinFontForTest*)run.fakedFont.font)->fontPath(); } -TEST_F(FontCollectionItemizeTest, itemize_latin) { +TEST(FontCollectionItemizeTest, itemize_latin) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -134,7 +130,7 @@ TEST_F(FontCollectionItemizeTest, itemize_latin) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); } -TEST_F(FontCollectionItemizeTest, itemize_emoji) { +TEST(FontCollectionItemizeTest, itemize_emoji) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -195,7 +191,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emoji) { EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeItalic()); } -TEST_F(FontCollectionItemizeTest, itemize_non_latin) { +TEST(FontCollectionItemizeTest, itemize_non_latin) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -284,7 +280,7 @@ TEST_F(FontCollectionItemizeTest, itemize_non_latin) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); } -TEST_F(FontCollectionItemizeTest, itemize_mixed) { +TEST(FontCollectionItemizeTest, itemize_mixed) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -323,7 +319,7 @@ TEST_F(FontCollectionItemizeTest, itemize_mixed) { EXPECT_FALSE(runs[4].fakedFont.fakery.isFakeItalic()); } -TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { +TEST(FontCollectionItemizeTest, itemize_variationSelector) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -462,7 +458,7 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { EXPECT_EQ(kLatinFont, getFontPath(runs[0])); } -TEST_F(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { +TEST(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -587,7 +583,7 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); } -TEST_F(FontCollectionItemizeTest, itemize_no_crash) { +TEST(FontCollectionItemizeTest, itemize_no_crash) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -611,7 +607,7 @@ TEST_F(FontCollectionItemizeTest, itemize_no_crash) { itemize(collection.get(), "U+FE00 U+302D U+E0100", FontStyle(), &runs); } -TEST_F(FontCollectionItemizeTest, itemize_fakery) { +TEST(FontCollectionItemizeTest, itemize_fakery) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -651,18 +647,18 @@ TEST_F(FontCollectionItemizeTest, itemize_fakery) { EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeItalic()); } -TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { +TEST(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { // kVSTestFont supports U+717D U+FE02 but doesn't support U+717D. // kVSTestFont should be selected for U+717D U+FE02 even if it does not support the base code // point. const std::string kVSTestFont = kTestFontDir "VarioationSelectorTest-Regular.ttf"; std::vector families; - FontFamily* family1 = new FontFamily(android::VARIANT_DEFAULT); + FontFamily* family1 = new FontFamily(FontLanguage(), android::VARIANT_DEFAULT); family1->addFont(new MinikinFontForTest(kLatinFont)); families.push_back(family1); - FontFamily* family2 = new FontFamily(android::VARIANT_DEFAULT); + FontFamily* family2 = new FontFamily(FontLanguage(), android::VARIANT_DEFAULT); family2->addFont(new MinikinFontForTest(kVSTestFont)); families.push_back(family2); @@ -680,7 +676,7 @@ TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { family2->Unref(); } -TEST_F(FontCollectionItemizeTest, itemize_emojiSelection) { +TEST(FontCollectionItemizeTest, itemize_emojiSelection) { std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); std::vector runs; @@ -752,7 +748,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection) { EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); } -TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { +TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); std::vector runs; @@ -834,7 +830,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { EXPECT_EQ(kMixedEmojiFont, getFontPath(runs[0])); } -TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { +TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); std::vector runs; diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index ac7616fada3..fc44e6c6369 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -17,261 +17,74 @@ #include #include - -#include - #include "FontLanguageListCache.h" -#include "ICUTestBase.h" #include "MinikinFontForTest.h" #include "MinikinInternal.h" namespace android { -typedef ICUTestBase FontLanguagesTest; -typedef ICUTestBase FontLanguageTest; - -static FontLanguages createFontLanguages(const std::string& input) { - uint32_t langId = FontLanguageListCache::getId(input); - return FontLanguageListCache::getById(langId); -} - -static FontLanguage createFontLanguage(const std::string& input) { - uint32_t langId = FontLanguageListCache::getId(input); - return FontLanguageListCache::getById(langId)[0]; -} - -TEST_F(FontLanguageTest, basicTests) { - FontLanguage defaultLang; - FontLanguage emptyLang("", 0); - FontLanguage english = createFontLanguage("en"); - FontLanguage french = createFontLanguage("fr"); - FontLanguage und = createFontLanguage("und"); - FontLanguage undQaae = createFontLanguage("und-Qaae"); - - EXPECT_EQ(english, english); - EXPECT_EQ(french, french); - - EXPECT_TRUE(defaultLang != defaultLang); - EXPECT_TRUE(emptyLang != emptyLang); - EXPECT_TRUE(defaultLang != emptyLang); - EXPECT_TRUE(defaultLang != und); - EXPECT_TRUE(emptyLang != und); - EXPECT_TRUE(english != defaultLang); - EXPECT_TRUE(english != emptyLang); - EXPECT_TRUE(english != french); - EXPECT_TRUE(english != undQaae); - EXPECT_TRUE(und != undQaae); - EXPECT_TRUE(english != und); - - EXPECT_TRUE(defaultLang.isUnsupported()); - EXPECT_TRUE(emptyLang.isUnsupported()); - - EXPECT_FALSE(english.isUnsupported()); - EXPECT_FALSE(french.isUnsupported()); - EXPECT_FALSE(und.isUnsupported()); - EXPECT_FALSE(undQaae.isUnsupported()); -} - -TEST_F(FontLanguageTest, getStringTest) { - EXPECT_EQ("en-Latn", createFontLanguage("en").getString()); - EXPECT_EQ("en-Latn", createFontLanguage("en-Latn").getString()); - - // Capitalized language code or lowercased script should be normalized. - EXPECT_EQ("en-Latn", createFontLanguage("EN-LATN").getString()); - EXPECT_EQ("en-Latn", createFontLanguage("EN-latn").getString()); - EXPECT_EQ("en-Latn", createFontLanguage("en-latn").getString()); - - // Invalid script should be kept. - EXPECT_EQ("en-Xyzt", createFontLanguage("en-xyzt").getString()); - - EXPECT_EQ("en-Latn", createFontLanguage("en-Latn-US").getString()); - EXPECT_EQ("ja-Jpan", createFontLanguage("ja").getString()); - EXPECT_EQ("und", createFontLanguage("und").getString()); - EXPECT_EQ("und", createFontLanguage("UND").getString()); - EXPECT_EQ("und", createFontLanguage("Und").getString()); - EXPECT_EQ("und-Qaae", createFontLanguage("und-Qaae").getString()); - EXPECT_EQ("und-Qaae", createFontLanguage("Und-QAAE").getString()); - EXPECT_EQ("und-Qaae", createFontLanguage("Und-qaae").getString()); - - EXPECT_EQ("de-Latn", createFontLanguage("de-1901").getString()); - - // This is not a necessary desired behavior, just known behavior. - EXPECT_EQ("en-Latn", createFontLanguage("und-Abcdefgh").getString()); -} - -TEST_F(FontLanguageTest, ScriptEqualTest) { - EXPECT_TRUE(createFontLanguage("en").isEqualScript(createFontLanguage("en"))); - EXPECT_TRUE(createFontLanguage("en-Latn").isEqualScript(createFontLanguage("en"))); - EXPECT_TRUE(createFontLanguage("jp-Latn").isEqualScript(createFontLanguage("en-Latn"))); - EXPECT_TRUE(createFontLanguage("en-Jpan").isEqualScript(createFontLanguage("en-Jpan"))); - - EXPECT_FALSE(createFontLanguage("en-Jpan").isEqualScript(createFontLanguage("en-Hira"))); - EXPECT_FALSE(createFontLanguage("en-Jpan").isEqualScript(createFontLanguage("en-Hani"))); -} - -TEST_F(FontLanguageTest, ScriptMatchTest) { - const bool SUPPORTED = true; - const bool NOT_SUPPORTED = false; - - struct TestCase { - const std::string baseScript; - const std::string requestedScript; - bool isSupported; - } testCases[] = { - // Same scripts - { "en-Latn", "Latn", SUPPORTED }, - { "ja-Jpan", "Jpan", SUPPORTED }, - { "ja-Hira", "Hira", SUPPORTED }, - { "ja-Kana", "Kana", SUPPORTED }, - { "ja-Hrkt", "Hrkt", SUPPORTED }, - { "zh-Hans", "Hans", SUPPORTED }, - { "zh-Hant", "Hant", SUPPORTED }, - { "zh-Hani", "Hani", SUPPORTED }, - { "ko-Kore", "Kore", SUPPORTED }, - { "ko-Hang", "Hang", SUPPORTED }, - - // Japanese supports Hiragana, Katakanara, etc. - { "ja-Jpan", "Hira", SUPPORTED }, - { "ja-Jpan", "Kana", SUPPORTED }, - { "ja-Jpan", "Hrkt", SUPPORTED }, - { "ja-Hrkt", "Hira", SUPPORTED }, - { "ja-Hrkt", "Kana", SUPPORTED }, - - // Chinese supports Han. - { "zh-Hans", "Hani", SUPPORTED }, - { "zh-Hant", "Hani", SUPPORTED }, - - // Korean supports Hangul. - { "ko-Kore", "Hang", SUPPORTED }, - - // Different scripts - { "ja-Jpan", "Latn", NOT_SUPPORTED }, - { "en-Latn", "Jpan", NOT_SUPPORTED }, - { "ja-Jpan", "Hant", NOT_SUPPORTED }, - { "zh-Hant", "Jpan", NOT_SUPPORTED }, - { "ja-Jpan", "Hans", NOT_SUPPORTED }, - { "zh-Hans", "Jpan", NOT_SUPPORTED }, - { "ja-Jpan", "Kore", NOT_SUPPORTED }, - { "ko-Kore", "Jpan", NOT_SUPPORTED }, - { "zh-Hans", "Hant", NOT_SUPPORTED }, - { "zh-Hant", "Hans", NOT_SUPPORTED }, - { "zh-Hans", "Kore", NOT_SUPPORTED }, - { "ko-Kore", "Hans", NOT_SUPPORTED }, - { "zh-Hant", "Kore", NOT_SUPPORTED }, - { "ko-Kore", "Hant", NOT_SUPPORTED }, - - // Hiragana doesn't support Japanese, etc. - { "ja-Hira", "Jpan", NOT_SUPPORTED }, - { "ja-Kana", "Jpan", NOT_SUPPORTED }, - { "ja-Hrkt", "Jpan", NOT_SUPPORTED }, - { "ja-Hani", "Jpan", NOT_SUPPORTED }, - { "ja-Hira", "Hrkt", NOT_SUPPORTED }, - { "ja-Kana", "Hrkt", NOT_SUPPORTED }, - { "ja-Hani", "Hrkt", NOT_SUPPORTED }, - { "ja-Hani", "Hira", NOT_SUPPORTED }, - { "ja-Hani", "Kana", NOT_SUPPORTED }, - - // Kanji doesn't support Chinese, etc. - { "zh-Hani", "Hant", NOT_SUPPORTED }, - { "zh-Hani", "Hans", NOT_SUPPORTED }, - - // Hangul doesn't support Korean, etc. - { "ko-Hang", "Kore", NOT_SUPPORTED }, - { "ko-Hani", "Kore", NOT_SUPPORTED }, - { "ko-Hani", "Hang", NOT_SUPPORTED }, - { "ko-Hang", "Hani", NOT_SUPPORTED }, - }; - - for (auto testCase : testCases) { - hb_script_t script = hb_script_from_iso15924_tag( - HB_TAG(testCase.requestedScript[0], testCase.requestedScript[1], - testCase.requestedScript[2], testCase.requestedScript[3])); - if (testCase.isSupported) { - EXPECT_TRUE( - createFontLanguage(testCase.baseScript).supportsHbScript(script)) - << testCase.baseScript << " should support " << testCase.requestedScript; - } else { - EXPECT_FALSE( - createFontLanguage(testCase.baseScript).supportsHbScript(script)) - << testCase.baseScript << " shouldn't support " << testCase.requestedScript; - } - } -} - -TEST_F(FontLanguagesTest, basicTests) { +TEST(FontLanguagesTest, basicTests) { FontLanguages emptyLangs; EXPECT_EQ(0u, emptyLangs.size()); - FontLanguage english = createFontLanguage("en"); - FontLanguages singletonLangs = createFontLanguages("en"); + FontLanguage english("en", 2); + FontLanguages singletonLangs("en", 2); EXPECT_EQ(1u, singletonLangs.size()); EXPECT_EQ(english, singletonLangs[0]); - FontLanguage french = createFontLanguage("fr"); - FontLanguages twoLangs = createFontLanguages("en,fr"); + FontLanguage french("fr", 2); + FontLanguages twoLangs("en,fr", 5); EXPECT_EQ(2u, twoLangs.size()); EXPECT_EQ(english, twoLangs[0]); EXPECT_EQ(french, twoLangs[1]); } -TEST_F(FontLanguagesTest, unsupportedLanguageTests) { - FontLanguage unsupportedLang = createFontLanguage("abcd"); +TEST(FontLanguagesTest, unsupportedLanguageTests) { + FontLanguage unsupportedLang("x-example", 9); ASSERT_TRUE(unsupportedLang.isUnsupported()); - FontLanguages oneUnsupported = createFontLanguages("abcd-example"); + FontLanguages oneUnsupported("x-example", 9); EXPECT_EQ(1u, oneUnsupported.size()); EXPECT_TRUE(oneUnsupported[0].isUnsupported()); - FontLanguages twoUnsupporteds = createFontLanguages("abcd-example,abcd-example"); + FontLanguages twoUnsupporteds("x-example,x-example", 19); EXPECT_EQ(1u, twoUnsupporteds.size()); EXPECT_TRUE(twoUnsupporteds[0].isUnsupported()); - FontLanguage english = createFontLanguage("en"); - FontLanguages firstUnsupported = createFontLanguages("abcd-example,en"); + FontLanguage english("en", 2); + FontLanguages firstUnsupported("x-example,en", 12); EXPECT_EQ(1u, firstUnsupported.size()); EXPECT_EQ(english, firstUnsupported[0]); - FontLanguages lastUnsupported = createFontLanguages("en,abcd-example"); + FontLanguages lastUnsupported("en,x-example", 12); EXPECT_EQ(1u, lastUnsupported.size()); EXPECT_EQ(english, lastUnsupported[0]); } -TEST_F(FontLanguagesTest, repeatedLanguageTests) { - FontLanguage english = createFontLanguage("en"); - FontLanguage french = createFontLanguage("fr"); - FontLanguage englishInLatn = createFontLanguage("en-Latn"); +TEST(FontLanguagesTest, repeatedLanguageTests) { + FontLanguage english("en", 2); + FontLanguage englishInLatn("en-Latn", 2); ASSERT_TRUE(english == englishInLatn); - FontLanguages langs = createFontLanguages("en,en-Latn"); + FontLanguages langs("en,en-Latn", 10); EXPECT_EQ(1u, langs.size()); EXPECT_EQ(english, langs[0]); - - // Country codes are ignored. - FontLanguages fr = createFontLanguages("fr,fr-CA,fr-FR"); - EXPECT_EQ(1u, fr.size()); - EXPECT_EQ(french, fr[0]); - - // The order should be kept. - langs = createFontLanguages("en,fr,en-Latn"); - EXPECT_EQ(2u, langs.size()); - EXPECT_EQ(english, langs[0]); - EXPECT_EQ(french, langs[1]); } -TEST_F(FontLanguagesTest, undEmojiTests) { - FontLanguage emoji = createFontLanguage("und-Qaae"); +TEST(FontLanguagesTest, undEmojiTests) { + FontLanguage emoji("und-Qaae", 8); EXPECT_TRUE(emoji.hasEmojiFlag()); - FontLanguage und = createFontLanguage("und"); + FontLanguage und("und", 3); EXPECT_FALSE(und.hasEmojiFlag()); EXPECT_FALSE(emoji == und); - FontLanguage undExample = createFontLanguage("und-example"); + FontLanguage undExample("und-example", 10); EXPECT_FALSE(undExample.hasEmojiFlag()); EXPECT_FALSE(emoji == undExample); } -TEST_F(FontLanguagesTest, registerLanguageListTest) { +TEST(FontLanguagesTest, registerLanguageListTest) { EXPECT_EQ(0UL, FontStyle::registerLanguageList("")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en")); EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); @@ -309,10 +122,9 @@ TEST_F(FontLanguagesTest, registerLanguageListTest) { // U+717D U+E0103 (VS20) const char kVsTestFont[] = kTestFontDir "VarioationSelectorTest-Regular.ttf"; -class FontFamilyTest : public ICUTestBase { +class FontFamilyTest : public testing::Test { public: virtual void SetUp() override { - ICUTestBase::SetUp(); if (access(kVsTestFont, R_OK) != 0) { FAIL() << "Unable to read " << kVsTestFont << ". " << "Please prepare the test data directory. " diff --git a/engine/src/flutter/tests/FontLanguageListCacheTest.cpp b/engine/src/flutter/tests/FontLanguageListCacheTest.cpp index f83988c1f50..29757fedceb 100644 --- a/engine/src/flutter/tests/FontLanguageListCacheTest.cpp +++ b/engine/src/flutter/tests/FontLanguageListCacheTest.cpp @@ -17,15 +17,11 @@ #include #include - #include "FontLanguageListCache.h" -#include "ICUTestBase.h" namespace android { -typedef ICUTestBase FontLanguageListCacheTest; - -TEST_F(FontLanguageListCacheTest, getId) { +TEST(FontLanguageListCacheTest, getId) { EXPECT_EQ(0UL, FontLanguageListCache::getId("")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en")); EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); @@ -46,15 +42,11 @@ TEST_F(FontLanguageListCacheTest, getId) { FontLanguageListCache::getId("en,zh-Hant")); } -TEST_F(FontLanguageListCacheTest, getById) { - uint32_t enLangId = FontLanguageListCache::getId("en"); - uint32_t jpLangId = FontLanguageListCache::getId("jp"); - FontLanguage english = FontLanguageListCache::getById(enLangId)[0]; - FontLanguage japanese = FontLanguageListCache::getById(jpLangId)[0]; +TEST(FontLanguageListCacheTest, getById) { + FontLanguage english("en", 2); + FontLanguage japanese("jp", 2); - FontLanguages defLangs = FontLanguageListCache::getById(0); - EXPECT_EQ(1UL, defLangs.size()); - EXPECT_TRUE(defLangs[0].isUnsupported()); + EXPECT_EQ(0UL, FontLanguageListCache::getById(0).size()); FontLanguages langs = FontLanguageListCache::getById(FontLanguageListCache::getId("en")); ASSERT_EQ(1UL, langs.size()); diff --git a/engine/src/flutter/tests/FontTestUtils.cpp b/engine/src/flutter/tests/FontTestUtils.cpp index 98dab5121b0..8e1d184adcc 100644 --- a/engine/src/flutter/tests/FontTestUtils.cpp +++ b/engine/src/flutter/tests/FontTestUtils.cpp @@ -20,8 +20,6 @@ #include #include - -#include "FontLanguage.h" #include "MinikinFontForTest.h" std::unique_ptr getFontCollection( @@ -46,10 +44,9 @@ std::unique_ptr getFontCollection( } xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); - uint32_t langId = android::FontStyle::registerLanguageList( - std::string((const char*)lang, xmlStrlen(lang))); - android::FontFamily* family = new android::FontFamily(langId, variant); + android::FontFamily* family = new android::FontFamily( + android::FontLanguage((const char*)lang, xmlStrlen(lang)), variant); for (xmlNode* fontNode = familyNode->children; fontNode; fontNode = fontNode->next) { if (xmlStrcmp(fontNode->name, (const xmlChar*)"font") != 0) { diff --git a/engine/src/flutter/tests/ICUTestBase.h b/engine/src/flutter/tests/ICUTestBase.h deleted file mode 100644 index 3bcfaf36945..00000000000 --- a/engine/src/flutter/tests/ICUTestBase.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2015 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_TEST_ICU_TEST_BASE_H -#define MINIKIN_TEST_ICU_TEST_BASE_H - -#include -#include -#include - -// low level file access for mapping ICU data -#include -#include -#include - -class ICUTestBase : public testing::Test { -protected: - virtual void SetUp() override { - const char* fn = "/system/usr/icu/" U_ICUDATA_NAME ".dat"; - int fd = open(fn, O_RDONLY); - ASSERT_NE(-1, fd); - struct stat sb; - ASSERT_EQ(0, fstat(fd, &sb)); - void* data = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0); - - UErrorCode errorCode = U_ZERO_ERROR; - udata_setCommonData(data, &errorCode); - ASSERT_TRUE(U_SUCCESS(errorCode)); - u_init(&errorCode); - ASSERT_TRUE(U_SUCCESS(errorCode)); - } - - virtual void TearDown() override { - u_cleanup(); - } -}; - - -#endif // MINIKIN_TEST_ICU_TEST_BASE_H From 5bacbeb51400c6c9491b1a3b3267aec71252a200 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Mon, 14 Dec 2015 18:33:23 -0800 Subject: [PATCH 135/364] Save all kind of script tags into FontLanguage. This is 2nd attempt of I8df992a6851021903478972601a9a5c9424b100c. The main purpose of this CL is expanding FontLanguage to be able to save full script tag. Previously, FontLangauge kept only limited script tags. With this CL, FontLanguage keeps all script tags. This CL contains the following changes: - FontLanguage changes: -- Moved to private directory not to be instantiated outside of Minikin. -- Removed bool(), bits(), FontLanguage(uint32_t) methods which are no longer used. -- Change the FontLanguage internal data structure. -- Introduces script match logic. - FontLanguages changes: -- Moved to private directory not to be instantiated outside of Minikin. -- This is now std::vector - FontLanguageListCache changes: -- Now FontLanguageListCache::getId through FontStyle::registerLanguageList is the only way to instantiate the FontLanguage. -- Normalize input to be BCP47 compliant identifier by ICU. Bug: 26168983 Change-Id: I431b3f361a7635497c05b85e8ecbeb48d9aef63e --- .../src/flutter/include/minikin/FontFamily.h | 64 +---- engine/src/flutter/libs/minikin/Android.mk | 1 + .../flutter/libs/minikin/FontCollection.cpp | 10 +- .../src/flutter/libs/minikin/FontFamily.cpp | 120 +-------- .../src/flutter/libs/minikin/FontLanguage.cpp | 136 ++++++++++ .../src/flutter/libs/minikin/FontLanguage.h | 89 +++++++ .../libs/minikin/FontLanguageListCache.cpp | 90 ++++++- .../libs/minikin/FontLanguageListCache.h | 1 + engine/src/flutter/libs/minikin/Layout.cpp | 13 +- .../tests/FontCollectionItemizeTest.cpp | 32 +-- engine/src/flutter/tests/FontFamilyTest.cpp | 232 ++++++++++++++++-- .../tests/FontLanguageListCacheTest.cpp | 18 +- engine/src/flutter/tests/FontTestUtils.cpp | 7 +- engine/src/flutter/tests/ICUTestBase.h | 52 ++++ 14 files changed, 640 insertions(+), 225 deletions(-) create mode 100644 engine/src/flutter/libs/minikin/FontLanguage.cpp create mode 100644 engine/src/flutter/libs/minikin/FontLanguage.h create mode 100644 engine/src/flutter/tests/ICUTestBase.h diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 00130e6f5d0..aa2e0ac2e4a 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -30,62 +30,6 @@ namespace android { class MinikinFont; -// FontLanguage is a compact representation of a bcp-47 language tag. It -// does not capture all possible information, only what directly affects -// font rendering. -class FontLanguage { - friend class FontStyle; - friend class FontLanguages; -public: - FontLanguage() : mBits(0) { } - - // Parse from string - FontLanguage(const char* buf, size_t size); - - bool operator==(const FontLanguage other) const { - return mBits != kUnsupportedLanguage && mBits == other.mBits; - } - operator bool() const { return mBits != 0; } - - bool isUnsupported() const { return mBits == kUnsupportedLanguage; } - bool hasEmojiFlag() const { return isUnsupported() ? false : (mBits & kEmojiFlag); } - - std::string getString() const; - - // 0 = no match, 1 = language matches - int match(const FontLanguage other) const; - -private: - explicit FontLanguage(uint32_t bits) : mBits(bits) { } - - uint32_t bits() const { return mBits; } - - static const uint32_t kUnsupportedLanguage = 0xFFFFFFFFu; - static const uint32_t kBaseLangMask = 0xFFFFFFu; - static const uint32_t kHansFlag = 1u << 24; - static const uint32_t kHantFlag = 1u << 25; - static const uint32_t kEmojiFlag = 1u << 26; - static const uint32_t kScriptMask = kHansFlag | kHantFlag | kEmojiFlag; - uint32_t mBits; -}; - -// A list of zero or more instances of FontLanguage, in the order of -// preference. Used for further resolution of rendering results. -class FontLanguages { -public: - FontLanguages() { mLangs.clear(); } - - // Parse from string, which is a comma-separated list of languages - FontLanguages(const char* buf, size_t size); - - const FontLanguage& operator[](size_t index) const { return mLangs.at(index); } - - size_t size() const { return mLangs.size(); } - -private: - std::vector mLangs; -}; - // FontStyle represents all style information needed to select an actual font // from a collection. The implementation is packed into two 32-bit words // so it can be efficiently copied, embedded in other objects, etc. @@ -158,7 +102,9 @@ class FontFamily : public MinikinRefCounted { public: FontFamily() : mHbFont(nullptr) { } - FontFamily(FontLanguage lang, int variant) : mLang(lang), mVariant(variant), mHbFont(nullptr) { + FontFamily(int variant); + + FontFamily(uint32_t langId, int variant) : mLangId(langId), mVariant(variant), mHbFont(nullptr) { } ~FontFamily(); @@ -169,7 +115,7 @@ public: void addFont(MinikinFont* typeface, FontStyle style); FakedFont getClosestMatch(FontStyle style) const; - FontLanguage lang() const { return mLang; } + uint32_t langId() const { return mLangId; } int variant() const { return mVariant; } // API's for enumerating the fonts in a family. These don't guarantee any particular order @@ -200,7 +146,7 @@ private: MinikinFont* typeface; FontStyle style; }; - FontLanguage mLang; + uint32_t mLangId; int mVariant; std::vector mFonts; diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 4c945a60c9c..42fdca39193 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -21,6 +21,7 @@ minikin_src_files := \ CmapCoverage.cpp \ FontCollection.cpp \ FontFamily.cpp \ + FontLanguage.cpp \ FontLanguageListCache.cpp \ GraphemeBreak.cpp \ HbFaceCache.cpp \ diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index bba2ef95359..62c70310c06 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -22,6 +22,7 @@ #include "unicode/unistr.h" #include "unicode/unorm2.h" +#include "FontLanguage.h" #include "FontLanguageListCache.h" #include "MinikinInternal.h" #include @@ -150,14 +151,17 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, // always use it. return family; } - int score = lang.match(family->lang()) * 2; + + // TODO use all language in the list. + FontLanguage fontLang = FontLanguageListCache::getById(family->langId())[0]; + int score = lang.match(fontLang) * 2; if (family->variant() == 0 || family->variant() == variant) { score++; } if (hasVSGlyph) { score += 8; - } else if (((vs == 0xFE0F) && family->lang().hasEmojiFlag()) || - ((vs == 0xFE0E) && !family->lang().hasEmojiFlag())) { + } else if (((vs == 0xFE0F) && fontLang.hasEmojiFlag()) || + ((vs == 0xFE0E) && !fontLang.hasEmojiFlag())) { score += 4; } if (score > bestScore) { diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 76398312406..14057890281 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -16,8 +16,6 @@ #define LOG_TAG "Minikin" -#include - #include #include #include @@ -28,6 +26,7 @@ #include +#include "FontLanguage.h" #include "FontLanguageListCache.h" #include "HbFaceCache.h" #include "MinikinInternal.h" @@ -41,117 +40,6 @@ using std::vector; namespace android { -// Parse bcp-47 language identifier into internal structure -FontLanguage::FontLanguage(const char* buf, size_t size) { - uint32_t bits = 0; - size_t i; - for (i = 0; i < size; i++) { - uint16_t c = buf[i]; - if (c == '-' || c == '_') break; - } - if (i == 2) { - bits = uint8_t(buf[0]) | (uint8_t(buf[1]) << 8); - } else if (i == 3) { - bits = uint8_t(buf[0]) | (uint8_t(buf[1]) << 8) | (uint8_t(buf[2]) << 16); - } else { - mBits = kUnsupportedLanguage; - // We don't understand anything other than two-letter or three-letter - // language codes, so we skip parsing the rest of the string. - return; - } - size_t next; - for (i++; i < size; i = next + 1) { - for (next = i; next < size; next++) { - uint16_t c = buf[next]; - if (c == '-' || c == '_') break; - } - if (next - i == 4) { - if (buf[i] == 'H' && buf[i+1] == 'a' && buf[i+2] == 'n') { - if (buf[i+3] == 's') { - bits |= kHansFlag; - } else if (buf[i+3] == 't') { - bits |= kHantFlag; - } - } else if (buf[i] == 'Q' && buf[i+1] == 'a' && buf[i+2] == 'a'&& buf[i+3] == 'e') { - bits |= kEmojiFlag; - } - } - // TODO: this might be a good place to infer script from country (zh_TW -> Hant), - // but perhaps it's up to the client to do that, before passing a string. - } - mBits = bits; -} - -std::string FontLanguage::getString() const { - if (mBits == kUnsupportedLanguage) { - return "und"; - } - char buf[16]; - size_t i = 0; - if (mBits & kBaseLangMask) { - buf[i++] = mBits & 0xFFu; - buf[i++] = (mBits >> 8) & 0xFFu; - char third_letter = (mBits >> 16) & 0xFFu; - if (third_letter != 0) buf[i++] = third_letter; - } - if (mBits & kScriptMask) { - if (!i) { - // This should not happen, but as it apparently has, we fill the language code part - // with "und". - buf[i++] = 'u'; - buf[i++] = 'n'; - buf[i++] = 'd'; - } - buf[i++] = '-'; - if (mBits & kEmojiFlag) { - buf[i++] = 'Q'; - buf[i++] = 'a'; - buf[i++] = 'a'; - buf[i++] = 'e'; - } else { - buf[i++] = 'H'; - buf[i++] = 'a'; - buf[i++] = 'n'; - buf[i++] = (mBits & kHansFlag) ? 's' : 't'; - } - } - return std::string(buf, i); -} - -int FontLanguage::match(const FontLanguage other) const { - return *this == other; -} - -FontLanguages::FontLanguages(const char* buf, size_t size) { - std::unordered_set seen; - mLangs.clear(); - const char* bufEnd = buf + size; - const char* lastStart = buf; - bool isLastLang = false; - while (true) { - const char* commaLoc = static_cast( - memchr(lastStart, ',', bufEnd - lastStart)); - if (commaLoc == NULL) { - commaLoc = bufEnd; - isLastLang = true; - } - FontLanguage lang(lastStart, commaLoc - lastStart); - if (isLastLang && mLangs.size() == 0) { - // Make sure the list has at least one member - mLangs.push_back(lang); - return; - } - uint32_t bits = lang.bits(); - if (bits != FontLanguage::kUnsupportedLanguage && seen.count(bits) == 0) { - mLangs.push_back(lang); - if (isLastLang) return; - seen.insert(bits); - } - if (isLastLang) return; - lastStart = commaLoc + 1; - } -} - FontStyle::FontStyle(int variant, int weight, bool italic) : FontStyle(FontLanguageListCache::kEmptyListId, variant, weight, italic) { } @@ -177,6 +65,9 @@ uint32_t FontStyle::pack(int variant, int weight, bool italic) { return (weight & kWeightMask) | (italic ? kItalicMask : 0) | (variant << kVariantShift); } +FontFamily::FontFamily(int variant) : FontFamily(FontLanguageListCache::kEmptyListId, variant) { +} + FontFamily::~FontFamily() { for (size_t i = 0; i < mFonts.size(); i++) { mFonts[i].typeface->UnrefLocked(); @@ -210,7 +101,8 @@ void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { addFontLocked(typeface, style); } -void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { typeface->RefLocked(); +void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { + typeface->RefLocked(); mFonts.push_back(Font(typeface, style)); mCoverageValid = false; } diff --git a/engine/src/flutter/libs/minikin/FontLanguage.cpp b/engine/src/flutter/libs/minikin/FontLanguage.cpp new file mode 100644 index 00000000000..bb8d608ac3d --- /dev/null +++ b/engine/src/flutter/libs/minikin/FontLanguage.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2015 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. + */ + +#define LOG_TAG "Minikin" + +#include "FontLanguage.h" + +#include +#include + +namespace android { + +#define SCRIPT_TAG(c1, c2, c3, c4) \ + (((uint32_t)(c1)) << 24 | ((uint32_t)(c2)) << 16 | ((uint32_t)(c3)) << 8 | \ + ((uint32_t)(c4))) + +// Parse BCP 47 language identifier into internal structure +FontLanguage::FontLanguage(const char* buf, size_t length) : FontLanguage() { + size_t i; + for (i = 0; i < length; i++) { + char c = buf[i]; + if (c == '-' || c == '_') break; + } + if (i == 2 || i == 3) { // only accept two or three letter language code. + mLanguage = buf[0] | (buf[1] << 8) | ((i == 3) ? (buf[2] << 16) : 0); + } else { + // We don't understand anything other than two-letter or three-letter + // language codes, so we skip parsing the rest of the string. + mLanguage = 0ul; + return; + } + + size_t next; + for (i++; i < length; i = next + 1) { + for (next = i; next < length; next++) { + char c = buf[next]; + if (c == '-' || c == '_') break; + } + if (next - i == 4 && 'A' <= buf[i] && buf[i] <= 'Z') { + mScript = SCRIPT_TAG(buf[i], buf[i + 1], buf[i + 2], buf[i + 3]); + } + } + + mSubScriptBits = scriptToSubScriptBits(mScript); +} + +//static +uint8_t FontLanguage::scriptToSubScriptBits(uint32_t script) { + uint8_t subScriptBits = 0u; + switch (script) { + case SCRIPT_TAG('H', 'a', 'n', 'g'): + subScriptBits = kHangulFlag; + break; + case SCRIPT_TAG('H', 'a', 'n', 'i'): + subScriptBits = kHanFlag; + break; + case SCRIPT_TAG('H', 'a', 'n', 's'): + subScriptBits = kHanFlag | kSimplifiedChineseFlag; + break; + case SCRIPT_TAG('H', 'a', 'n', 't'): + subScriptBits = kHanFlag | kTraditionalChineseFlag; + break; + case SCRIPT_TAG('H', 'i', 'r', 'a'): + subScriptBits = kHiraganaFlag; + break; + case SCRIPT_TAG('H', 'r', 'k', 't'): + subScriptBits = kKatakanaFlag | kHiraganaFlag; + break; + case SCRIPT_TAG('J', 'p', 'a', 'n'): + subScriptBits = kHanFlag | kKatakanaFlag | kHiraganaFlag; + break; + case SCRIPT_TAG('K', 'a', 'n', 'a'): + subScriptBits = kKatakanaFlag; + break; + case SCRIPT_TAG('K', 'o', 'r', 'e'): + subScriptBits = kHanFlag | kHangulFlag; + break; + case SCRIPT_TAG('Q', 'a', 'a', 'e'): + subScriptBits = kEmojiFlag; + break; + } + return subScriptBits; +} + +std::string FontLanguage::getString() const { + if (mLanguage == 0ul) { + return "und"; + } + char buf[16]; + size_t i = 0; + buf[i++] = mLanguage & 0xFF ; + buf[i++] = (mLanguage >> 8) & 0xFF; + char third_letter = (mLanguage >> 16) & 0xFF; + if (third_letter != 0) buf[i++] = third_letter; + if (mScript != 0) { + buf[i++] = '-'; + buf[i++] = (mScript >> 24) & 0xFFu; + buf[i++] = (mScript >> 16) & 0xFFu; + buf[i++] = (mScript >> 8) & 0xFFu; + buf[i++] = mScript & 0xFFu; + } + return std::string(buf, i); +} + +bool FontLanguage::isEqualScript(const FontLanguage other) const { + return other.mScript == mScript; +} + +bool FontLanguage::supportsHbScript(hb_script_t script) const { + static_assert(SCRIPT_TAG('J', 'p', 'a', 'n') == HB_TAG('J', 'p', 'a', 'n'), + "The Minikin script and HarfBuzz hb_script_t have different encodings."); + if (script == mScript) return true; + uint8_t requestedBits = scriptToSubScriptBits(script); + return requestedBits != 0 && (mSubScriptBits & requestedBits) == requestedBits; +} + +int FontLanguage::match(const FontLanguage other) const { + // TODO: Use script for matching. + return *this == other; +} + +#undef SCRIPT_TAG +} // namespace android diff --git a/engine/src/flutter/libs/minikin/FontLanguage.h b/engine/src/flutter/libs/minikin/FontLanguage.h new file mode 100644 index 00000000000..abe7d13179d --- /dev/null +++ b/engine/src/flutter/libs/minikin/FontLanguage.h @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2015 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_LANGUAGE_H +#define MINIKIN_FONT_LANGUAGE_H + +#include +#include + +#include + +namespace android { + +// FontLanguage is a compact representation of a BCP 47 language tag. It +// does not capture all possible information, only what directly affects +// font rendering. +struct FontLanguage { +public: + // Default constructor creates the unsupported language. + FontLanguage() : mScript(0ul), mLanguage(0ul), mSubScriptBits(0ul) {} + + // Parse from string + FontLanguage(const char* buf, size_t length); + + bool operator==(const FontLanguage other) const { + return !isUnsupported() && isEqualScript(other) && isEqualLanguage(other); + } + + bool operator!=(const FontLanguage other) const { + return !(*this == other); + } + + bool isUnsupported() const { return mLanguage == 0ul; } + bool hasEmojiFlag() const { return mSubScriptBits & kEmojiFlag; } + + bool isEqualLanguage(const FontLanguage other) const { return mLanguage == other.mLanguage; } + bool isEqualScript(const FontLanguage other) const; + + // Returns true if this script supports the given script. For example, ja-Jpan supports Hira, + // ja-Hira doesn't support Jpan. + bool supportsHbScript(hb_script_t script) const; + + std::string getString() const; + + // 0 = no match, 1 = language matches + int match(const FontLanguage other) const; + + uint64_t getIdentifier() const { return (uint64_t)mScript << 32 | (uint64_t)mLanguage; } + +private: + // ISO 15924 compliant script code. The 4 chars script code are packed into a 32 bit integer. + uint32_t mScript; + + // ISO 639-1 or ISO 639-2 compliant language code. + // The two or three letter language code is packed into 32 bit integer. + // mLanguage = 0 means the FontLanguage is unsupported. + uint32_t mLanguage; + + // For faster comparing, use 7 bits for specific scripts. + static const uint8_t kEmojiFlag = 1u; + static const uint8_t kHanFlag = 1u << 1; + static const uint8_t kHangulFlag = 1u << 2; + static const uint8_t kHiraganaFlag = 1u << 3; + static const uint8_t kKatakanaFlag = 1u << 4; + static const uint8_t kSimplifiedChineseFlag = 1u << 5; + static const uint8_t kTraditionalChineseFlag = 1u << 6; + uint8_t mSubScriptBits; + + static uint8_t scriptToSubScriptBits(uint32_t script); +}; + +typedef std::vector FontLanguages; + +} // namespace android + +#endif // MINIKIN_FONT_LANGUAGE_H diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp index e1c2343ddaa..2d64998e7a3 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp @@ -19,13 +19,92 @@ #include "FontLanguageListCache.h" #include +#include +#include #include "MinikinInternal.h" +#include "FontLanguage.h" namespace android { const uint32_t FontLanguageListCache::kEmptyListId; +// Returns the text length of output. +static size_t toLanguageTag(char* output, size_t outSize, const std::string& locale) { + output[0] = '\0'; + if (locale.empty()) { + return 0; + } + + size_t outLength = 0; + UErrorCode uErr = U_ZERO_ERROR; + outLength = uloc_canonicalize(locale.c_str(), output, outSize, &uErr); + if (U_FAILURE(uErr)) { + // unable to build a proper language identifier + ALOGD("uloc_canonicalize(\"%s\") failed: %s", locale.c_str(), u_errorName(uErr)); + output[0] = '\0'; + return 0; + } + + // Preserve "und" and "und-****" since uloc_addLikelySubtags changes "und" to "en-Latn-US". + if (strncmp(output, "und", 3) == 0 && + (outLength == 3 || (outLength == 8 && output[3] == '_'))) { + return outLength; + } + + char likelyChars[ULOC_FULLNAME_CAPACITY]; + uErr = U_ZERO_ERROR; + uloc_addLikelySubtags(output, likelyChars, ULOC_FULLNAME_CAPACITY, &uErr); + if (U_FAILURE(uErr)) { + // unable to build a proper language identifier + ALOGD("uloc_addLikelySubtags(\"%s\") failed: %s", output, u_errorName(uErr)); + output[0] = '\0'; + return 0; + } + + uErr = U_ZERO_ERROR; + outLength = uloc_toLanguageTag(likelyChars, output, outSize, FALSE, &uErr); + if (U_FAILURE(uErr)) { + // unable to build a proper language identifier + ALOGD("uloc_toLanguageTag(\"%s\") failed: %s", likelyChars, u_errorName(uErr)); + output[0] = '\0'; + return 0; + } +#ifdef VERBOSE_DEBUG + ALOGD("ICU normalized '%s' to '%s'", locale.c_str(), output); +#endif + return outLength; +} + +static FontLanguages constructFontLanguages(const std::string& input) { + FontLanguages result; + size_t currentIdx = 0; + size_t commaLoc = 0; + char langTag[ULOC_FULLNAME_CAPACITY]; + std::unordered_set seen; + std::string locale(input.size(), 0); + + while ((commaLoc = input.find_first_of(',', currentIdx)) != std::string::npos) { + locale.assign(input, currentIdx, commaLoc - currentIdx); + currentIdx = commaLoc + 1; + size_t length = toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, locale); + FontLanguage lang(langTag, length); + uint64_t identifier = lang.getIdentifier(); + if (!lang.isUnsupported() && seen.count(identifier) == 0) { + result.push_back(lang); + seen.insert(identifier); + } + } + locale.assign(input, currentIdx, input.size() - currentIdx); + size_t length = toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, locale); + FontLanguage lang(langTag, length); + uint64_t identifier = lang.getIdentifier(); + if (!lang.isUnsupported() && seen.count(identifier) == 0) { + result.push_back(lang); + } + return result; +} + // static uint32_t FontLanguageListCache::getId(const std::string& languages) { FontLanguageListCache* inst = FontLanguageListCache::getInstance(); @@ -37,7 +116,11 @@ uint32_t FontLanguageListCache::getId(const std::string& languages) { // Given language list is not in cache. Insert it and return newly assigned ID. const uint32_t nextId = inst->mLanguageLists.size(); - inst->mLanguageLists.push_back(FontLanguages(languages.c_str(), languages.size())); + FontLanguages fontLanguages = constructFontLanguages(languages); + if (fontLanguages.empty()) { + return kEmptyListId; + } + inst->mLanguageLists.push_back(fontLanguages); inst->mLanguageListLookupTable.insert(std::make_pair(languages, nextId)); return nextId; } @@ -56,8 +139,9 @@ FontLanguageListCache* FontLanguageListCache::getInstance() { if (instance == nullptr) { instance = new FontLanguageListCache(); - // Insert an empty language list for mapping empty language list to kEmptyListId. - instance->mLanguageLists.push_back(FontLanguages()); + // Insert an empty language list for mapping default language list to kEmptyListId. + // The default language list has only one FontLanguage and it is the unsupported language. + instance->mLanguageLists.push_back(FontLanguages({FontLanguage()})); instance->mLanguageListLookupTable.insert(std::make_pair("", kEmptyListId)); } return instance; diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.h b/engine/src/flutter/libs/minikin/FontLanguageListCache.h index 7d627b562e3..c961882f0a8 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.h +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.h @@ -20,6 +20,7 @@ #include #include +#include "FontLanguage.h" namespace android { diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index af5e6fe75a7..2e206a20fc3 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -34,6 +34,7 @@ #include #include +#include "FontLanguage.h" #include "FontLanguageListCache.h" #include "LayoutUtils.h" #include "HbFaceCache.h" @@ -746,9 +747,15 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t const FontLanguages& langList = FontLanguageListCache::getById(ctx->style.getLanguageListId()); if (langList.size() != 0) { - // TODO: use all languages in langList. - string lang = langList[0].getString(); - hb_buffer_set_language(buffer, hb_language_from_string(lang.c_str(), -1)); + const FontLanguage* hbLanguage = &langList[0]; + for (size_t i = 0; i < langList.size(); ++i) { + if (langList[i].supportsHbScript(script)) { + hbLanguage = &langList[i]; + break; + } + } + hb_buffer_set_language(buffer, + hb_language_from_string(hbLanguage->getString().c_str(), -1)); } hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart); if (ctx->paint.hyphenEdit.hasHyphen() && srunend > srunstart) { diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index 85d76afccb8..cf9b704efa2 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -16,7 +16,9 @@ #include +#include "FontLanguage.h" #include "FontTestUtils.h" +#include "ICUTestBase.h" #include "MinikinFontForTest.h" #include "UnicodeUtils.h" @@ -42,6 +44,8 @@ const char kColorEmojiFont[] = kTestFontDir "ColorEmojiFont.ttf"; const char kTextEmojiFont[] = kTestFontDir "TextEmojiFont.ttf"; const char kMixedEmojiFont[] = kTestFontDir "ColorTextMixedEmojiFont.ttf"; +typedef ICUTestBase FontCollectionItemizeTest; + // Utility function for calling itemize function. void itemize(FontCollection* collection, const char* str, FontStyle style, std::vector* result) { @@ -60,7 +64,7 @@ const std::string& getFontPath(const FontCollection::Run& run) { return ((MinikinFontForTest*)run.fakedFont.font)->fontPath(); } -TEST(FontCollectionItemizeTest, itemize_latin) { +TEST_F(FontCollectionItemizeTest, itemize_latin) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -130,7 +134,7 @@ TEST(FontCollectionItemizeTest, itemize_latin) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); } -TEST(FontCollectionItemizeTest, itemize_emoji) { +TEST_F(FontCollectionItemizeTest, itemize_emoji) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -191,7 +195,7 @@ TEST(FontCollectionItemizeTest, itemize_emoji) { EXPECT_FALSE(runs[1].fakedFont.fakery.isFakeItalic()); } -TEST(FontCollectionItemizeTest, itemize_non_latin) { +TEST_F(FontCollectionItemizeTest, itemize_non_latin) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -280,7 +284,7 @@ TEST(FontCollectionItemizeTest, itemize_non_latin) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); } -TEST(FontCollectionItemizeTest, itemize_mixed) { +TEST_F(FontCollectionItemizeTest, itemize_mixed) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -319,7 +323,7 @@ TEST(FontCollectionItemizeTest, itemize_mixed) { EXPECT_FALSE(runs[4].fakedFont.fakery.isFakeItalic()); } -TEST(FontCollectionItemizeTest, itemize_variationSelector) { +TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -458,7 +462,7 @@ TEST(FontCollectionItemizeTest, itemize_variationSelector) { EXPECT_EQ(kLatinFont, getFontPath(runs[0])); } -TEST(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { +TEST_F(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -583,7 +587,7 @@ TEST(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); } -TEST(FontCollectionItemizeTest, itemize_no_crash) { +TEST_F(FontCollectionItemizeTest, itemize_no_crash) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -607,7 +611,7 @@ TEST(FontCollectionItemizeTest, itemize_no_crash) { itemize(collection.get(), "U+FE00 U+302D U+E0100", FontStyle(), &runs); } -TEST(FontCollectionItemizeTest, itemize_fakery) { +TEST_F(FontCollectionItemizeTest, itemize_fakery) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -647,18 +651,18 @@ TEST(FontCollectionItemizeTest, itemize_fakery) { EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeItalic()); } -TEST(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { +TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { // kVSTestFont supports U+717D U+FE02 but doesn't support U+717D. // kVSTestFont should be selected for U+717D U+FE02 even if it does not support the base code // point. const std::string kVSTestFont = kTestFontDir "VarioationSelectorTest-Regular.ttf"; std::vector families; - FontFamily* family1 = new FontFamily(FontLanguage(), android::VARIANT_DEFAULT); + FontFamily* family1 = new FontFamily(android::VARIANT_DEFAULT); family1->addFont(new MinikinFontForTest(kLatinFont)); families.push_back(family1); - FontFamily* family2 = new FontFamily(FontLanguage(), android::VARIANT_DEFAULT); + FontFamily* family2 = new FontFamily(android::VARIANT_DEFAULT); family2->addFont(new MinikinFontForTest(kVSTestFont)); families.push_back(family2); @@ -676,7 +680,7 @@ TEST(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { family2->Unref(); } -TEST(FontCollectionItemizeTest, itemize_emojiSelection) { +TEST_F(FontCollectionItemizeTest, itemize_emojiSelection) { std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); std::vector runs; @@ -748,7 +752,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection) { EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); } -TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { +TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); std::vector runs; @@ -830,7 +834,7 @@ TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { EXPECT_EQ(kMixedEmojiFont, getFontPath(runs[0])); } -TEST(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { +TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); std::vector runs; diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index fc44e6c6369..ac7616fada3 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -17,74 +17,261 @@ #include #include + +#include + #include "FontLanguageListCache.h" +#include "ICUTestBase.h" #include "MinikinFontForTest.h" #include "MinikinInternal.h" namespace android { -TEST(FontLanguagesTest, basicTests) { +typedef ICUTestBase FontLanguagesTest; +typedef ICUTestBase FontLanguageTest; + +static FontLanguages createFontLanguages(const std::string& input) { + uint32_t langId = FontLanguageListCache::getId(input); + return FontLanguageListCache::getById(langId); +} + +static FontLanguage createFontLanguage(const std::string& input) { + uint32_t langId = FontLanguageListCache::getId(input); + return FontLanguageListCache::getById(langId)[0]; +} + +TEST_F(FontLanguageTest, basicTests) { + FontLanguage defaultLang; + FontLanguage emptyLang("", 0); + FontLanguage english = createFontLanguage("en"); + FontLanguage french = createFontLanguage("fr"); + FontLanguage und = createFontLanguage("und"); + FontLanguage undQaae = createFontLanguage("und-Qaae"); + + EXPECT_EQ(english, english); + EXPECT_EQ(french, french); + + EXPECT_TRUE(defaultLang != defaultLang); + EXPECT_TRUE(emptyLang != emptyLang); + EXPECT_TRUE(defaultLang != emptyLang); + EXPECT_TRUE(defaultLang != und); + EXPECT_TRUE(emptyLang != und); + EXPECT_TRUE(english != defaultLang); + EXPECT_TRUE(english != emptyLang); + EXPECT_TRUE(english != french); + EXPECT_TRUE(english != undQaae); + EXPECT_TRUE(und != undQaae); + EXPECT_TRUE(english != und); + + EXPECT_TRUE(defaultLang.isUnsupported()); + EXPECT_TRUE(emptyLang.isUnsupported()); + + EXPECT_FALSE(english.isUnsupported()); + EXPECT_FALSE(french.isUnsupported()); + EXPECT_FALSE(und.isUnsupported()); + EXPECT_FALSE(undQaae.isUnsupported()); +} + +TEST_F(FontLanguageTest, getStringTest) { + EXPECT_EQ("en-Latn", createFontLanguage("en").getString()); + EXPECT_EQ("en-Latn", createFontLanguage("en-Latn").getString()); + + // Capitalized language code or lowercased script should be normalized. + EXPECT_EQ("en-Latn", createFontLanguage("EN-LATN").getString()); + EXPECT_EQ("en-Latn", createFontLanguage("EN-latn").getString()); + EXPECT_EQ("en-Latn", createFontLanguage("en-latn").getString()); + + // Invalid script should be kept. + EXPECT_EQ("en-Xyzt", createFontLanguage("en-xyzt").getString()); + + EXPECT_EQ("en-Latn", createFontLanguage("en-Latn-US").getString()); + EXPECT_EQ("ja-Jpan", createFontLanguage("ja").getString()); + EXPECT_EQ("und", createFontLanguage("und").getString()); + EXPECT_EQ("und", createFontLanguage("UND").getString()); + EXPECT_EQ("und", createFontLanguage("Und").getString()); + EXPECT_EQ("und-Qaae", createFontLanguage("und-Qaae").getString()); + EXPECT_EQ("und-Qaae", createFontLanguage("Und-QAAE").getString()); + EXPECT_EQ("und-Qaae", createFontLanguage("Und-qaae").getString()); + + EXPECT_EQ("de-Latn", createFontLanguage("de-1901").getString()); + + // This is not a necessary desired behavior, just known behavior. + EXPECT_EQ("en-Latn", createFontLanguage("und-Abcdefgh").getString()); +} + +TEST_F(FontLanguageTest, ScriptEqualTest) { + EXPECT_TRUE(createFontLanguage("en").isEqualScript(createFontLanguage("en"))); + EXPECT_TRUE(createFontLanguage("en-Latn").isEqualScript(createFontLanguage("en"))); + EXPECT_TRUE(createFontLanguage("jp-Latn").isEqualScript(createFontLanguage("en-Latn"))); + EXPECT_TRUE(createFontLanguage("en-Jpan").isEqualScript(createFontLanguage("en-Jpan"))); + + EXPECT_FALSE(createFontLanguage("en-Jpan").isEqualScript(createFontLanguage("en-Hira"))); + EXPECT_FALSE(createFontLanguage("en-Jpan").isEqualScript(createFontLanguage("en-Hani"))); +} + +TEST_F(FontLanguageTest, ScriptMatchTest) { + const bool SUPPORTED = true; + const bool NOT_SUPPORTED = false; + + struct TestCase { + const std::string baseScript; + const std::string requestedScript; + bool isSupported; + } testCases[] = { + // Same scripts + { "en-Latn", "Latn", SUPPORTED }, + { "ja-Jpan", "Jpan", SUPPORTED }, + { "ja-Hira", "Hira", SUPPORTED }, + { "ja-Kana", "Kana", SUPPORTED }, + { "ja-Hrkt", "Hrkt", SUPPORTED }, + { "zh-Hans", "Hans", SUPPORTED }, + { "zh-Hant", "Hant", SUPPORTED }, + { "zh-Hani", "Hani", SUPPORTED }, + { "ko-Kore", "Kore", SUPPORTED }, + { "ko-Hang", "Hang", SUPPORTED }, + + // Japanese supports Hiragana, Katakanara, etc. + { "ja-Jpan", "Hira", SUPPORTED }, + { "ja-Jpan", "Kana", SUPPORTED }, + { "ja-Jpan", "Hrkt", SUPPORTED }, + { "ja-Hrkt", "Hira", SUPPORTED }, + { "ja-Hrkt", "Kana", SUPPORTED }, + + // Chinese supports Han. + { "zh-Hans", "Hani", SUPPORTED }, + { "zh-Hant", "Hani", SUPPORTED }, + + // Korean supports Hangul. + { "ko-Kore", "Hang", SUPPORTED }, + + // Different scripts + { "ja-Jpan", "Latn", NOT_SUPPORTED }, + { "en-Latn", "Jpan", NOT_SUPPORTED }, + { "ja-Jpan", "Hant", NOT_SUPPORTED }, + { "zh-Hant", "Jpan", NOT_SUPPORTED }, + { "ja-Jpan", "Hans", NOT_SUPPORTED }, + { "zh-Hans", "Jpan", NOT_SUPPORTED }, + { "ja-Jpan", "Kore", NOT_SUPPORTED }, + { "ko-Kore", "Jpan", NOT_SUPPORTED }, + { "zh-Hans", "Hant", NOT_SUPPORTED }, + { "zh-Hant", "Hans", NOT_SUPPORTED }, + { "zh-Hans", "Kore", NOT_SUPPORTED }, + { "ko-Kore", "Hans", NOT_SUPPORTED }, + { "zh-Hant", "Kore", NOT_SUPPORTED }, + { "ko-Kore", "Hant", NOT_SUPPORTED }, + + // Hiragana doesn't support Japanese, etc. + { "ja-Hira", "Jpan", NOT_SUPPORTED }, + { "ja-Kana", "Jpan", NOT_SUPPORTED }, + { "ja-Hrkt", "Jpan", NOT_SUPPORTED }, + { "ja-Hani", "Jpan", NOT_SUPPORTED }, + { "ja-Hira", "Hrkt", NOT_SUPPORTED }, + { "ja-Kana", "Hrkt", NOT_SUPPORTED }, + { "ja-Hani", "Hrkt", NOT_SUPPORTED }, + { "ja-Hani", "Hira", NOT_SUPPORTED }, + { "ja-Hani", "Kana", NOT_SUPPORTED }, + + // Kanji doesn't support Chinese, etc. + { "zh-Hani", "Hant", NOT_SUPPORTED }, + { "zh-Hani", "Hans", NOT_SUPPORTED }, + + // Hangul doesn't support Korean, etc. + { "ko-Hang", "Kore", NOT_SUPPORTED }, + { "ko-Hani", "Kore", NOT_SUPPORTED }, + { "ko-Hani", "Hang", NOT_SUPPORTED }, + { "ko-Hang", "Hani", NOT_SUPPORTED }, + }; + + for (auto testCase : testCases) { + hb_script_t script = hb_script_from_iso15924_tag( + HB_TAG(testCase.requestedScript[0], testCase.requestedScript[1], + testCase.requestedScript[2], testCase.requestedScript[3])); + if (testCase.isSupported) { + EXPECT_TRUE( + createFontLanguage(testCase.baseScript).supportsHbScript(script)) + << testCase.baseScript << " should support " << testCase.requestedScript; + } else { + EXPECT_FALSE( + createFontLanguage(testCase.baseScript).supportsHbScript(script)) + << testCase.baseScript << " shouldn't support " << testCase.requestedScript; + } + } +} + +TEST_F(FontLanguagesTest, basicTests) { FontLanguages emptyLangs; EXPECT_EQ(0u, emptyLangs.size()); - FontLanguage english("en", 2); - FontLanguages singletonLangs("en", 2); + FontLanguage english = createFontLanguage("en"); + FontLanguages singletonLangs = createFontLanguages("en"); EXPECT_EQ(1u, singletonLangs.size()); EXPECT_EQ(english, singletonLangs[0]); - FontLanguage french("fr", 2); - FontLanguages twoLangs("en,fr", 5); + FontLanguage french = createFontLanguage("fr"); + FontLanguages twoLangs = createFontLanguages("en,fr"); EXPECT_EQ(2u, twoLangs.size()); EXPECT_EQ(english, twoLangs[0]); EXPECT_EQ(french, twoLangs[1]); } -TEST(FontLanguagesTest, unsupportedLanguageTests) { - FontLanguage unsupportedLang("x-example", 9); +TEST_F(FontLanguagesTest, unsupportedLanguageTests) { + FontLanguage unsupportedLang = createFontLanguage("abcd"); ASSERT_TRUE(unsupportedLang.isUnsupported()); - FontLanguages oneUnsupported("x-example", 9); + FontLanguages oneUnsupported = createFontLanguages("abcd-example"); EXPECT_EQ(1u, oneUnsupported.size()); EXPECT_TRUE(oneUnsupported[0].isUnsupported()); - FontLanguages twoUnsupporteds("x-example,x-example", 19); + FontLanguages twoUnsupporteds = createFontLanguages("abcd-example,abcd-example"); EXPECT_EQ(1u, twoUnsupporteds.size()); EXPECT_TRUE(twoUnsupporteds[0].isUnsupported()); - FontLanguage english("en", 2); - FontLanguages firstUnsupported("x-example,en", 12); + FontLanguage english = createFontLanguage("en"); + FontLanguages firstUnsupported = createFontLanguages("abcd-example,en"); EXPECT_EQ(1u, firstUnsupported.size()); EXPECT_EQ(english, firstUnsupported[0]); - FontLanguages lastUnsupported("en,x-example", 12); + FontLanguages lastUnsupported = createFontLanguages("en,abcd-example"); EXPECT_EQ(1u, lastUnsupported.size()); EXPECT_EQ(english, lastUnsupported[0]); } -TEST(FontLanguagesTest, repeatedLanguageTests) { - FontLanguage english("en", 2); - FontLanguage englishInLatn("en-Latn", 2); +TEST_F(FontLanguagesTest, repeatedLanguageTests) { + FontLanguage english = createFontLanguage("en"); + FontLanguage french = createFontLanguage("fr"); + FontLanguage englishInLatn = createFontLanguage("en-Latn"); ASSERT_TRUE(english == englishInLatn); - FontLanguages langs("en,en-Latn", 10); + FontLanguages langs = createFontLanguages("en,en-Latn"); EXPECT_EQ(1u, langs.size()); EXPECT_EQ(english, langs[0]); + + // Country codes are ignored. + FontLanguages fr = createFontLanguages("fr,fr-CA,fr-FR"); + EXPECT_EQ(1u, fr.size()); + EXPECT_EQ(french, fr[0]); + + // The order should be kept. + langs = createFontLanguages("en,fr,en-Latn"); + EXPECT_EQ(2u, langs.size()); + EXPECT_EQ(english, langs[0]); + EXPECT_EQ(french, langs[1]); } -TEST(FontLanguagesTest, undEmojiTests) { - FontLanguage emoji("und-Qaae", 8); +TEST_F(FontLanguagesTest, undEmojiTests) { + FontLanguage emoji = createFontLanguage("und-Qaae"); EXPECT_TRUE(emoji.hasEmojiFlag()); - FontLanguage und("und", 3); + FontLanguage und = createFontLanguage("und"); EXPECT_FALSE(und.hasEmojiFlag()); EXPECT_FALSE(emoji == und); - FontLanguage undExample("und-example", 10); + FontLanguage undExample = createFontLanguage("und-example"); EXPECT_FALSE(undExample.hasEmojiFlag()); EXPECT_FALSE(emoji == undExample); } -TEST(FontLanguagesTest, registerLanguageListTest) { +TEST_F(FontLanguagesTest, registerLanguageListTest) { EXPECT_EQ(0UL, FontStyle::registerLanguageList("")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en")); EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); @@ -122,9 +309,10 @@ TEST(FontLanguagesTest, registerLanguageListTest) { // U+717D U+E0103 (VS20) const char kVsTestFont[] = kTestFontDir "VarioationSelectorTest-Regular.ttf"; -class FontFamilyTest : public testing::Test { +class FontFamilyTest : public ICUTestBase { public: virtual void SetUp() override { + ICUTestBase::SetUp(); if (access(kVsTestFont, R_OK) != 0) { FAIL() << "Unable to read " << kVsTestFont << ". " << "Please prepare the test data directory. " diff --git a/engine/src/flutter/tests/FontLanguageListCacheTest.cpp b/engine/src/flutter/tests/FontLanguageListCacheTest.cpp index 29757fedceb..f83988c1f50 100644 --- a/engine/src/flutter/tests/FontLanguageListCacheTest.cpp +++ b/engine/src/flutter/tests/FontLanguageListCacheTest.cpp @@ -17,11 +17,15 @@ #include #include + #include "FontLanguageListCache.h" +#include "ICUTestBase.h" namespace android { -TEST(FontLanguageListCacheTest, getId) { +typedef ICUTestBase FontLanguageListCacheTest; + +TEST_F(FontLanguageListCacheTest, getId) { EXPECT_EQ(0UL, FontLanguageListCache::getId("")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en")); EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); @@ -42,11 +46,15 @@ TEST(FontLanguageListCacheTest, getId) { FontLanguageListCache::getId("en,zh-Hant")); } -TEST(FontLanguageListCacheTest, getById) { - FontLanguage english("en", 2); - FontLanguage japanese("jp", 2); +TEST_F(FontLanguageListCacheTest, getById) { + uint32_t enLangId = FontLanguageListCache::getId("en"); + uint32_t jpLangId = FontLanguageListCache::getId("jp"); + FontLanguage english = FontLanguageListCache::getById(enLangId)[0]; + FontLanguage japanese = FontLanguageListCache::getById(jpLangId)[0]; - EXPECT_EQ(0UL, FontLanguageListCache::getById(0).size()); + FontLanguages defLangs = FontLanguageListCache::getById(0); + EXPECT_EQ(1UL, defLangs.size()); + EXPECT_TRUE(defLangs[0].isUnsupported()); FontLanguages langs = FontLanguageListCache::getById(FontLanguageListCache::getId("en")); ASSERT_EQ(1UL, langs.size()); diff --git a/engine/src/flutter/tests/FontTestUtils.cpp b/engine/src/flutter/tests/FontTestUtils.cpp index 8e1d184adcc..98dab5121b0 100644 --- a/engine/src/flutter/tests/FontTestUtils.cpp +++ b/engine/src/flutter/tests/FontTestUtils.cpp @@ -20,6 +20,8 @@ #include #include + +#include "FontLanguage.h" #include "MinikinFontForTest.h" std::unique_ptr getFontCollection( @@ -44,9 +46,10 @@ std::unique_ptr getFontCollection( } xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); + uint32_t langId = android::FontStyle::registerLanguageList( + std::string((const char*)lang, xmlStrlen(lang))); - android::FontFamily* family = new android::FontFamily( - android::FontLanguage((const char*)lang, xmlStrlen(lang)), variant); + android::FontFamily* family = new android::FontFamily(langId, variant); for (xmlNode* fontNode = familyNode->children; fontNode; fontNode = fontNode->next) { if (xmlStrcmp(fontNode->name, (const xmlChar*)"font") != 0) { diff --git a/engine/src/flutter/tests/ICUTestBase.h b/engine/src/flutter/tests/ICUTestBase.h new file mode 100644 index 00000000000..3bcfaf36945 --- /dev/null +++ b/engine/src/flutter/tests/ICUTestBase.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2015 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_TEST_ICU_TEST_BASE_H +#define MINIKIN_TEST_ICU_TEST_BASE_H + +#include +#include +#include + +// low level file access for mapping ICU data +#include +#include +#include + +class ICUTestBase : public testing::Test { +protected: + virtual void SetUp() override { + const char* fn = "/system/usr/icu/" U_ICUDATA_NAME ".dat"; + int fd = open(fn, O_RDONLY); + ASSERT_NE(-1, fd); + struct stat sb; + ASSERT_EQ(0, fstat(fd, &sb)); + void* data = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0); + + UErrorCode errorCode = U_ZERO_ERROR; + udata_setCommonData(data, &errorCode); + ASSERT_TRUE(U_SUCCESS(errorCode)); + u_init(&errorCode); + ASSERT_TRUE(U_SUCCESS(errorCode)); + } + + virtual void TearDown() override { + u_cleanup(); + } +}; + + +#endif // MINIKIN_TEST_ICU_TEST_BASE_H From 9d30380ce99c14af63f3b5ece14603ea0125d762 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 22 Dec 2015 13:22:12 +0900 Subject: [PATCH 136/364] Replace Qaae script with Zsye The emoji variant script "Zsye" is registered in ISO 15924. Bug: 26226285 Change-Id: Ibc2bc740d57c48f99b6f66b1ad7595bfa8c3cff4 --- engine/src/flutter/libs/minikin/FontLanguage.cpp | 2 +- engine/src/flutter/tests/FontFamilyTest.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontLanguage.cpp b/engine/src/flutter/libs/minikin/FontLanguage.cpp index 3c12e06c6f1..43190d7a7d2 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguage.cpp @@ -87,7 +87,7 @@ uint8_t FontLanguage::scriptToSubScriptBits(uint32_t script) { case SCRIPT_TAG('K', 'o', 'r', 'e'): subScriptBits = kHanFlag | kHangulFlag; break; - case SCRIPT_TAG('Q', 'a', 'a', 'e'): + case SCRIPT_TAG('Z', 's', 'y', 'e'): subScriptBits = kEmojiFlag; break; } diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index ac7616fada3..5b4b28b3161 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -46,7 +46,7 @@ TEST_F(FontLanguageTest, basicTests) { FontLanguage english = createFontLanguage("en"); FontLanguage french = createFontLanguage("fr"); FontLanguage und = createFontLanguage("und"); - FontLanguage undQaae = createFontLanguage("und-Qaae"); + FontLanguage undZsye = createFontLanguage("und-Zsye"); EXPECT_EQ(english, english); EXPECT_EQ(french, french); @@ -59,8 +59,8 @@ TEST_F(FontLanguageTest, basicTests) { EXPECT_TRUE(english != defaultLang); EXPECT_TRUE(english != emptyLang); EXPECT_TRUE(english != french); - EXPECT_TRUE(english != undQaae); - EXPECT_TRUE(und != undQaae); + EXPECT_TRUE(english != undZsye); + EXPECT_TRUE(und != undZsye); EXPECT_TRUE(english != und); EXPECT_TRUE(defaultLang.isUnsupported()); @@ -69,7 +69,7 @@ TEST_F(FontLanguageTest, basicTests) { EXPECT_FALSE(english.isUnsupported()); EXPECT_FALSE(french.isUnsupported()); EXPECT_FALSE(und.isUnsupported()); - EXPECT_FALSE(undQaae.isUnsupported()); + EXPECT_FALSE(undZsye.isUnsupported()); } TEST_F(FontLanguageTest, getStringTest) { @@ -89,9 +89,9 @@ TEST_F(FontLanguageTest, getStringTest) { EXPECT_EQ("und", createFontLanguage("und").getString()); EXPECT_EQ("und", createFontLanguage("UND").getString()); EXPECT_EQ("und", createFontLanguage("Und").getString()); - EXPECT_EQ("und-Qaae", createFontLanguage("und-Qaae").getString()); - EXPECT_EQ("und-Qaae", createFontLanguage("Und-QAAE").getString()); - EXPECT_EQ("und-Qaae", createFontLanguage("Und-qaae").getString()); + EXPECT_EQ("und-Zsye", createFontLanguage("und-Zsye").getString()); + EXPECT_EQ("und-Zsye", createFontLanguage("Und-ZSYE").getString()); + EXPECT_EQ("und-Zsye", createFontLanguage("Und-zsye").getString()); EXPECT_EQ("de-Latn", createFontLanguage("de-1901").getString()); @@ -259,7 +259,7 @@ TEST_F(FontLanguagesTest, repeatedLanguageTests) { } TEST_F(FontLanguagesTest, undEmojiTests) { - FontLanguage emoji = createFontLanguage("und-Qaae"); + FontLanguage emoji = createFontLanguage("und-Zsye"); EXPECT_TRUE(emoji.hasEmojiFlag()); FontLanguage und = createFontLanguage("und"); From 147ce0acb9ccb2c7594e47512ac0f5d68eafb580 Mon Sep 17 00:00:00 2001 From: Dan Austin Date: Tue, 5 Jan 2016 17:36:31 -0800 Subject: [PATCH 137/364] Enable integer sanitization in libminikin. Enable signed and unsigned integer sanitization in libminikin. Bug: 25884483 Change-Id: I53abf6affea8e2bb3a5abd381a9f19003a306b36 --- engine/src/flutter/libs/minikin/Android.mk | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index c3e70db2675..e51e4668f93 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -50,7 +50,8 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) - +LOCAL_CLANG := true +LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) @@ -61,6 +62,8 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) +LOCAL_CLANG := true +LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow include $(BUILD_STATIC_LIBRARY) @@ -73,6 +76,8 @@ LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_SHARED_LIBRARIES := liblog libicuuc-host +LOCAL_CLANG := true +LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow LOCAL_SRC_FILES := Hyphenator.cpp From 5f7e7e239e73a3d3ec796660d3f10afd435c0858 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 5 Jan 2016 15:20:39 +0900 Subject: [PATCH 138/364] Fix race condition in Paint.hasGlyph() The caller of FontFamily::hasVariationSelector needs to acquire the lock before calling it, but FontCollection::hasVariationSelector didn't acquire the lock. This caused a race condition. This CL fixes this race condition. Also, it turned out that assertMinikinLocked didn't assert even on eng or userdebug device. This CL enables assertion on eng and userdebug device since this assertion must be treated as bug. BUG: 26323806 Change-Id: I9c4b1e1f09c6793e387fbdb8bb654cc0a13c65d5 --- engine/src/flutter/libs/minikin/Android.mk | 13 ++++++++++--- engine/src/flutter/libs/minikin/FontCollection.cpp | 1 + engine/src/flutter/libs/minikin/MinikinInternal.cpp | 4 +++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 4c945a60c9c..b2e1dc82936 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -47,11 +47,18 @@ minikin_shared_libraries := \ libicuuc \ libutils +ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT))) +# Enable race detection on eng and userdebug build. +enable_race_detection := -DENABLE_RACE_DETECTION +else +enable_race_detection := +endif + LOCAL_MODULE := libminikin LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra +LOCAL_CPPFLAGS += -Werror -Wall -Wextra $(enable_race_detection) LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) include $(BUILD_SHARED_LIBRARY) @@ -63,7 +70,7 @@ LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra +LOCAL_CPPFLAGS += -Werror -Wall -Wextra $(enable_race_detection) LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) include $(BUILD_STATIC_LIBRARY) @@ -76,7 +83,7 @@ LOCAL_MODULE := libminikin_host LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra +LOCAL_CPPFLAGS += -Werror -Wall -Wextra $(enable_race_detection) LOCAL_SHARED_LIBRARIES := liblog libicuuc-host LOCAL_SRC_FILES := Hyphenator.cpp diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index bba2ef95359..529b5c03a34 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -223,6 +223,7 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, // Currently mRanges can not be used here since it isn't aware of the variation sequence. // TODO: Use mRanges for narrowing down the search range. for (size_t i = 0; i < mFamilies.size(); i++) { + AutoMutex _l(gMinikinLock); if (mFamilies[i]->hasVariationSelector(baseCodepoint, variationSelector)) { return true; } diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index 5a21ef9862c..c2aa01ac198 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -25,7 +25,9 @@ namespace android { Mutex gMinikinLock; void assertMinikinLocked() { - LOG_FATAL_IF(gMinikinLock.tryLock() == 0); +#ifdef ENABLE_RACE_DETECTION + LOG_ALWAYS_FATAL_IF(gMinikinLock.tryLock() == 0); +#endif } } From 02345a5e8f47faeed80e62730874194575a0dc46 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 6 Jan 2016 22:49:33 +0900 Subject: [PATCH 139/364] Fix lock assertion failures in unit test. The assertion for the lock state has now activated by I9c4b1e1f09c6793e387fbdb8bb654cc0a13c65d5. This CL fixes the assertion failure in the unit tests by acquiring lock before calling the functions. Change-Id: I6a6afefb4de01e8610c2abfe6c779afa9442cc67 --- engine/src/flutter/tests/FontCollectionItemizeTest.cpp | 4 ++++ engine/src/flutter/tests/FontFamilyTest.cpp | 2 ++ engine/src/flutter/tests/FontLanguageListCacheTest.cpp | 6 +++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index cf9b704efa2..57409a5e62c 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -20,12 +20,15 @@ #include "FontTestUtils.h" #include "ICUTestBase.h" #include "MinikinFontForTest.h" +#include "MinikinInternal.h" #include "UnicodeUtils.h" +using android::AutoMutex; using android::FontCollection; using android::FontFamily; using android::FontLanguage; using android::FontStyle; +using android::gMinikinLock; const char kItemizeFontXml[] = kTestFontDir "itemize.xml"; const char kEmojiFont[] = kTestFontDir "Emoji.ttf"; @@ -55,6 +58,7 @@ void itemize(FontCollection* collection, const char* str, FontStyle style, result->clear(); ParseUnicode(buf, BUF_SIZE, str, &len, NULL); + AutoMutex _l(gMinikinLock); collection->itemize(buf, len, style, result); } diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index 5b4b28b3161..6b32689081e 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -31,11 +31,13 @@ typedef ICUTestBase FontLanguagesTest; typedef ICUTestBase FontLanguageTest; static FontLanguages createFontLanguages(const std::string& input) { + AutoMutex _l(gMinikinLock); uint32_t langId = FontLanguageListCache::getId(input); return FontLanguageListCache::getById(langId); } static FontLanguage createFontLanguage(const std::string& input) { + AutoMutex _l(gMinikinLock); uint32_t langId = FontLanguageListCache::getId(input); return FontLanguageListCache::getById(langId)[0]; } diff --git a/engine/src/flutter/tests/FontLanguageListCacheTest.cpp b/engine/src/flutter/tests/FontLanguageListCacheTest.cpp index f83988c1f50..fbbd9376f04 100644 --- a/engine/src/flutter/tests/FontLanguageListCacheTest.cpp +++ b/engine/src/flutter/tests/FontLanguageListCacheTest.cpp @@ -20,17 +20,20 @@ #include "FontLanguageListCache.h" #include "ICUTestBase.h" +#include "MinikinInternal.h" namespace android { typedef ICUTestBase FontLanguageListCacheTest; TEST_F(FontLanguageListCacheTest, getId) { - EXPECT_EQ(0UL, FontLanguageListCache::getId("")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en")); EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en,zh-Hans")); + AutoMutex _l(gMinikinLock); + EXPECT_EQ(0UL, FontLanguageListCache::getId("")); + EXPECT_EQ(FontLanguageListCache::getId("en"), FontLanguageListCache::getId("en")); EXPECT_NE(FontLanguageListCache::getId("en"), FontLanguageListCache::getId("jp")); @@ -47,6 +50,7 @@ TEST_F(FontLanguageListCacheTest, getId) { } TEST_F(FontLanguageListCacheTest, getById) { + AutoMutex _l(gMinikinLock); uint32_t enLangId = FontLanguageListCache::getId("en"); uint32_t jpLangId = FontLanguageListCache::getId("jp"); FontLanguage english = FontLanguageListCache::getById(enLangId)[0]; From 2ffc28610290d221109105ba17969db83b317ca1 Mon Sep 17 00:00:00 2001 From: Dan Austin Date: Wed, 6 Jan 2016 18:31:38 +0000 Subject: [PATCH 140/364] Revert "Enable integer sanitization in libminikin." This reverts commit 147ce0acb9ccb2c7594e47512ac0f5d68eafb580. Change-Id: Iecd1f61a5fdf5955d871a920cb243553857d46ff --- engine/src/flutter/libs/minikin/Android.mk | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index e51e4668f93..c3e70db2675 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -50,8 +50,7 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) -LOCAL_CLANG := true -LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow + include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) @@ -62,8 +61,6 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) -LOCAL_CLANG := true -LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow include $(BUILD_STATIC_LIBRARY) @@ -76,8 +73,6 @@ LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_SHARED_LIBRARIES := liblog libicuuc-host -LOCAL_CLANG := true -LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow LOCAL_SRC_FILES := Hyphenator.cpp From da13d5e835bf4657246e2410dcf29c0b4a61887b Mon Sep 17 00:00:00 2001 From: Dan Austin Date: Wed, 6 Jan 2016 12:30:12 -0800 Subject: [PATCH 141/364] Enable integer sanitization in libminikin Enable signed and unsigned integer sanitization in libminikin. Bug: 25884483 Change-Id: I98905827174d16138d20bb443fe2e1d7228ea1a3 --- engine/src/flutter/libs/minikin/Android.mk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index c3e70db2675..428f49b4952 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -50,6 +50,8 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) +LOCAL_CLANG := true +LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow include $(BUILD_SHARED_LIBRARY) @@ -61,6 +63,8 @@ LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) +LOCAL_CLANG := true +LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow include $(BUILD_STATIC_LIBRARY) From 251f4772fb6996b5b8555fa94dd67f97a0377650 Mon Sep 17 00:00:00 2001 From: Andreas Gampe Date: Wed, 6 Jan 2016 20:28:52 -0800 Subject: [PATCH 142/364] Minikin: Disable sanitizer on x86 Disable unsigned-integer-overflow sanitizer on x86, as it crashes. Bug: 25884483 Bug: 26432628 Change-Id: Ia658ed56a6c81660a36edf71f7116118056aa917 --- engine/src/flutter/libs/minikin/Android.mk | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 428f49b4952..f91a4a80d3d 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -51,7 +51,11 @@ LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) LOCAL_CLANG := true -LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow +LOCAL_SANITIZE := signed-integer-overflow +# b/26432628. +ifeq ($(filter x86%,$(TARGET_ARCH)),) + LOCAL_SANITIZE += unsigned-integer-overflow +endif include $(BUILD_SHARED_LIBRARY) @@ -64,7 +68,11 @@ LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) LOCAL_CLANG := true -LOCAL_SANITIZE := signed-integer-overflow unsigned-integer-overflow +LOCAL_SANITIZE := signed-integer-overflow +# b/26432628. +ifeq ($(filter x86%,$(TARGET_ARCH)),) + LOCAL_SANITIZE += unsigned-integer-overflow +endif include $(BUILD_STATIC_LIBRARY) From 116708d9a3c237490fc6642a38598bf83c8e3d58 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 6 Jan 2016 14:31:23 -0800 Subject: [PATCH 143/364] Reject fonts with invalid ranges in cmap A corrupt or malicious font may have a negative size in its cmap range, which in turn could lead to memory corruption. This patch detects the case and rejects the font, and also includes an assertion in the sparse bit set implementation if we missed any such case. External issue: https://code.google.com/p/android/issues/detail?id=192618 Bug: 26413177 Change-Id: Icc0c80e4ef389abba0964495b89aa0fae3e9f4b2 --- .../src/flutter/libs/minikin/CmapCoverage.cpp | 41 +++++++++++-------- .../src/flutter/libs/minikin/SparseBitSet.cpp | 2 + 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/engine/src/flutter/libs/minikin/CmapCoverage.cpp b/engine/src/flutter/libs/minikin/CmapCoverage.cpp index 64310006fd7..9f3447e62af 100644 --- a/engine/src/flutter/libs/minikin/CmapCoverage.cpp +++ b/engine/src/flutter/libs/minikin/CmapCoverage.cpp @@ -49,7 +49,7 @@ static void addRange(vector &coverage, uint32_t start, uint32_t end) { } } -// Get the coverage information out of a Format 12 subtable, storing it in the coverage vector +// Get the coverage information out of a Format 4 subtable, storing it in the coverage vector static bool getCoverageFormat4(vector& coverage, const uint8_t* data, size_t size) { const size_t kSegCountOffset = 6; const size_t kEndCountOffset = 14; @@ -63,29 +63,33 @@ static bool getCoverageFormat4(vector& coverage, const uint8_t* data, return false; } for (size_t i = 0; i < segCount; i++) { - int end = readU16(data, kEndCountOffset + 2 * i); - int start = readU16(data, kHeaderSize + 2 * (segCount + i)); - int rangeOffset = readU16(data, kHeaderSize + 2 * (3 * segCount + i)); + uint32_t end = readU16(data, kEndCountOffset + 2 * i); + uint32_t start = readU16(data, kHeaderSize + 2 * (segCount + i)); + if (end < start) { + // invalid segment range: size must be positive + return false; + } + uint32_t rangeOffset = readU16(data, kHeaderSize + 2 * (3 * segCount + i)); if (rangeOffset == 0) { - int delta = readU16(data, kHeaderSize + 2 * (2 * segCount + i)); + uint32_t delta = readU16(data, kHeaderSize + 2 * (2 * segCount + i)); if (((end + delta) & 0xffff) > end - start) { addRange(coverage, start, end + 1); } else { - for (int j = start; j < end + 1; j++) { + for (uint32_t j = start; j < end + 1; j++) { if (((j + delta) & 0xffff) != 0) { addRange(coverage, j, j + 1); } } } } else { - for (int j = start; j < end + 1; j++) { + for (uint32_t j = start; j < end + 1; j++) { uint32_t actualRangeOffset = kHeaderSize + 6 * segCount + rangeOffset + (i + j - start) * 2; if (actualRangeOffset + 2 > size) { // invalid rangeOffset is considered a "warning" by OpenType Sanitizer continue; } - int glyphId = readU16(data, actualRangeOffset); + uint32_t glyphId = readU16(data, actualRangeOffset); if (glyphId != 0) { addRange(coverage, j, j + 1); } @@ -115,6 +119,10 @@ static bool getCoverageFormat12(vector& coverage, const uint8_t* data, uint32_t groupOffset = kFirstGroupOffset + i * kGroupSize; uint32_t start = readU32(data, groupOffset + kStartCharCodeOffset); uint32_t end = readU32(data, groupOffset + kEndCharCodeOffset); + if (end < start) { + // invalid group range: size must be positive + return false; + } addRange(coverage, start, end + 1); // file is inclusive, vector is exclusive } return true; @@ -128,18 +136,19 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, const size_t kPlatformIdOffset = 0; const size_t kEncodingIdOffset = 2; const size_t kOffsetOffset = 4; - const int kMicrosoftPlatformId = 3; - const int kUnicodeBmpEncodingId = 1; - const int kUnicodeUcs4EncodingId = 10; + const uint16_t kMicrosoftPlatformId = 3; + const uint16_t kUnicodeBmpEncodingId = 1; + const uint16_t kUnicodeUcs4EncodingId = 10; + const uint32_t kNoTable = UINT32_MAX; if (kHeaderSize > cmap_size) { return false; } - int numTables = readU16(cmap_data, kNumTablesOffset); + uint32_t numTables = readU16(cmap_data, kNumTablesOffset); if (kHeaderSize + numTables * kTableSize > cmap_size) { return false; } - int bestTable = -1; - for (int i = 0; i < numTables; i++) { + uint32_t bestTable = kNoTable; + for (uint32_t i = 0; i < numTables; i++) { uint16_t platformId = readU16(cmap_data, kHeaderSize + i * kTableSize + kPlatformIdOffset); uint16_t encodingId = readU16(cmap_data, kHeaderSize + i * kTableSize + kEncodingIdOffset); if (platformId == kMicrosoftPlatformId && encodingId == kUnicodeUcs4EncodingId) { @@ -152,11 +161,11 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, #ifdef VERBOSE_DEBUG ALOGD("best table = %d\n", bestTable); #endif - if (bestTable < 0) { + if (bestTable == kNoTable) { return false; } uint32_t offset = readU32(cmap_data, kHeaderSize + bestTable * kTableSize + kOffsetOffset); - if (offset + 2 > cmap_size) { + if (offset > cmap_size - 2) { return false; } uint16_t format = readU16(cmap_data, offset); diff --git a/engine/src/flutter/libs/minikin/SparseBitSet.cpp b/engine/src/flutter/libs/minikin/SparseBitSet.cpp index 9d1fd308bc5..de0791445cd 100644 --- a/engine/src/flutter/libs/minikin/SparseBitSet.cpp +++ b/engine/src/flutter/libs/minikin/SparseBitSet.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include #include @@ -71,6 +72,7 @@ void SparseBitSet::initFromRanges(const uint32_t* ranges, size_t nRanges) { for (size_t i = 0; i < nRanges; i++) { uint32_t start = ranges[i * 2]; uint32_t end = ranges[i * 2 + 1]; + LOG_ALWAYS_FATAL_IF(end < start); // make sure range size is nonnegative uint32_t startPage = start >> kLogValuesPerPage; uint32_t endPage = (end - 1) >> kLogValuesPerPage; if (startPage >= nonzeroPageEnd) { From f5d2fa97bbdbf5075e293fb641cd2e5dbaa29cfa Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 6 Jan 2016 14:31:23 -0800 Subject: [PATCH 144/364] Reject fonts with invalid ranges in cmap A corrupt or malicious font may have a negative size in its cmap range, which in turn could lead to memory corruption. This patch detects the case and rejects the font, and also includes an assertion in the sparse bit set implementation if we missed any such case. External issue: https://code.google.com/p/android/issues/detail?id=192618 Bug: 26413177 Change-Id: Icc0c80e4ef389abba0964495b89aa0fae3e9f4b2 --- .../src/flutter/libs/minikin/CmapCoverage.cpp | 41 +++++++++++-------- .../src/flutter/libs/minikin/SparseBitSet.cpp | 2 + 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/engine/src/flutter/libs/minikin/CmapCoverage.cpp b/engine/src/flutter/libs/minikin/CmapCoverage.cpp index 8be45d173c5..4c9643a1d4a 100644 --- a/engine/src/flutter/libs/minikin/CmapCoverage.cpp +++ b/engine/src/flutter/libs/minikin/CmapCoverage.cpp @@ -50,7 +50,7 @@ static void addRange(vector &coverage, uint32_t start, uint32_t end) { } } -// Get the coverage information out of a Format 12 subtable, storing it in the coverage vector +// Get the coverage information out of a Format 4 subtable, storing it in the coverage vector static bool getCoverageFormat4(vector& coverage, const uint8_t* data, size_t size) { const size_t kSegCountOffset = 6; const size_t kEndCountOffset = 14; @@ -64,28 +64,32 @@ static bool getCoverageFormat4(vector& coverage, const uint8_t* data, return false; } for (size_t i = 0; i < segCount; i++) { - int end = readU16(data, kEndCountOffset + 2 * i); - int start = readU16(data, kHeaderSize + 2 * (segCount + i)); - int rangeOffset = readU16(data, kHeaderSize + 2 * (3 * segCount + i)); + uint32_t end = readU16(data, kEndCountOffset + 2 * i); + uint32_t start = readU16(data, kHeaderSize + 2 * (segCount + i)); + if (end < start) { + // invalid segment range: size must be positive + return false; + } + uint32_t rangeOffset = readU16(data, kHeaderSize + 2 * (3 * segCount + i)); if (rangeOffset == 0) { - int delta = readU16(data, kHeaderSize + 2 * (2 * segCount + i)); + uint32_t delta = readU16(data, kHeaderSize + 2 * (2 * segCount + i)); if (((end + delta) & 0xffff) > end - start) { addRange(coverage, start, end + 1); } else { - for (int j = start; j < end + 1; j++) { + for (uint32_t j = start; j < end + 1; j++) { if (((j + delta) & 0xffff) != 0) { addRange(coverage, j, j + 1); } } } } else { - for (int j = start; j < end + 1; j++) { + for (uint32_t j = start; j < end + 1; j++) { uint32_t actualRangeOffset = kHeaderSize + 6 * segCount + rangeOffset + (i + j - start) * 2; if (actualRangeOffset + 2 > size) { return false; } - int glyphId = readU16(data, actualRangeOffset); + uint32_t glyphId = readU16(data, actualRangeOffset); if (glyphId != 0) { addRange(coverage, j, j + 1); } @@ -115,6 +119,10 @@ static bool getCoverageFormat12(vector& coverage, const uint8_t* data, uint32_t groupOffset = kFirstGroupOffset + i * kGroupSize; uint32_t start = readU32(data, groupOffset + kStartCharCodeOffset); uint32_t end = readU32(data, groupOffset + kEndCharCodeOffset); + if (end < start) { + // invalid group range: size must be positive + return false; + } addRange(coverage, start, end + 1); // file is inclusive, vector is exclusive } return true; @@ -128,18 +136,19 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, const size_t kPlatformIdOffset = 0; const size_t kEncodingIdOffset = 2; const size_t kOffsetOffset = 4; - const int kMicrosoftPlatformId = 3; - const int kUnicodeBmpEncodingId = 1; - const int kUnicodeUcs4EncodingId = 10; + const uint16_t kMicrosoftPlatformId = 3; + const uint16_t kUnicodeBmpEncodingId = 1; + const uint16_t kUnicodeUcs4EncodingId = 10; + const uint32_t kNoTable = UINT32_MAX; if (kHeaderSize > cmap_size) { return false; } - int numTables = readU16(cmap_data, kNumTablesOffset); + uint32_t numTables = readU16(cmap_data, kNumTablesOffset); if (kHeaderSize + numTables * kTableSize > cmap_size) { return false; } - int bestTable = -1; - for (int i = 0; i < numTables; i++) { + uint32_t bestTable = kNoTable; + for (uint32_t i = 0; i < numTables; i++) { uint16_t platformId = readU16(cmap_data, kHeaderSize + i * kTableSize + kPlatformIdOffset); uint16_t encodingId = readU16(cmap_data, kHeaderSize + i * kTableSize + kEncodingIdOffset); if (platformId == kMicrosoftPlatformId && encodingId == kUnicodeUcs4EncodingId) { @@ -152,11 +161,11 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, #ifdef PRINTF_DEBUG printf("best table = %d\n", bestTable); #endif - if (bestTable < 0) { + if (bestTable == kNoTable) { return false; } uint32_t offset = readU32(cmap_data, kHeaderSize + bestTable * kTableSize + kOffsetOffset); - if (offset + 2 > cmap_size) { + if (offset > cmap_size - 2) { return false; } uint16_t format = readU16(cmap_data, offset); diff --git a/engine/src/flutter/libs/minikin/SparseBitSet.cpp b/engine/src/flutter/libs/minikin/SparseBitSet.cpp index 7acb7ba345b..2265ff2bb2a 100644 --- a/engine/src/flutter/libs/minikin/SparseBitSet.cpp +++ b/engine/src/flutter/libs/minikin/SparseBitSet.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include #include @@ -71,6 +72,7 @@ void SparseBitSet::initFromRanges(const uint32_t* ranges, size_t nRanges) { for (size_t i = 0; i < nRanges; i++) { uint32_t start = ranges[i * 2]; uint32_t end = ranges[i * 2 + 1]; + LOG_ALWAYS_FATAL_IF(end < start); // make sure range size is nonnegative uint32_t startPage = start >> kLogValuesPerPage; uint32_t endPage = (end - 1) >> kLogValuesPerPage; if (startPage >= nonzeroPageEnd) { From 4760a9f19038820734f31cc9e51b0ae5352b185e Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 29 Oct 2015 14:06:07 -0700 Subject: [PATCH 145/364] Tailor grapheme boundaries so sequence emoji are one grapheme Make it so it's not possible to position the cursor inside an emoji formed by a sequence including zero-width joiners. Bug: 25368653 Change-Id: I67ec0874cd1505f3c82ab91492ffc3d39a52fae6 --- .../flutter/libs/minikin/GraphemeBreak.cpp | 26 +++++++++++++++++++ .../src/flutter/tests/GraphemeBreakTests.cpp | 15 +++++++++++ 2 files changed, 41 insertions(+) diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index eca74b178ce..7865d1d0458 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -64,6 +64,19 @@ bool isPureKiller(uint32_t c) { || c == 0xA953 || c == 0xABED || c == 0x11134 || c == 0x112EA || c == 0x1172B); } +// Returns true if the character appears before or after zwj in a zwj emoji sequence. See +// http://www.unicode.org/emoji/charts/emoji-zwj-sequences.html +bool isZwjEmoji(uint32_t c) { + return (c == 0x2764 // HEAVY BLACK HEART + || c == 0x1F468 // MAN + || c == 0x1F469 // WOMAN + || c == 0x1F48B // KISS MARK + || c == 0x1F466 // BOY + || c == 0x1F467 // GIRL + || c == 0x1F441 // EYE + || c == 0x1F5E8); // LEFT SPEECH BUBBLE +} + bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t count, size_t offset) { // This implementation closely follows Unicode Standard Annex #29 on @@ -139,6 +152,19 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co && u_getIntPropertyValue(c2, UCHAR_GENERAL_CATEGORY) == U_OTHER_LETTER) { return false; } + // Tailoring: make emoji sequences with ZWJ a single grapheme cluster + if (c1 == 0x200D && isZwjEmoji(c2) && offset_back > start) { + // look at character before ZWJ to see that both can participate in an emoji zwj sequence + uint32_t c0 = 0; + U16_PREV(buf, start, offset_back, c0); + if (c0 == 0xFE0F && offset_back > start) { + // skip over emoji variation selector + U16_PREV(buf, start, offset_back, c0); + } + if (isZwjEmoji(c0)) { + return false; + } + } // Rule GB10, Any ÷ Any return true; } diff --git a/engine/src/flutter/tests/GraphemeBreakTests.cpp b/engine/src/flutter/tests/GraphemeBreakTests.cpp index 6eda4da9fdb..d6746bc2b09 100644 --- a/engine/src/flutter/tests/GraphemeBreakTests.cpp +++ b/engine/src/flutter/tests/GraphemeBreakTests.cpp @@ -119,6 +119,21 @@ TEST(GraphemeBreak, tailoring) { EXPECT_FALSE(IsBreak("U+0915 U+094D | U+0915")); // Devanagari ka+virama+ka EXPECT_FALSE(IsBreak("U+0E01 | U+0E3A U+0E01")); // thai phinthu = pure killer EXPECT_TRUE(IsBreak("U+0E01 U+0E3A | U+0E01")); // thai phinthu = pure killer + + // suppress grapheme breaks in zwj emoji sequences, see + // http://www.unicode.org/emoji/charts/emoji-zwj-sequences.html + EXPECT_FALSE(IsBreak("U+1F469 U+200D | U+2764 U+FE0F U+200D U+1F48B U+200D U+1F468")); + EXPECT_FALSE(IsBreak("U+1F469 U+200D U+2764 U+FE0F U+200D | U+1F48B U+200D U+1F468")); + EXPECT_FALSE(IsBreak("U+1F469 U+200D U+2764 U+FE0F U+200D U+1F48B U+200D | U+1F468")); + EXPECT_FALSE(IsBreak("U+1F468 U+200D | U+1F469 U+200D U+1F466")); + EXPECT_FALSE(IsBreak("U+1F468 U+200D U+1F469 U+200D | U+1F466")); + EXPECT_FALSE(IsBreak("U+1F469 U+200D | U+1F469 U+200D U+1F467 U+200D U+1F466")); + EXPECT_FALSE(IsBreak("U+1F469 U+200D U+1F469 U+200D | U+1F467 U+200D U+1F466")); + EXPECT_FALSE(IsBreak("U+1F469 U+200D U+1F469 U+200D U+1F467 U+200D | U+1F466")); + EXPECT_FALSE(IsBreak("U+1F441 U+200D | U+1F5E8")); + + // ARABIC LETTER BEH + ZWJ + heart, not a zwj emoji sequence, so we preserve the break + EXPECT_TRUE(IsBreak("U+0628 U+200D | U+2764")); } TEST(GraphemeBreak, offsets) { From c4e24421ecb8b4532bde4e759625107367cd60e3 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 29 Oct 2015 14:06:07 -0700 Subject: [PATCH 146/364] Tailor grapheme boundaries so sequence emoji are one grapheme - DO NOT MERGE Make it so it's not possible to position the cursor inside an emoji formed by a sequence including zero-width joiners. Bug: 25368653 Change-Id: I67ec0874cd1505f3c82ab91492ffc3d39a52fae6 --- .../flutter/libs/minikin/GraphemeBreak.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index f8f386c0de9..56d5b238d37 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -22,6 +22,19 @@ namespace android { +// Returns true if the character appears before or after zwj in a zwj emoji sequence. See +// http://www.unicode.org/emoji/charts/emoji-zwj-sequences.html +bool isZwjEmoji(uint32_t c) { + return (c == 0x2764 // HEAVY BLACK HEART + || c == 0x1F468 // MAN + || c == 0x1F469 // WOMAN + || c == 0x1F48B // KISS MARK + || c == 0x1F466 // BOY + || c == 0x1F467 // GIRL + || c == 0x1F441 // EYE + || c == 0x1F5E8); // LEFT SPEECH BUBBLE +} + bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t count, size_t offset) { // This implementation closely follows Unicode Standard Annex #29 on @@ -93,6 +106,19 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co && u_getIntPropertyValue(c2, UCHAR_GENERAL_CATEGORY) == U_OTHER_LETTER) { return false; } + // Tailoring: make emoji sequences with ZWJ a single grapheme cluster + if (c1 == 0x200D && isZwjEmoji(c2) && offset_back > start) { + // look at character before ZWJ to see that both can participate in an emoji zwj sequence + uint32_t c0 = 0; + U16_PREV(buf, start, offset_back, c0); + if (c0 == 0xFE0F && offset_back > start) { + // skip over emoji variation selector + U16_PREV(buf, start, offset_back, c0); + } + if (isZwjEmoji(c0)) { + return false; + } + } // Rule GB10, Any / Any return true; } From 6cefe2eab1a796184891936062cff4835d0e17a7 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Fri, 11 Dec 2015 17:58:03 -0800 Subject: [PATCH 147/364] Introduce multiple language based font fallback. The motivation of this CL is enhance the font fallback score design to support multiple language font fallback. This CL contains following changes: - Break language based font score into two: script-based score and primary-language-based score. - The primary-language-based score is 0 if the script-based score is 0. If the script-based score is not 0 and the primary language is the as same as the requested one, the font gets an extra score of 1. - The language score gets a higher multiplier for languages higher in the locale list. Bug: 25122318 Bug: 26168983 Change-Id: Ib999997a88e6977e341f4c325e2a1b41a59db2d5 --- .../flutter/include/minikin/FontCollection.h | 10 + .../flutter/libs/minikin/FontCollection.cpp | 178 +++++-- .../src/flutter/libs/minikin/FontLanguage.cpp | 20 +- .../src/flutter/libs/minikin/FontLanguage.h | 12 +- .../libs/minikin/FontLanguageListCache.cpp | 17 +- .../tests/FontCollectionItemizeTest.cpp | 437 +++++++++++++++++- engine/src/flutter/tests/MinikinFontForTest.h | 5 + 7 files changed, 615 insertions(+), 64 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index cd14261640c..294692fcede 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -67,6 +67,16 @@ private: FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const; + uint32_t calcFamilyScore(uint32_t ch, uint32_t vs, int variant, uint32_t langListId, + FontFamily* fontFamily) const; + + uint32_t calcCoverageScore(uint32_t ch, uint32_t vs, FontFamily* fontFamily) const; + + static uint32_t calcLanguageMatchingScore(uint32_t userLangListId, + const FontFamily& fontFamily); + + static uint32_t calcVariantMatchingScore(int variant, const FontFamily& fontFamily); + // static for allocating unique id's static uint32_t sNextId; diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 38687001fed..da58fa39c9a 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -18,6 +18,7 @@ #define LOG_TAG "Minikin" #include +#include #include "unicode/unistr.h" #include "unicode/unorm2.h" @@ -103,29 +104,135 @@ FontCollection::~FontCollection() { } } +// Special scores for the font fallback. +const uint32_t kUnsupportedFontScore = 0; +const uint32_t kFirstFontScore = UINT32_MAX; + +// Calculates a font score. +// The score of the font family is based on three subscores. +// - Coverage Score: How well the font family covers the given character or variation sequence. +// - Language Score: How well the font family is appropriate for the language. +// - Variant Score: Whether the font family matches the variant. Note that this variant is not the +// one in BCP47. This is our own font variant (e.g., elegant, compact). +// +// Then, there is a priority for these three subscores as follow: +// Coverage Score > Language Score > Variant Score +// The returned score reflects this priority order. +// +// Note that there are two special scores. +// - kUnsupportedFontScore: When the font family doesn't support the variation sequence or even its +// base character. +// - kFirstFontScore: When the font is the first font family in the collection and it supports the +// given character or variation sequence. +uint32_t FontCollection::calcFamilyScore(uint32_t ch, uint32_t vs, int variant, uint32_t langListId, + FontFamily* fontFamily) const { + + const uint32_t coverageScore = calcCoverageScore(ch, vs, fontFamily); + if (coverageScore == kFirstFontScore || coverageScore == kUnsupportedFontScore) { + // No need to calculate other scores. + return coverageScore; + } + + const uint32_t languageScore = calcLanguageMatchingScore(langListId, *fontFamily); + const uint32_t variantScore = calcVariantMatchingScore(variant, *fontFamily); + + // Subscores are encoded into 31 bits representation to meet the subscore priority. + // The highest 2 bits are for coverage score, then following 28 bits are for language score, + // then the last 1 bit is for variant score. + return coverageScore << 29 | languageScore << 1 | variantScore; +} + +// Calculates a font score based on variation sequence coverage. +// - Returns kUnsupportedFontScore if the font doesn't support the variation sequence or its base +// character. +// - Returns kFirstFontScore if the font family is the first font family in the collection and it +// supports the given character or variation sequence. +// - Returns 3 if the font family supports the variation sequence. +// - Returns 2 if the vs is a color variation selector (U+FE0F) and if the font is an emoji font. +// - Returns 2 if the vs is a text variation selector (U+FE0E) and if the font is not an emoji font. +// - Returns 1 if the variation selector is not specified or if the font family only supports the +// variation sequence's base character. +uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, FontFamily* fontFamily) const { + const bool hasVSGlyph = (vs != 0) && fontFamily->hasVariationSelector(ch, vs); + if (!hasVSGlyph && !fontFamily->getCoverage()->get(ch)) { + // The font doesn't support either variation sequence or even the base character. + return kUnsupportedFontScore; + } + + if ((vs == 0 || hasVSGlyph) && mFamilies[0] == fontFamily) { + // If the first font family supports the given character or variation sequence, always use + // it. + return kFirstFontScore; + } + + if (vs == 0) { + return 1; + } + + if (hasVSGlyph) { + return 3; + } + + if (vs == 0xFE0F || vs == 0xFE0E) { + // TODO use all language in the list. + const FontLanguage lang = FontLanguageListCache::getById(fontFamily->langId())[0]; + const bool hasEmojiFlag = lang.hasEmojiFlag(); + if (vs == 0xFE0F) { + return hasEmojiFlag ? 2 : 1; + } else { // vs == 0xFE0E + return hasEmojiFlag ? 1 : 2; + } + } + return 1; +} + +// Calculates font scores based on the script matching and primary langauge matching. +// +// If the font's script doesn't support the requested script, the font gets a score of 0. If the +// font's script supports the requested script and the font has the same primary language as the +// requested one, the font gets a score of 2. If the font's script supports the requested script +// but the primary language is different from the requested one, the font gets a score of 1. +// +// If two languages in the requested list have the same language score, the font matching with +// higher priority language gets a higher score. For example, in the case the user requested +// language list is "ja-Jpan,en-Latn". The score of for the font of "ja-Jpan" gets a higher score +// than the font of "en-Latn". +// +// To achieve the above two conditions, the language score is determined as follows: +// LanguageScore = s(0) * 3^(m - 1) + s(1) * 3^(m - 2) + ... + s(m - 2) * 3 + s(m - 1) +// Here, m is the maximum number of languages to be compared, and s(i) is the i-th language's +// matching score. The possible values of s(i) are 0, 1 and 2. +uint32_t FontCollection::calcLanguageMatchingScore( + uint32_t userLangListId, const FontFamily& fontFamily) { + const FontLanguages& langList = FontLanguageListCache::getById(userLangListId); + // TODO use all language in the list. + FontLanguage fontLanguage = FontLanguageListCache::getById(fontFamily.langId())[0]; + + const size_t maxCompareNum = std::min(langList.size(), FONT_LANGUAGES_LIMIT); + uint32_t score = fontLanguage.getScoreFor(langList[0]); // maxCompareNum can't be zero. + for (size_t i = 1; i < maxCompareNum; ++i) { + score = score * 3u + fontLanguage.getScoreFor(langList[i]); + } + return score; +} + +// Calculates a font score based on variant ("compact" or "elegant") matching. +// - Returns 1 if the font doesn't have variant or the variant matches with the text style. +// - No score if the font has a variant but it doesn't match with the text style. +uint32_t FontCollection::calcVariantMatchingScore(int variant, const FontFamily& fontFamily) { + return (fontFamily.variant() == 0 || fontFamily.variant() == variant) ? 1 : 0; +} + // Implement heuristic for choosing best-match font. Here are the rules: // 1. If first font in the collection has the character, it wins. -// 2. If a font matches language, it gets a score of 2. -// 3. Matching the "compact" or "elegant" variant adds one to the score. -// 4. If there is a variation selector and a font supports the complete variation sequence, we add -// 8 to the score. -// 5. If there is a color variation selector (U+FE0F), we add 4 to the score if the font is an emoji -// font. This additional score of 4 is only given if the base character is supported in the font, -// but not the whole variation sequence. -// 6. If there is a text variation selector (U+FE0E), we add 4 to the score if the font is not an -// emoji font. This additional score of 4 is only given if the base character is supported in the -// font, but not the whole variation sequence. -// 7. Highest score wins, with ties resolved to the first font. +// 2. Calculate a score for the font family. See comments in calcFamilyScore for the detail. +// 3. Highest score wins, with ties resolved to the first font. FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const { if (ch >= mMaxChar) { return NULL; } - const FontLanguages& langList = FontLanguageListCache::getById(langListId); - // TODO: use all languages in langList. - const FontLanguage lang = (langList.size() == 0) ? FontLanguage() : langList[0]; - // Even if the font supports variation sequence, mRanges isn't aware of the base character of // the sequence. Search all FontFamilies if variation sequence is specified. // TODO: Always use mRanges for font search. @@ -141,40 +248,19 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, ALOGD("querying range %zd:%zd\n", range.start, range.end); #endif FontFamily* bestFamily = nullptr; - int bestScore = -1; + uint32_t bestScore = kUnsupportedFontScore; for (size_t i = range.start; i < range.end; i++) { FontFamily* family = familyVec[i]; - const bool hasVSGlyph = (vs != 0) && family->hasVariationSelector(ch, vs); - if (hasVSGlyph || family->getCoverage()->get(ch)) { - if ((vs == 0 || hasVSGlyph) && mFamilies[0] == family) { - // If the first font family in collection supports the given character or sequence, - // always use it. - return family; - } - - // TODO use all language in the list. - FontLanguage fontLang = FontLanguageListCache::getById(family->langId())[0]; - int score = lang.match(fontLang) * 2; - if (family->variant() == 0 || family->variant() == variant) { - score++; - } - if (hasVSGlyph) { - score += 8; - } else if (((vs == 0xFE0F) && fontLang.hasEmojiFlag()) || - ((vs == 0xFE0E) && !fontLang.hasEmojiFlag())) { - score += 4; - } - if (score > bestScore) { - bestScore = score; - bestFamily = family; - } + const uint32_t score = calcFamilyScore(ch, vs, variant, langListId, family); + if (score == kFirstFontScore) { + // If the first font family supports the given character or variation sequence, always + // use it. + return family; + } + if (score > bestScore) { + bestScore = score; + bestFamily = family; } - } - if (bestFamily == nullptr && vs != 0) { - // If no fonts support the codepoint and variation selector pair, - // fallback to select a font family that supports just the base - // character, ignoring the variation selector. - return getFamilyForChar(ch, 0, langListId, variant); } if (bestFamily == nullptr && !mFamilyVec.empty()) { UErrorCode errorCode = U_ZERO_ERROR; diff --git a/engine/src/flutter/libs/minikin/FontLanguage.cpp b/engine/src/flutter/libs/minikin/FontLanguage.cpp index b34040030fb..8e5c9c481f6 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguage.cpp @@ -115,21 +115,29 @@ std::string FontLanguage::getString() const { return std::string(buf, i); } -bool FontLanguage::isEqualScript(const FontLanguage other) const { +bool FontLanguage::isEqualScript(const FontLanguage& other) const { return other.mScript == mScript; } +bool FontLanguage::supportsScript(uint8_t requestedBits) const { + return requestedBits != 0 && (mSubScriptBits & requestedBits) == requestedBits; +} + bool FontLanguage::supportsHbScript(hb_script_t script) const { static_assert(SCRIPT_TAG('J', 'p', 'a', 'n') == HB_TAG('J', 'p', 'a', 'n'), "The Minikin script and HarfBuzz hb_script_t have different encodings."); if (script == mScript) return true; - uint8_t requestedBits = scriptToSubScriptBits(script); - return requestedBits != 0 && (mSubScriptBits & requestedBits) == requestedBits; + return supportsScript(scriptToSubScriptBits(script)); } -int FontLanguage::match(const FontLanguage other) const { - // TODO: Use script for matching. - return *this == other; +int FontLanguage::getScoreFor(const FontLanguage other) const { + if (isUnsupported() || other.isUnsupported()) { + return 0; + } else if (isEqualScript(other) || supportsScript(other.mSubScriptBits)) { + return mLanguage == other.mLanguage ? 2 : 1; + } else { + return 0; + } } #undef SCRIPT_TAG diff --git a/engine/src/flutter/libs/minikin/FontLanguage.h b/engine/src/flutter/libs/minikin/FontLanguage.h index abe7d13179d..ee0b505bdde 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.h +++ b/engine/src/flutter/libs/minikin/FontLanguage.h @@ -36,7 +36,7 @@ public: FontLanguage(const char* buf, size_t length); bool operator==(const FontLanguage other) const { - return !isUnsupported() && isEqualScript(other) && isEqualLanguage(other); + return !isUnsupported() && isEqualScript(other) && mLanguage == other.mLanguage; } bool operator!=(const FontLanguage other) const { @@ -46,8 +46,7 @@ public: bool isUnsupported() const { return mLanguage == 0ul; } bool hasEmojiFlag() const { return mSubScriptBits & kEmojiFlag; } - bool isEqualLanguage(const FontLanguage other) const { return mLanguage == other.mLanguage; } - bool isEqualScript(const FontLanguage other) const; + bool isEqualScript(const FontLanguage& other) const; // Returns true if this script supports the given script. For example, ja-Jpan supports Hira, // ja-Hira doesn't support Jpan. @@ -55,8 +54,8 @@ public: std::string getString() const; - // 0 = no match, 1 = language matches - int match(const FontLanguage other) const; + // 0 = no match, 1 = script match, 2 = script and primary language match. + int getScoreFor(const FontLanguage other) const; uint64_t getIdentifier() const { return (uint64_t)mScript << 32 | (uint64_t)mLanguage; } @@ -80,8 +79,11 @@ private: uint8_t mSubScriptBits; static uint8_t scriptToSubScriptBits(uint32_t script); + bool supportsScript(uint8_t requestedBits) const; }; +// Due to the limit of font fallback cost calculation, we can't use anything more than 17 languages. +const size_t FONT_LANGUAGES_LIMIT = 17; typedef std::vector FontLanguages; } // namespace android diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp index 2d64998e7a3..5d177b5827a 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp @@ -92,15 +92,20 @@ static FontLanguages constructFontLanguages(const std::string& input) { uint64_t identifier = lang.getIdentifier(); if (!lang.isUnsupported() && seen.count(identifier) == 0) { result.push_back(lang); + if (result.size() == FONT_LANGUAGES_LIMIT) { + break; + } seen.insert(identifier); } } - locale.assign(input, currentIdx, input.size() - currentIdx); - size_t length = toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, locale); - FontLanguage lang(langTag, length); - uint64_t identifier = lang.getIdentifier(); - if (!lang.isUnsupported() && seen.count(identifier) == 0) { - result.push_back(lang); + if (result.size() < FONT_LANGUAGES_LIMIT) { + locale.assign(input, currentIdx, input.size() - currentIdx); + size_t length = toLanguageTag(langTag, ULOC_FULLNAME_CAPACITY, locale); + FontLanguage lang(langTag, length); + uint64_t identifier = lang.getIdentifier(); + if (!lang.isUnsupported() && seen.count(identifier) == 0) { + result.push_back(lang); + } } return result; } diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index 57409a5e62c..446efc6b565 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -16,18 +16,23 @@ #include +#include "FontLanguageListCache.h" #include "FontLanguage.h" #include "FontTestUtils.h" #include "ICUTestBase.h" #include "MinikinFontForTest.h" #include "MinikinInternal.h" #include "UnicodeUtils.h" +#include "minikin/FontFamily.h" using android::AutoMutex; using android::FontCollection; using android::FontFamily; using android::FontLanguage; +using android::FontLanguages; +using android::FontLanguageListCache; using android::FontStyle; +using android::MinikinFont; using android::gMinikinLock; const char kItemizeFontXml[] = kTestFontDir "itemize.xml"; @@ -68,6 +73,12 @@ const std::string& getFontPath(const FontCollection::Run& run) { return ((MinikinFontForTest*)run.fakedFont.font)->fontPath(); } +// Utility function to obtain FontLanguages from string. +const FontLanguages& registerAndGetFontLanguages(const std::string& lang_string) { + AutoMutex _l(gMinikinLock); + return FontLanguageListCache::getById(FontLanguageListCache::getId(lang_string)); +} + TEST_F(FontCollectionItemizeTest, itemize_latin) { std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); std::vector runs; @@ -451,7 +462,7 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); // First font family (Regular.ttf) supports U+203C but doesn't support U+203C U+FE0F. - // Emoji.ttf font supports supports U+203C U+FE0F. Emoji.ttf should be selected. + // Emoji.ttf font supports U+203C U+FE0F. Emoji.ttf should be selected. itemize(collection.get(), "U+203C U+FE0F", kZH_HantStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); @@ -684,6 +695,430 @@ TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { family2->Unref(); } +TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { + struct TestCase { + std::string userPreferredLanguages; + std::string fontLanguages; + int selectedFontIndex; + } testCases[] = { + // Single user preferred language. + // Exact match case + { "en-Latn", "en-Latn,ja-Jpan", 0 }, + { "ja-Jpan", "en-Latn,ja-Jpan", 1 }, + { "en-Latn", "en-Latn,nl-Latn,es-Latn", 0 }, + { "nl-Latn", "en-Latn,nl-Latn,es-Latn", 1 }, + { "es-Latn", "en-Latn,nl-Latn,es-Latn", 2 }, + { "es-Latn", "en-Latn,en-Latn,nl-Latn", 0 }, + + // Exact script match case + { "en-Latn", "nl-Latn,be-Latn", 0 }, + { "en-Arab", "nl-Latn,ar-Arab", 1 }, + { "en-Latn", "be-Latn,ar-Arab,bd-Beng", 0 }, + { "en-Arab", "be-Latn,ar-Arab,bd-Beng", 1 }, + { "en-Beng", "be-Latn,ar-Arab,bd-Beng", 2 }, + { "en-Beng", "be-Latn,ar-Beng,bd-Beng", 1 }, + { "zh-Hant", "zh-Hant,zh-Hans", 0 }, + { "zh-Hans", "zh-Hant,zh-Hans", 1 }, + + // Subscript match case, e.g. Jpan supports Hira. + { "en-Hira", "ja-Jpan", 0 }, + { "zh-Hani", "zh-Hans,zh-Hant", 0 }, + { "zh-Hani", "zh-Hant,zh-Hans", 0 }, + { "en-Hira", "zh-Hant,ja-Jpan,ja-Jpan", 1 }, + + // Language match case + { "ja-Latn", "zh-Latn,ja-Latn", 1 }, + { "zh-Latn", "zh-Latn,ja-Latn", 0 }, + { "ja-Latn", "zh-Latn,ja-Latn", 1 }, + { "ja-Latn", "zh-Latn,ja-Latn,ja-Latn", 1 }, + + // Mixed case + // Script/subscript match is strongest. + { "ja-Jpan", "en-Latn,ja-Latn,en-Jpan", 2 }, + { "ja-Hira", "en-Latn,ja-Latn,en-Jpan", 2 }, + { "ja-Hira", "en-Latn,ja-Latn,en-Jpan,en-Jpan", 2 }, + + // Language match only happens if the script matches. + { "ja-Hira", "en-Latn,ja-Latn", 0 }, + { "ja-Hira", "en-Jpan,ja-Jpan", 1 }, + + // Multiple languages. + // Even if all fonts have the same score, use the 2nd language for better selection. + { "en-Latn,ja-Jpan", "zh-Hant,zh-Hans,ja-Jpan", 2 }, + { "en-Latn,nl-Latn", "es-Latn,be-Latn,nl-Latn", 2 }, + { "en-Latn,br-Latn,nl-Latn", "es-Latn,be-Latn,nl-Latn", 2 }, + { "en-Latn,br-Latn,nl-Latn", "es-Latn,be-Latn,nl-Latn,nl-Latn", 2 }, + + // Script score. + { "en-Latn,ja-Jpan", "en-Arab,en-Jpan", 1 }, + { "en-Latn,ja-Jpan", "en-Arab,en-Jpan,en-Jpan", 1 }, + + // Language match case + { "en-Latn,ja-Latn", "bd-Latn,ja-Latn", 1 }, + { "en-Latn,ja-Latn", "bd-Latn,ja-Latn,ja-Latn", 1 }, + + // Language match only happens if the script matches. + { "en-Latn,ar-Arab", "en-Beng,ar-Arab", 1 }, + }; + + for (auto testCase : testCases) { + SCOPED_TRACE("Test of user preferred languages: \"" + testCase.userPreferredLanguages + + "\" with font languages: " + testCase.fontLanguages); + + std::vector families; + + // Prepare first font which doesn't supports U+9AA8 + FontFamily* firstFamily = new FontFamily( + FontStyle::registerLanguageList("und"), 0 /* variant */); + MinikinFont* firstFamilyMinikinFont = new MinikinFontForTest(kNoGlyphFont); + firstFamily->addFont(firstFamilyMinikinFont); + families.push_back(firstFamily); + + // Prepare font families + // Each font family is associated with a specified language. All font families except for + // the first font support U+9AA8. + std::unordered_map fontLangIdxMap; + const FontLanguages& fontLanguages = registerAndGetFontLanguages(testCase.fontLanguages); + + for (size_t i = 0; i < fontLanguages.size(); ++i) { + const FontLanguage& fontLanguage = fontLanguages[i]; + FontFamily* family = new FontFamily( + FontStyle::registerLanguageList(fontLanguage.getString()), 0 /* variant */); + MinikinFont* minikin_font = new MinikinFontForTest(kJAFont); + family->addFont(minikin_font); + families.push_back(family); + fontLangIdxMap.insert(std::make_pair(minikin_font, i)); + } + FontCollection collection(families); + for (auto family : families) { + family->Unref(); + } + + // Do itemize + const FontStyle style = FontStyle( + FontStyle::registerLanguageList(testCase.userPreferredLanguages)); + std::vector runs; + itemize(&collection, "U+9AA8", style, &runs); + ASSERT_EQ(1U, runs.size()); + ASSERT_NE(nullptr, runs[0].fakedFont.font); + + // First family doesn't support U+9AA8 and others support it, so the first font should not + // be selected. + EXPECT_NE(firstFamilyMinikinFont, runs[0].fakedFont.font); + + // Lookup used font family by MinikinFont*. + const int usedLangIndex = fontLangIdxMap[runs[0].fakedFont.font]; + EXPECT_EQ(testCase.selectedFontIndex, usedLangIndex); + } +} + +TEST_F(FontCollectionItemizeTest, itemize_LanguageAndCoverage) { + struct TestCase { + std::string testString; + std::string requestedLanguages; + std::string expectedFont; + } testCases[] = { + // Following test cases verify that following rules in font fallback chain. + // - If the first font in the collection supports the given character or variation sequence, + // it should be selected. + // - If the font doesn't support the given character, variation sequence or its base + // character, it should not be selected. + // - If two or more fonts match the requested languages, the font matches with the highest + // priority language should be selected. + // - If two or more fonts get the same score, the font listed earlier in the XML file + // (here, kItemizeFontXml) should be selected. + + // Regardless of language, the first font is always selected if it covers the code point. + { "'a'", "", kLatinFont}, + { "'a'", "en-Latn", kLatinFont}, + { "'a'", "ja-Jpan", kLatinFont}, + { "'a'", "ja-Jpan,en-Latn", kLatinFont}, + { "'a'", "zh-Hans,zh-Hant,en-Latn,ja-Jpan,fr-Latn", kLatinFont}, + + // U+81ED is supported by both the ja font and zh-Hans font. + { "U+81ED", "", kZH_HansFont }, // zh-Hans font is listed before ja font. + { "U+81ED", "en-Latn", kZH_HansFont }, // zh-Hans font is listed before ja font. + { "U+81ED", "ja-Jpan", kJAFont }, + { "U+81ED", "zh-Hans", kZH_HansFont }, + + { "U+81ED", "ja-Jpan,en-Latn", kJAFont }, + { "U+81ED", "en-Latn,ja-Jpan", kJAFont }, + { "U+81ED", "en-Latn,zh-Hans", kZH_HansFont }, + { "U+81ED", "zh-Hans,en-Latn", kZH_HansFont }, + { "U+81ED", "ja-Jpan,zh-Hans", kJAFont }, + { "U+81ED", "zh-Hans,ja-Jpan", kZH_HansFont }, + + { "U+81ED", "en-Latn,zh-Hans,ja-Jpan", kZH_HansFont }, + { "U+81ED", "en-Latn,ja-Jpan,zh-Hans", kJAFont }, + { "U+81ED", "en-Latn,zh-Hans,ja-Jpan", kZH_HansFont }, + { "U+81ED", "ja-Jpan,en-Latn,zh-Hans", kJAFont }, + { "U+81ED", "ja-Jpan,zh-Hans,en-Latn", kJAFont }, + { "U+81ED", "zh-Hans,en-Latn,ja-Jpan", kZH_HansFont }, + { "U+81ED", "zh-Hans,ja-Jpan,en-Latn", kZH_HansFont }, + + // U+304A is only supported by ja font. + { "U+304A", "", kJAFont }, + { "U+304A", "ja-Jpan", kJAFont }, + { "U+304A", "zh-Hant", kJAFont }, + { "U+304A", "zh-Hans", kJAFont }, + + { "U+304A", "ja-Jpan,zh-Hant", kJAFont }, + { "U+304A", "zh-Hant,ja-Jpan", kJAFont }, + { "U+304A", "zh-Hans,zh-Hant", kJAFont }, + { "U+304A", "zh-Hant,zh-Hans", kJAFont }, + { "U+304A", "zh-Hans,ja-Jpan", kJAFont }, + { "U+304A", "ja-Jpan,zh-Hans", kJAFont }, + + { "U+304A", "zh-Hans,ja-Jpan,zh-Hant", kJAFont }, + { "U+304A", "zh-Hans,zh-Hant,ja-Jpan", kJAFont }, + { "U+304A", "ja-Jpan,zh-Hans,zh-Hant", kJAFont }, + { "U+304A", "ja-Jpan,zh-Hant,zh-Hans", kJAFont }, + { "U+304A", "zh-Hant,zh-Hans,ja-Jpan", kJAFont }, + { "U+304A", "zh-Hant,ja-Jpan,zh-Hans", kJAFont }, + + // U+242EE is supported by both ja font and zh-Hant fonts but not by zh-Hans font. + { "U+242EE", "", kJAFont }, // ja font is listed before zh-Hant font. + { "U+242EE", "ja-Jpan", kJAFont }, + { "U+242EE", "zh-Hans", kJAFont }, + { "U+242EE", "zh-Hant", kZH_HantFont }, + + { "U+242EE", "ja-Jpan,zh-Hant", kJAFont }, + { "U+242EE", "zh-Hant,ja-Jpan", kZH_HantFont }, + { "U+242EE", "zh-Hans,zh-Hant", kZH_HantFont }, + { "U+242EE", "zh-Hant,zh-Hans", kZH_HantFont }, + { "U+242EE", "zh-Hans,ja-Jpan", kJAFont }, + { "U+242EE", "ja-Jpan,zh-Hans", kJAFont }, + + { "U+242EE", "zh-Hans,ja-Jpan,zh-Hant", kJAFont }, + { "U+242EE", "zh-Hans,zh-Hant,ja-Jpan", kZH_HantFont }, + { "U+242EE", "ja-Jpan,zh-Hans,zh-Hant", kJAFont }, + { "U+242EE", "ja-Jpan,zh-Hant,zh-Hans", kJAFont }, + { "U+242EE", "zh-Hant,zh-Hans,ja-Jpan", kZH_HantFont }, + { "U+242EE", "zh-Hant,ja-Jpan,zh-Hans", kZH_HantFont }, + + // U+9AA8 is supported by all ja-Jpan, zh-Hans, zh-Hant fonts. + { "U+9AA8", "", kZH_HansFont }, // zh-Hans font is listed before ja and zh-Hant fonts. + { "U+9AA8", "ja-Jpan", kJAFont }, + { "U+9AA8", "zh-Hans", kZH_HansFont }, + { "U+9AA8", "zh-Hant", kZH_HantFont }, + + { "U+9AA8", "ja-Jpan,zh-Hant", kJAFont }, + { "U+9AA8", "zh-Hant,ja-Jpan", kZH_HantFont }, + { "U+9AA8", "zh-Hans,zh-Hant", kZH_HansFont }, + { "U+9AA8", "zh-Hant,zh-Hans", kZH_HantFont }, + { "U+9AA8", "zh-Hans,ja-Jpan", kZH_HansFont }, + { "U+9AA8", "ja-Jpan,zh-Hans", kJAFont }, + + { "U+9AA8", "zh-Hans,ja-Jpan,zh-Hant", kZH_HansFont }, + { "U+9AA8", "zh-Hans,zh-Hant,ja-Jpan", kZH_HansFont }, + { "U+9AA8", "ja-Jpan,zh-Hans,zh-Hant", kJAFont }, + { "U+9AA8", "ja-Jpan,zh-Hant,zh-Hans", kJAFont }, + { "U+9AA8", "zh-Hant,zh-Hans,ja-Jpan", kZH_HantFont }, + { "U+9AA8", "zh-Hant,ja-Jpan,zh-Hans", kZH_HantFont }, + + // U+242EE U+FE00 is supported by ja font but not by zh-Hans or zh-Hant fonts. + { "U+242EE U+FE00", "", kJAFont }, + { "U+242EE U+FE00", "ja-Jpan", kJAFont }, + { "U+242EE U+FE00", "zh-Hant", kJAFont }, + { "U+242EE U+FE00", "zh-Hans", kJAFont }, + + { "U+242EE U+FE00", "ja-Jpan,zh-Hant", kJAFont }, + { "U+242EE U+FE00", "zh-Hant,ja-Jpan", kJAFont }, + { "U+242EE U+FE00", "zh-Hans,zh-Hant", kJAFont }, + { "U+242EE U+FE00", "zh-Hant,zh-Hans", kJAFont }, + { "U+242EE U+FE00", "zh-Hans,ja-Jpan", kJAFont }, + { "U+242EE U+FE00", "ja-Jpan,zh-Hans", kJAFont }, + + { "U+242EE U+FE00", "zh-Hans,ja-Jpan,zh-Hant", kJAFont }, + { "U+242EE U+FE00", "zh-Hans,zh-Hant,ja-Jpan", kJAFont }, + { "U+242EE U+FE00", "ja-Jpan,zh-Hans,zh-Hant", kJAFont }, + { "U+242EE U+FE00", "ja-Jpan,zh-Hant,zh-Hans", kJAFont }, + { "U+242EE U+FE00", "zh-Hant,zh-Hans,ja-Jpan", kJAFont }, + { "U+242EE U+FE00", "zh-Hant,ja-Jpan,zh-Hans", kJAFont }, + + // U+3402 U+E0100 is supported by both zh-Hans and zh-Hant but not by ja font. + { "U+3402 U+E0100", "", kZH_HansFont }, // zh-Hans font is listed before zh-Hant font. + { "U+3402 U+E0100", "ja-Jpan", kZH_HansFont }, // zh-Hans font is listed before zh-Hant font. + { "U+3402 U+E0100", "zh-Hant", kZH_HantFont }, + { "U+3402 U+E0100", "zh-Hans", kZH_HansFont }, + + { "U+3402 U+E0100", "ja-Jpan,zh-Hant", kZH_HantFont }, + { "U+3402 U+E0100", "zh-Hant,ja-Jpan", kZH_HantFont }, + { "U+3402 U+E0100", "zh-Hans,zh-Hant", kZH_HansFont }, + { "U+3402 U+E0100", "zh-Hant,zh-Hans", kZH_HantFont }, + { "U+3402 U+E0100", "zh-Hans,ja-Jpan", kZH_HansFont }, + { "U+3402 U+E0100", "ja-Jpan,zh-Hans", kZH_HansFont }, + + { "U+3402 U+E0100", "zh-Hans,ja-Jpan,zh-Hant", kZH_HansFont }, + { "U+3402 U+E0100", "zh-Hans,zh-Hant,ja-Jpan", kZH_HansFont }, + { "U+3402 U+E0100", "ja-Jpan,zh-Hans,zh-Hant", kZH_HansFont }, + { "U+3402 U+E0100", "ja-Jpan,zh-Hant,zh-Hans", kZH_HantFont }, + { "U+3402 U+E0100", "zh-Hant,zh-Hans,ja-Jpan", kZH_HantFont }, + { "U+3402 U+E0100", "zh-Hant,ja-Jpan,zh-Hans", kZH_HantFont }, + + // No font supports U+4444 U+FE00 but only zh-Hans supports its base character U+4444. + { "U+4444 U+FE00", "", kZH_HansFont }, + { "U+4444 U+FE00", "ja-Jpan", kZH_HansFont }, + { "U+4444 U+FE00", "zh-Hant", kZH_HansFont }, + { "U+4444 U+FE00", "zh-Hans", kZH_HansFont }, + + { "U+4444 U+FE00", "ja-Jpan,zh-Hant", kZH_HansFont }, + { "U+4444 U+FE00", "zh-Hant,ja-Jpan", kZH_HansFont }, + { "U+4444 U+FE00", "zh-Hans,zh-Hant", kZH_HansFont }, + { "U+4444 U+FE00", "zh-Hant,zh-Hans", kZH_HansFont }, + { "U+4444 U+FE00", "zh-Hans,ja-Jpan", kZH_HansFont }, + { "U+4444 U+FE00", "ja-Jpan,zh-Hans", kZH_HansFont }, + + { "U+4444 U+FE00", "zh-Hans,ja-Jpan,zh-Hant", kZH_HansFont }, + { "U+4444 U+FE00", "zh-Hans,zh-Hant,ja-Jpan", kZH_HansFont }, + { "U+4444 U+FE00", "ja-Jpan,zh-Hans,zh-Hant", kZH_HansFont }, + { "U+4444 U+FE00", "ja-Jpan,zh-Hant,zh-Hans", kZH_HansFont }, + { "U+4444 U+FE00", "zh-Hant,zh-Hans,ja-Jpan", kZH_HansFont }, + { "U+4444 U+FE00", "zh-Hant,ja-Jpan,zh-Hans", kZH_HansFont }, + + // No font supports U+81ED U+E0100 but ja and zh-Hans support its base character U+81ED. + // zh-Hans font is listed before ja font. + { "U+81ED U+E0100", "", kZH_HansFont }, + { "U+81ED U+E0100", "ja-Jpan", kJAFont }, + { "U+81ED U+E0100", "zh-Hant", kZH_HansFont }, + { "U+81ED U+E0100", "zh-Hans", kZH_HansFont }, + + { "U+81ED U+E0100", "ja-Jpan,zh-Hant", kJAFont }, + { "U+81ED U+E0100", "zh-Hant,ja-Jpan", kJAFont }, + { "U+81ED U+E0100", "zh-Hans,zh-Hant", kZH_HansFont }, + { "U+81ED U+E0100", "zh-Hant,zh-Hans", kZH_HansFont }, + { "U+81ED U+E0100", "zh-Hans,ja-Jpan", kZH_HansFont }, + { "U+81ED U+E0100", "ja-Jpan,zh-Hans", kJAFont }, + + { "U+81ED U+E0100", "zh-Hans,ja-Jpan,zh-Hant", kZH_HansFont }, + { "U+81ED U+E0100", "zh-Hans,zh-Hant,ja-Jpan", kZH_HansFont }, + { "U+81ED U+E0100", "ja-Jpan,zh-Hans,zh-Hant", kJAFont }, + { "U+81ED U+E0100", "ja-Jpan,zh-Hant,zh-Hans", kJAFont }, + { "U+81ED U+E0100", "zh-Hant,zh-Hans,ja-Jpan", kZH_HansFont }, + { "U+81ED U+E0100", "zh-Hant,ja-Jpan,zh-Hans", kJAFont }, + + // No font supports U+9AA8 U+E0100 but all zh-Hans zh-hant ja fonts support its base + // character U+9AA8. + // zh-Hans font is listed before ja and zh-Hant fonts. + { "U+9AA8 U+E0100", "", kZH_HansFont }, + { "U+9AA8 U+E0100", "ja-Jpan", kJAFont }, + { "U+9AA8 U+E0100", "zh-Hans", kZH_HansFont }, + { "U+9AA8 U+E0100", "zh-Hant", kZH_HantFont }, + + { "U+9AA8 U+E0100", "ja-Jpan,zh-Hant", kJAFont }, + { "U+9AA8 U+E0100", "zh-Hant,ja-Jpan", kZH_HantFont }, + { "U+9AA8 U+E0100", "zh-Hans,zh-Hant", kZH_HansFont }, + { "U+9AA8 U+E0100", "zh-Hant,zh-Hans", kZH_HantFont }, + { "U+9AA8 U+E0100", "zh-Hans,ja-Jpan", kZH_HansFont }, + { "U+9AA8 U+E0100", "ja-Jpan,zh-Hans", kJAFont }, + + { "U+9AA8 U+E0100", "zh-Hans,ja-Jpan,zh-Hant", kZH_HansFont }, + { "U+9AA8 U+E0100", "zh-Hans,zh-Hant,ja-Jpan", kZH_HansFont }, + { "U+9AA8 U+E0100", "ja-Jpan,zh-Hans,zh-Hant", kJAFont }, + { "U+9AA8 U+E0100", "ja-Jpan,zh-Hant,zh-Hans", kJAFont }, + { "U+9AA8 U+E0100", "zh-Hant,zh-Hans,ja-Jpan", kZH_HantFont }, + { "U+9AA8 U+E0100", "zh-Hant,ja-Jpan,zh-Hans", kZH_HantFont }, + + // All zh-Hans,zh-Hant,ja fonts support U+35A8 U+E0100 and its base character U+35A8. + // zh-Hans font is listed before ja and zh-Hant fonts. + { "U+35A8", "", kZH_HansFont }, + { "U+35A8", "ja-Jpan", kJAFont }, + { "U+35A8", "zh-Hans", kZH_HansFont }, + { "U+35A8", "zh-Hant", kZH_HantFont }, + + { "U+35A8", "ja-Jpan,zh-Hant", kJAFont }, + { "U+35A8", "zh-Hant,ja-Jpan", kZH_HantFont }, + { "U+35A8", "zh-Hans,zh-Hant", kZH_HansFont }, + { "U+35A8", "zh-Hant,zh-Hans", kZH_HantFont }, + { "U+35A8", "zh-Hans,ja-Jpan", kZH_HansFont }, + { "U+35A8", "ja-Jpan,zh-Hans", kJAFont }, + + { "U+35A8", "zh-Hans,ja-Jpan,zh-Hant", kZH_HansFont }, + { "U+35A8", "zh-Hans,zh-Hant,ja-Jpan", kZH_HansFont }, + { "U+35A8", "ja-Jpan,zh-Hans,zh-Hant", kJAFont }, + { "U+35A8", "ja-Jpan,zh-Hant,zh-Hans", kJAFont }, + { "U+35A8", "zh-Hant,zh-Hans,ja-Jpan", kZH_HantFont }, + { "U+35A8", "zh-Hant,ja-Jpan,zh-Hans", kZH_HantFont }, + + // All zh-Hans,zh-Hant,ja fonts support U+35B6 U+E0100, but zh-Hant and ja fonts support its + // base character U+35B6. + // ja font is listed before zh-Hant font. + { "U+35B6", "", kJAFont }, + { "U+35B6", "ja-Jpan", kJAFont }, + { "U+35B6", "zh-Hant", kZH_HantFont }, + { "U+35B6", "zh-Hans", kJAFont }, + + { "U+35B6", "ja-Jpan,zh-Hant", kJAFont }, + { "U+35B6", "zh-Hant,ja-Jpan", kZH_HantFont }, + { "U+35B6", "zh-Hans,zh-Hant", kZH_HantFont }, + { "U+35B6", "zh-Hant,zh-Hans", kZH_HantFont }, + { "U+35B6", "zh-Hans,ja-Jpan", kJAFont }, + { "U+35B6", "ja-Jpan,zh-Hans", kJAFont }, + + { "U+35B6", "zh-Hans,ja-Jpan,zh-Hant", kJAFont }, + { "U+35B6", "zh-Hans,zh-Hant,ja-Jpan", kZH_HantFont }, + { "U+35B6", "ja-Jpan,zh-Hans,zh-Hant", kJAFont }, + { "U+35B6", "ja-Jpan,zh-Hant,zh-Hans", kJAFont }, + { "U+35B6", "zh-Hant,zh-Hans,ja-Jpan", kZH_HantFont }, + { "U+35B6", "zh-Hant,ja-Jpan,zh-Hans", kZH_HantFont }, + + // All zh-Hans,zh-Hant,ja fonts support U+35C5 U+E0100, but only ja font supports its base + // character U+35C5. + { "U+35C5", "", kJAFont }, + { "U+35C5", "ja-Jpan", kJAFont }, + { "U+35C5", "zh-Hant", kJAFont }, + { "U+35C5", "zh-Hans", kJAFont }, + + { "U+35C5", "ja-Jpan,zh-Hant", kJAFont }, + { "U+35C5", "zh-Hant,ja-Jpan", kJAFont }, + { "U+35C5", "zh-Hans,zh-Hant", kJAFont }, + { "U+35C5", "zh-Hant,zh-Hans", kJAFont }, + { "U+35C5", "zh-Hans,ja-Jpan", kJAFont }, + { "U+35C5", "ja-Jpan,zh-Hans", kJAFont }, + + { "U+35C5", "zh-Hans,ja-Jpan,zh-Hant", kJAFont }, + { "U+35C5", "zh-Hans,zh-Hant,ja-Jpan", kJAFont }, + { "U+35C5", "ja-Jpan,zh-Hans,zh-Hant", kJAFont }, + { "U+35C5", "ja-Jpan,zh-Hant,zh-Hans", kJAFont }, + { "U+35C5", "zh-Hant,zh-Hans,ja-Jpan", kJAFont }, + { "U+35C5", "zh-Hant,ja-Jpan,zh-Hans", kJAFont }, + + // None of ja-Jpan, zh-Hant, zh-Hans font supports U+1F469. Emoji font supports it. + { "U+1F469", "", kEmojiFont }, + { "U+1F469", "ja-Jpan", kEmojiFont }, + { "U+1F469", "zh-Hant", kEmojiFont }, + { "U+1F469", "zh-Hans", kEmojiFont }, + + { "U+1F469", "ja-Jpan,zh-Hant", kEmojiFont }, + { "U+1F469", "zh-Hant,ja-Jpan", kEmojiFont }, + { "U+1F469", "zh-Hans,zh-Hant", kEmojiFont }, + { "U+1F469", "zh-Hant,zh-Hans", kEmojiFont }, + { "U+1F469", "zh-Hans,ja-Jpan", kEmojiFont }, + { "U+1F469", "ja-Jpan,zh-Hans", kEmojiFont }, + + { "U+1F469", "zh-Hans,ja-Jpan,zh-Hant", kEmojiFont }, + { "U+1F469", "zh-Hans,zh-Hant,ja-Jpan", kEmojiFont }, + { "U+1F469", "ja-Jpan,zh-Hans,zh-Hant", kEmojiFont }, + { "U+1F469", "ja-Jpan,zh-Hant,zh-Hans", kEmojiFont }, + { "U+1F469", "zh-Hant,zh-Hans,ja-Jpan", kEmojiFont }, + { "U+1F469", "zh-Hant,ja-Jpan,zh-Hans", kEmojiFont }, + }; + + std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); + + for (auto testCase : testCases) { + SCOPED_TRACE("Test for \"" + testCase.testString + "\" with languages " + + testCase.requestedLanguages); + + std::vector runs; + const FontStyle style = + FontStyle(FontStyle::registerLanguageList(testCase.requestedLanguages)); + itemize(collection.get(), testCase.testString.c_str(), style, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(testCase.expectedFont, getFontPath(runs[0])); + } +} + TEST_F(FontCollectionItemizeTest, itemize_emojiSelection) { std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); std::vector runs; diff --git a/engine/src/flutter/tests/MinikinFontForTest.h b/engine/src/flutter/tests/MinikinFontForTest.h index 5738666f77d..790348deaea 100644 --- a/engine/src/flutter/tests/MinikinFontForTest.h +++ b/engine/src/flutter/tests/MinikinFontForTest.h @@ -14,6 +14,9 @@ * limitations under the License. */ +#ifndef MINIKIN_TEST_MINIKIN_FONT_FOR_TEST_H +#define MINIKIN_TEST_MINIKIN_FONT_FOR_TEST_H + #include class SkTypeface; @@ -35,3 +38,5 @@ private: SkTypeface *mTypeface; const std::string mFontPath; }; + +#endif // MINIKIN_TEST_MINIKIN_FONT_FOR_TEST_H From 84b080abc57a299fc2ea0d0b0b09d895476ca2a9 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Tue, 13 Oct 2015 19:20:09 +0900 Subject: [PATCH 148/364] Add light weight methods for text measurement. The intruduced method measureText can be used instead of doLayout for text measurement purpose. Bug: 24505153 Change-Id: Ic29bbb347daf18d1f6c13f86970dcdd11dd6a2bd --- engine/src/flutter/include/minikin/Layout.h | 16 +++-- engine/src/flutter/libs/minikin/Layout.cpp | 68 ++++++++++++++++----- 2 files changed, 65 insertions(+), 19 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index cb68db9c3dd..d9bb01f1a7c 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -93,6 +93,10 @@ public: void doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint); + static float measureText(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + int bidiFlags, const FontStyle &style, const MinikinPaint &paint, + const FontCollection* collection, float* advances); + void draw(minikin::Bitmap*, int x0, int y0, float size) const; // Deprecated. Nont needed. Remove when callers are removed. @@ -129,12 +133,16 @@ private: int findFace(FakedFont face, LayoutContext* ctx); // Lay out a single bidi run - void doLayoutRunCached(const uint16_t* buf, size_t runStart, size_t runLength, size_t bufSize, - bool isRtl, LayoutContext* ctx, size_t dstStart); + // When layout is not null, layout info will be stored in the object. + // When advances is not null, measurement results will be stored in the array. + static float doLayoutRunCached(const uint16_t* buf, size_t runStart, size_t runLength, + size_t bufSize, bool isRtl, LayoutContext* ctx, size_t dstStart, + const FontCollection* collection, Layout* layout, float* advances); // Lay out a single word - void doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - bool isRtl, LayoutContext* ctx, size_t bufStart); + static float doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, LayoutContext* ctx, size_t bufStart, const FontCollection* collection, + Layout* layout, float* advances); // Lay out a single bidi run void doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 2e206a20fc3..2839e5b71d3 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -596,15 +596,37 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu for (const BidiText::Iter::RunInfo& runInfo : BidiText(buf, start, count, bufSize, bidiFlags)) { doLayoutRunCached(buf, runInfo.mRunStart, runInfo.mRunLength, bufSize, runInfo.mIsRtl, &ctx, - start); + start, mCollection, this, NULL); } ctx.clearHbFonts(); mCollection->purgeFontFamilyHbFontCache(); } -void Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - bool isRtl, LayoutContext* ctx, size_t dstStart) { +float Layout::measureText(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + int bidiFlags, const FontStyle &style, const MinikinPaint &paint, + const FontCollection* collection, float* advances) { + AutoMutex _l(gMinikinLock); + + LayoutContext ctx; + ctx.style = style; + ctx.paint = paint; + + float advance = 0; + for (const BidiText::Iter::RunInfo& runInfo : BidiText(buf, start, count, bufSize, bidiFlags)) { + float* advancesForRun = advances ? advances + (runInfo.mRunStart - start) : advances; + advance += doLayoutRunCached(buf, runInfo.mRunStart, runInfo.mRunLength, bufSize, + runInfo.mIsRtl, &ctx, 0, collection, NULL, advancesForRun); + } + + ctx.clearHbFonts(); + return advance; +} + +float Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, LayoutContext* ctx, size_t dstStart, const FontCollection* collection, + Layout* layout, float* advances) { HyphenEdit hyphen = ctx->paint.hyphenEdit; + float advance = 0; if (!isRtl) { // left to right size_t wordstart = @@ -615,8 +637,9 @@ void Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, // Only apply hyphen to the last word in the string. ctx->paint.hyphenEdit = wordend >= start + count ? hyphen : HyphenEdit(); size_t wordcount = std::min(start + count, wordend) - iter; - doLayoutWord(buf + wordstart, iter - wordstart, wordcount, wordend - wordstart, - isRtl, ctx, iter - dstStart); + advance += doLayoutWord(buf + wordstart, iter - wordstart, wordcount, + wordend - wordstart, isRtl, ctx, iter - dstStart, collection, layout, + advances ? advances + (iter - start) : advances); wordstart = wordend; } } else { @@ -629,25 +652,40 @@ void Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, // Only apply hyphen to the last (leftmost) word in the string. ctx->paint.hyphenEdit = iter == end ? hyphen : HyphenEdit(); size_t bufStart = std::max(start, wordstart); - doLayoutWord(buf + wordstart, bufStart - wordstart, iter - bufStart, - wordend - wordstart, isRtl, ctx, bufStart - dstStart); + advance += doLayoutWord(buf + wordstart, bufStart - wordstart, iter - bufStart, + wordend - wordstart, isRtl, ctx, bufStart - dstStart, collection, layout, + advances ? advances + (bufStart - start) : advances); wordend = wordstart; } } + return advance; } -void Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - bool isRtl, LayoutContext* ctx, size_t bufStart) { +float Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_t bufSize, + bool isRtl, LayoutContext* ctx, size_t bufStart, const FontCollection* collection, + Layout* layout, float* advances) { LayoutCache& cache = LayoutEngine::getInstance().layoutCache; - LayoutCacheKey key(mCollection, ctx->paint, ctx->style, buf, start, count, bufSize, isRtl); + LayoutCacheKey key(collection, ctx->paint, ctx->style, buf, start, count, bufSize, isRtl); bool skipCache = ctx->paint.skipCache(); if (skipCache) { - Layout layout; - key.doLayout(&layout, ctx, mCollection); - appendLayout(&layout, bufStart); + Layout layoutForWord; + key.doLayout(&layoutForWord, ctx, collection); + if (layout) { + layout->appendLayout(&layoutForWord, bufStart); + } + if (advances) { + layoutForWord.getAdvances(advances); + } + return layoutForWord.getAdvance(); } else { - Layout* layout = cache.get(key, ctx, mCollection); - appendLayout(layout, bufStart); + Layout* layoutForWord = cache.get(key, ctx, collection); + if (layout) { + layout->appendLayout(layoutForWord, bufStart); + } + if (advances) { + layoutForWord->getAdvances(advances); + } + return layoutForWord->getAdvance(); } } From 900a7c36fb2953605bae61a70fb508d0f8fe515c Mon Sep 17 00:00:00 2001 From: Stephen Hines Date: Tue, 26 Jan 2016 00:44:02 -0800 Subject: [PATCH 149/364] Disable unsigned integer overflow sanitization until libc++ is fixed. Bug: http://b/26781196 Bug: http://b/25884483 Bug: http://b/26432628 Although this issue was first only manifesting on Fugu, it now affects N9 and N6p as well. This change disables unsigned overflow sanitization on all platforms. The real fix for libc++ (r257368) can't be committed until we have updated Clang at least one more time. Change-Id: I71e9c50d25ae4566d4c06f348183c4b22a4bb60a --- engine/src/flutter/libs/minikin/Android.mk | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index f91a4a80d3d..48d06c0847a 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -53,9 +53,7 @@ LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) LOCAL_CLANG := true LOCAL_SANITIZE := signed-integer-overflow # b/26432628. -ifeq ($(filter x86%,$(TARGET_ARCH)),) - LOCAL_SANITIZE += unsigned-integer-overflow -endif +#LOCAL_SANITIZE += unsigned-integer-overflow include $(BUILD_SHARED_LIBRARY) @@ -70,9 +68,7 @@ LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) LOCAL_CLANG := true LOCAL_SANITIZE := signed-integer-overflow # b/26432628. -ifeq ($(filter x86%,$(TARGET_ARCH)),) - LOCAL_SANITIZE += unsigned-integer-overflow -endif +#LOCAL_SANITIZE += unsigned-integer-overflow include $(BUILD_STATIC_LIBRARY) From 109b6675541d10cfccfb188f94eb9def9d1d3723 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 3 Feb 2016 19:41:00 +0900 Subject: [PATCH 150/364] Improve Paint.hasGlyph performance by caching hb_font_t It turned out that hb_font_t creation is not a lightweight operation. Especially, Paint.hasGlyph creates hb_font_t for all existing fonts every time. To improve the performance, cache hb_font_t instead of hb_face_t. Note that to calculate horizontal advance, MinikinPaint needs to be associated with hb_font_t by calling hb_font_set_funcs. With this patch, hb_font_set_funcs may be called multiple times for the same hb_font_t object. However this is not an issue since MinikinPaint is unique during layout. Bug: 26784699 Change-Id: I516498ae9f0127d700fc9829327e9789845a1416 --- .../flutter/include/minikin/FontCollection.h | 3 - .../src/flutter/include/minikin/FontFamily.h | 11 +- engine/src/flutter/libs/minikin/Android.mk | 2 +- .../flutter/libs/minikin/FontCollection.cpp | 7 -- .../src/flutter/libs/minikin/FontFamily.cpp | 22 +--- .../{HbFaceCache.cpp => HbFontCache.cpp} | 60 +++++---- .../minikin/{HbFaceCache.h => HbFontCache.h} | 12 +- engine/src/flutter/libs/minikin/Layout.cpp | 26 +--- engine/src/flutter/tests/Android.mk | 2 +- engine/src/flutter/tests/FontFamilyTest.cpp | 14 --- engine/src/flutter/tests/HbFaceCacheTest.cpp | 118 ------------------ engine/src/flutter/tests/HbFontCacheTest.cpp | 87 +++++++++++++ 12 files changed, 144 insertions(+), 220 deletions(-) rename engine/src/flutter/libs/minikin/{HbFaceCache.cpp => HbFontCache.cpp} (60%) rename engine/src/flutter/libs/minikin/{HbFaceCache.h => HbFontCache.h} (77%) delete mode 100644 engine/src/flutter/tests/HbFaceCacheTest.cpp create mode 100644 engine/src/flutter/tests/HbFontCacheTest.cpp diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 294692fcede..3a63c079480 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -53,9 +53,6 @@ public: uint32_t getId() const; - // Calls each managed font family's FontFamily::purgeHbFontCache method. - // Caller should acquire a lock before calling the method. - void purgeFontFamilyHbFontCache() const; private: static const int kLogCharsPerPage = 8; static const int kPageMask = (1 << kLogCharsPerPage) - 1; diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index aa2e0ac2e4a..2b59160ffad 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -100,11 +100,11 @@ struct FakedFont { class FontFamily : public MinikinRefCounted { public: - FontFamily() : mHbFont(nullptr) { } + FontFamily() {} FontFamily(int variant); - FontFamily(uint32_t langId, int variant) : mLangId(langId), mVariant(variant), mHbFont(nullptr) { + FontFamily(uint32_t langId, int variant) : mLangId(langId), mVariant(variant) { } ~FontFamily(); @@ -131,11 +131,6 @@ public: // Caller should acquire a lock before calling the method. bool hasVariationSelector(uint32_t codepoint, uint32_t variationSelector); - // Purges cached mHbFont. - // hb_font_t keeps a reference to hb_face_t which is managed by HbFaceCache. Thus, - // it is good to purge hb_font_t once it is no longer necessary. - // Caller should acquire a lock before calling the method. - void purgeHbFontCache(); private: void addFontLocked(MinikinFont* typeface, FontStyle style); @@ -152,8 +147,6 @@ private: SparseBitSet mCoverage; bool mCoverageValid; - - hb_font_t* mHbFont; }; } // namespace android diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 769b5fcd816..1fd0e6e8a06 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -24,7 +24,7 @@ minikin_src_files := \ FontLanguage.cpp \ FontLanguageListCache.cpp \ GraphemeBreak.cpp \ - HbFaceCache.cpp \ + HbFontCache.cpp \ Hyphenator.cpp \ Layout.cpp \ LayoutUtils.cpp \ diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index da58fa39c9a..26aefe44906 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -410,11 +410,4 @@ uint32_t FontCollection::getId() const { return mId; } -void FontCollection::purgeFontFamilyHbFontCache() const { - assertMinikinLocked(); - for (size_t i = 0; i < mFamilies.size(); ++i) { - mFamilies[i]->purgeHbFontCache(); - } -} - } // namespace android diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 14057890281..9eda3c2498e 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -28,7 +28,7 @@ #include "FontLanguage.h" #include "FontLanguageListCache.h" -#include "HbFaceCache.h" +#include "HbFontCache.h" #include "MinikinInternal.h" #include #include @@ -189,23 +189,11 @@ const SparseBitSet* FontFamily::getCoverage() { bool FontFamily::hasVariationSelector(uint32_t codepoint, uint32_t variationSelector) { assertMinikinLocked(); - if (!mHbFont) { - const FontStyle defaultStyle; - MinikinFont* minikinFont = getClosestMatch(defaultStyle).font; - hb_face_t* face = getHbFaceLocked(minikinFont); - mHbFont = hb_font_create(face); - hb_ot_font_set_funcs(mHbFont); - } + const FontStyle defaultStyle; + MinikinFont* minikinFont = getClosestMatch(defaultStyle).font; + hb_font_t* font = getHbFontLocked(minikinFont); uint32_t unusedGlyph; - return hb_font_get_glyph(mHbFont, codepoint, variationSelector, &unusedGlyph); -} - -void FontFamily::purgeHbFontCache() { - assertMinikinLocked(); - if (mHbFont) { - hb_font_destroy(mHbFont); - mHbFont = nullptr; - } + return hb_font_get_glyph(font, codepoint, variationSelector, &unusedGlyph); } } // namespace android diff --git a/engine/src/flutter/libs/minikin/HbFaceCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp similarity index 60% rename from engine/src/flutter/libs/minikin/HbFaceCache.cpp rename to engine/src/flutter/libs/minikin/HbFontCache.cpp index 235f7f1b0c2..73308efab70 100644 --- a/engine/src/flutter/libs/minikin/HbFaceCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -16,10 +16,11 @@ #define LOG_TAG "Minikin" -#include "HbFaceCache.h" +#include "HbFontCache.h" #include #include +#include #include #include @@ -51,23 +52,23 @@ static hb_blob_t* referenceTable(hb_face_t* /* face */, hb_tag_t tag, void* user HB_MEMORY_MODE_WRITABLE, buffer, free); } -class HbFaceCache : private OnEntryRemoved { +class HbFontCache : private OnEntryRemoved { public: - HbFaceCache() : mCache(kMaxEntries) { + HbFontCache() : mCache(kMaxEntries) { mCache.setOnEntryRemovedListener(this); } // callback for OnEntryRemoved - void operator()(int32_t& /* key */, hb_face_t*& value) { - hb_face_destroy(value); + void operator()(int32_t& /* key */, hb_font_t*& value) { + hb_font_destroy(value); } - hb_face_t* get(int32_t fontId) { + hb_font_t* get(int32_t fontId) { return mCache.get(fontId); } - void put(int32_t fontId, hb_face_t* face) { - mCache.put(fontId, face); + void put(int32_t fontId, hb_font_t* font) { + mCache.put(fontId, font); } void clear() { @@ -77,39 +78,52 @@ public: private: static const size_t kMaxEntries = 100; - LruCache mCache; + LruCache mCache; }; -HbFaceCache* getFaceCacheLocked() { +HbFontCache* getFontCacheLocked() { assertMinikinLocked(); - static HbFaceCache* cache = nullptr; + static HbFontCache* cache = nullptr; if (cache == nullptr) { - cache = new HbFaceCache(); + cache = new HbFontCache(); } return cache; } -void purgeHbFaceCacheLocked() { +void purgeHbFontCacheLocked() { assertMinikinLocked(); - getFaceCacheLocked()->clear(); + getFontCacheLocked()->clear(); } -hb_face_t* getHbFaceLocked(MinikinFont* minikinFont) { +hb_font_t* getHbFontLocked(MinikinFont* minikinFont) { assertMinikinLocked(); + static hb_font_t* nullFaceFont = nullptr; if (minikinFont == nullptr) { - return nullptr; + if (nullFaceFont == nullptr) { + nullFaceFont = hb_font_create(nullptr); + } + return nullFaceFont; } - HbFaceCache* faceCache = getFaceCacheLocked(); + HbFontCache* fontCache = getFontCacheLocked(); const int32_t fontId = minikinFont->GetUniqueId(); - hb_face_t* face = faceCache->get(fontId); - if (face != nullptr) { - return face; + hb_font_t* font = fontCache->get(fontId); + if (font != nullptr) { + return font; } - face = hb_face_create_for_tables(referenceTable, minikinFont, nullptr); - faceCache->put(fontId, face); - return face; + hb_face_t* face = hb_face_create_for_tables(referenceTable, minikinFont, nullptr); + hb_font_t* parent_font = hb_font_create(face); + hb_ot_font_set_funcs(parent_font); + + unsigned int upem = hb_face_get_upem(face); + hb_font_set_scale(parent_font, upem, upem); + + font = hb_font_create_sub_font(parent_font); + hb_font_destroy(parent_font); + hb_face_destroy(face); + fontCache->put(fontId, font); + return font; } } // namespace android diff --git a/engine/src/flutter/libs/minikin/HbFaceCache.h b/engine/src/flutter/libs/minikin/HbFontCache.h similarity index 77% rename from engine/src/flutter/libs/minikin/HbFaceCache.h rename to engine/src/flutter/libs/minikin/HbFontCache.h index 8ee38c3603e..62564d35b9a 100644 --- a/engine/src/flutter/libs/minikin/HbFaceCache.h +++ b/engine/src/flutter/libs/minikin/HbFontCache.h @@ -14,16 +14,16 @@ * limitations under the License. */ -#ifndef MINIKIN_HBFACE_CACHE_H -#define MINIKIN_HBFACE_CACHE_H +#ifndef MINIKIN_HBFONT_CACHE_H +#define MINIKIN_HBFONT_CACHE_H -struct hb_face_t; +struct hb_font_t; namespace android { class MinikinFont; -void purgeHbFaceCacheLocked(); -hb_face_t* getHbFaceLocked(MinikinFont* minikinFont); +void purgeHbFontCacheLocked(); +hb_font_t* getHbFontLocked(MinikinFont* minikinFont); } // namespace android -#endif // MINIKIN_HBFACE_CACHE_H +#endif // MINIKIN_HBFONT_CACHE_H diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 2839e5b71d3..71e0d890b78 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -37,7 +37,7 @@ #include "FontLanguage.h" #include "FontLanguageListCache.h" #include "LayoutUtils.h" -#include "HbFaceCache.h" +#include "HbFontCache.h" #include "MinikinInternal.h" #include #include @@ -98,7 +98,7 @@ struct LayoutContext { void clearHbFonts() { for (size_t i = 0; i < hbFonts.size(); i++) { - hb_font_destroy(hbFonts[i]); + hb_font_set_funcs(hbFonts[i], nullptr, nullptr, nullptr); } hbFonts.clear(); } @@ -133,7 +133,6 @@ public: layout->setFontCollection(collection); layout->mAdvances.resize(mCount, 0); ctx->clearHbFonts(); - collection->purgeFontFamilyHbFontCache(); layout->doLayoutRun(mChars, mStart, mCount, mNchars, mIsRtl, ctx); } @@ -306,21 +305,6 @@ hb_font_funcs_t* getHbFontFuncs() { return hbFontFuncs; } -static hb_font_t* create_hb_font(MinikinFont* minikinFont, MinikinPaint* minikinPaint) { - hb_face_t* face = getHbFaceLocked(minikinFont); - hb_font_t* parent_font = hb_font_create(face); - hb_ot_font_set_funcs(parent_font); - - unsigned int upem = hb_face_get_upem(face); - hb_font_set_scale(parent_font, upem, upem); - - hb_font_t* font = hb_font_create_sub_font(parent_font); - hb_font_destroy(parent_font); - - hb_font_set_funcs(font, getHbFontFuncs(), minikinPaint, 0); - return font; -} - static float HBFixedToFloat(hb_position_t v) { return scalbnf (v, -8); @@ -349,7 +333,8 @@ int Layout::findFace(FakedFont face, LayoutContext* ctx) { // Note: ctx == NULL means we're copying from the cache, no need to create // corresponding hb_font object. if (ctx != NULL) { - hb_font_t* font = create_hb_font(face.font, &ctx->paint); + hb_font_t* font = getHbFontLocked(face.font); + hb_font_set_funcs(font, getHbFontFuncs(), &ctx->paint, 0); ctx->hbFonts.push_back(font); } return ix; @@ -599,7 +584,6 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu start, mCollection, this, NULL); } ctx.clearHbFonts(); - mCollection->purgeFontFamilyHbFontCache(); } float Layout::measureText(const uint16_t* buf, size_t start, size_t count, size_t bufSize, @@ -976,7 +960,7 @@ void Layout::purgeCaches() { AutoMutex _l(gMinikinLock); LayoutCache& layoutCache = LayoutEngine::getInstance().layoutCache; layoutCache.clear(); - purgeHbFaceCacheLocked(); + purgeHbFontCacheLocked(); } } // namespace android diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index 2483b763c42..d2aa5fd107f 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -75,9 +75,9 @@ LOCAL_SRC_FILES += \ FontFamilyTest.cpp \ FontLanguageListCacheTest.cpp \ FontTestUtils.cpp \ + HbFontCacheTest.cpp \ MinikinFontForTest.cpp \ GraphemeBreakTests.cpp \ - HbFaceCacheTest.cpp \ LayoutUtilsTest.cpp \ UnicodeUtils.cpp diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index 6b32689081e..fef464f1d77 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -378,18 +378,4 @@ TEST_F(FontFamilyTest, hasVariationSelectorTest) { expectVSGlyphs(&family, kNotSupportedChar, std::set()); } -TEST_F(FontFamilyTest, hasVariationSelectorWorksAfterpurgeHbFontCache) { - MinikinFontForTest minikinFont(kVsTestFont); - FontFamily family; - family.addFont(&minikinFont); - - const uint32_t kVS1 = 0xFE00; - const uint32_t kSupportedChar1 = 0x82A6; - - AutoMutex _l(gMinikinLock); - EXPECT_TRUE(family.hasVariationSelector(kSupportedChar1, kVS1)); - - family.purgeHbFontCache(); - EXPECT_TRUE(family.hasVariationSelector(kSupportedChar1, kVS1)); -} } // namespace android diff --git a/engine/src/flutter/tests/HbFaceCacheTest.cpp b/engine/src/flutter/tests/HbFaceCacheTest.cpp deleted file mode 100644 index 76eec5b5a83..00000000000 --- a/engine/src/flutter/tests/HbFaceCacheTest.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2015 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 - -#include "HbFaceCache.h" - -#include -#include -#include - -#include "MinikinInternal.h" -#include - -namespace android { -namespace { - -// A mock implementation of MinikinFont. The passed integer value will be -// returned in GetUniqueId(). -class MockMinikinFont : public MinikinFont { -public: - MockMinikinFont(int32_t id) : mId(id) { - } - - virtual float GetHorizontalAdvance(uint32_t /* glyph_id */, - const MinikinPaint& /* paint */) const { - LOG_ALWAYS_FATAL("MockMinikinFont::GetHorizontalAdvance is not implemented."); - return 0.0f; - } - - virtual void GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph_id */, - const MinikinPaint& /* paint */) const { - LOG_ALWAYS_FATAL("MockMinikinFont::GetBounds is not implemented."); - } - - virtual bool GetTable(uint32_t /* tag */, uint8_t* /* buf */, size_t* /* size */) { - LOG_ALWAYS_FATAL("MockMinikinFont::GetTable is not implemented."); - return false; - } - - virtual int32_t GetUniqueId() const { - return mId; - } - -private: - int32_t mId; -}; - -class HbFaceCacheTest : public testing::Test { -public: - virtual void TearDown() { - AutoMutex _l(gMinikinLock); - purgeHbFaceCacheLocked(); - } -}; - -TEST_F(HbFaceCacheTest, getHbFaceLockedTest) { - AutoMutex _l(gMinikinLock); - - MockMinikinFont fontA(1); - MockMinikinFont fontB(2); - MockMinikinFont fontC(2); - - // Never return NULL. - EXPECT_TRUE(getHbFaceLocked(&fontA)); - EXPECT_TRUE(getHbFaceLocked(&fontB)); - EXPECT_TRUE(getHbFaceLocked(&fontC)); - - // Must return same object if same font object is passed. - EXPECT_EQ(getHbFaceLocked(&fontA), getHbFaceLocked(&fontA)); - EXPECT_EQ(getHbFaceLocked(&fontB), getHbFaceLocked(&fontB)); - EXPECT_EQ(getHbFaceLocked(&fontC), getHbFaceLocked(&fontC)); - - // Different object must be returned if the passed minikinFont has different ID. - EXPECT_NE(getHbFaceLocked(&fontA), getHbFaceLocked(&fontB)); - EXPECT_NE(getHbFaceLocked(&fontA), getHbFaceLocked(&fontC)); - - // Same object must be returned if the minikinFont has same Id. - EXPECT_EQ(getHbFaceLocked(&fontB), getHbFaceLocked(&fontC)); -} - -TEST_F(HbFaceCacheTest, purgeCacheTest) { - AutoMutex _l(gMinikinLock); - MockMinikinFont font(1); - - hb_face_t* face = getHbFaceLocked(&font); - EXPECT_TRUE(face); - - // Set user data to identify the face object. - hb_user_data_key_t key; - void* data = (void*)0xdeadbeef; - hb_face_set_user_data(face, &key, data, NULL, false); - EXPECT_EQ(data, hb_face_get_user_data(face, &key)); - - purgeHbFaceCacheLocked(); - - // By checking user data, confirm that the object after purge is different from previously - // created one. Do not compare the returned pointer here since memory allocator may assign - // same region for new object. - face = getHbFaceLocked(&font); - EXPECT_EQ(nullptr, hb_face_get_user_data(face, &key)); -} - -} // namespace -} // namespace android diff --git a/engine/src/flutter/tests/HbFontCacheTest.cpp b/engine/src/flutter/tests/HbFontCacheTest.cpp new file mode 100644 index 00000000000..2dee61aff06 --- /dev/null +++ b/engine/src/flutter/tests/HbFontCacheTest.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2016 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 + +#include "HbFontCache.h" + +#include +#include +#include + +#include "MinikinInternal.h" +#include "MinikinFontForTest.h" +#include + +namespace android { +namespace { + +class HbFontCacheTest : public testing::Test { +public: + virtual void TearDown() { + AutoMutex _l(gMinikinLock); + purgeHbFontCacheLocked(); + } +}; + +TEST_F(HbFontCacheTest, getHbFontLockedTest) { + AutoMutex _l(gMinikinLock); + + MinikinFontForTest fontA(kTestFontDir "Regular.ttf"); + MinikinFontForTest fontB(kTestFontDir "Bold.ttf"); + MinikinFontForTest fontC(kTestFontDir "BoldItalic.ttf"); + + // Never return NULL. + EXPECT_NE(nullptr, getHbFontLocked(&fontA)); + EXPECT_NE(nullptr, getHbFontLocked(&fontB)); + EXPECT_NE(nullptr, getHbFontLocked(&fontC)); + + EXPECT_NE(nullptr, getHbFontLocked(nullptr)); + + // Must return same object if same font object is passed. + EXPECT_EQ(getHbFontLocked(&fontA), getHbFontLocked(&fontA)); + EXPECT_EQ(getHbFontLocked(&fontB), getHbFontLocked(&fontB)); + EXPECT_EQ(getHbFontLocked(&fontC), getHbFontLocked(&fontC)); + + // Different object must be returned if the passed minikinFont has different ID. + EXPECT_NE(getHbFontLocked(&fontA), getHbFontLocked(&fontB)); + EXPECT_NE(getHbFontLocked(&fontA), getHbFontLocked(&fontC)); +} + +TEST_F(HbFontCacheTest, purgeCacheTest) { + AutoMutex _l(gMinikinLock); + MinikinFontForTest minikinFont(kTestFontDir "Regular.ttf"); + + hb_font_t* font = getHbFontLocked(&minikinFont); + ASSERT_NE(nullptr, font); + + // Set user data to identify the font object. + hb_user_data_key_t key; + void* data = (void*)0xdeadbeef; + hb_font_set_user_data(font, &key, data, NULL, false); + ASSERT_EQ(data, hb_font_get_user_data(font, &key)); + + purgeHbFontCacheLocked(); + + // By checking user data, confirm that the object after purge is different from previously + // created one. Do not compare the returned pointer here since memory allocator may assign + // same region for new object. + font = getHbFontLocked(&minikinFont); + EXPECT_EQ(nullptr, hb_font_get_user_data(font, &key)); +} + +} // namespace +} // namespace android From 380658778eb18b611b37a360b246d8045cbc4c47 Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Tue, 2 Feb 2016 19:48:04 +0900 Subject: [PATCH 151/364] Optimize: Precompute the hash value for LayoutCacheKey. Bug: 24505153 Change-Id: If61c063c175086dec88cda187eafd9ce923e4cb1 --- engine/src/flutter/libs/minikin/Layout.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 71e0d890b78..3a05acfd9d6 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -114,10 +114,14 @@ public: mStart(start), mCount(count), mId(collection->getId()), mStyle(style), mSize(paint.size), mScaleX(paint.scaleX), mSkewX(paint.skewX), mLetterSpacing(paint.letterSpacing), - mPaintFlags(paint.paintFlags), mHyphenEdit(paint.hyphenEdit), mIsRtl(dir) { + mPaintFlags(paint.paintFlags), mHyphenEdit(paint.hyphenEdit), mIsRtl(dir), + mHash(computeHash()) { } bool operator==(const LayoutCacheKey &other) const; - hash_t hash() const; + + hash_t hash() const { + return mHash; + } void copyText() { uint16_t* charsCopy = new uint16_t[mNchars]; @@ -152,6 +156,9 @@ private: bool mIsRtl; // Note: any fields added to MinikinPaint must also be reflected here. // TODO: language matching (possibly integrate into style) + hash_t mHash; + + hash_t computeHash() const; }; class LayoutCache : private OnEntryRemoved { @@ -230,7 +237,7 @@ bool LayoutCacheKey::operator==(const LayoutCacheKey& other) const { && !memcmp(mChars, other.mChars, mNchars * sizeof(uint16_t)); } -hash_t LayoutCacheKey::hash() const { +hash_t LayoutCacheKey::computeHash() const { uint32_t hash = JenkinsHashMix(0, mId); hash = JenkinsHashMix(hash, mStart); hash = JenkinsHashMix(hash, mCount); From aa48a657667f30ffb878e3ccd29e7ae2c21b5b87 Mon Sep 17 00:00:00 2001 From: Aurimas Liutikas Date: Thu, 11 Feb 2016 14:27:07 -0800 Subject: [PATCH 152/364] Fix two "unused parameter" warnings in minikin sample. Removing variables in main function of sample/example.cpp as they are not used. Bug: 26936282 Change-Id: I64ae0a455b413df333ddd4810a9e090d52322041 --- engine/src/flutter/sample/example.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/flutter/sample/example.cpp b/engine/src/flutter/sample/example.cpp index 3fbfa7910e0..f4c6a07a4a6 100644 --- a/engine/src/flutter/sample/example.cpp +++ b/engine/src/flutter/sample/example.cpp @@ -99,6 +99,6 @@ int runMinikinTest() { return 0; } -int main(int argc, const char** argv) { +int main() { return runMinikinTest(); } From 09481597e453ab3ce4fd4a1b4533ff2a2c5dd23a Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Thu, 11 Feb 2016 20:38:19 -0800 Subject: [PATCH 153/364] Fix warnings. Bug: http://b/26936282 Change-Id: I91b3bc246a4a8c45bde223cfc25df18ae9af8c5b --- engine/src/flutter/include/minikin/Layout.h | 2 +- engine/src/flutter/libs/minikin/Android.mk | 4 ++-- engine/src/flutter/libs/minikin/Layout.cpp | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index cdf4aac5236..a1c7155cda3 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -59,7 +59,7 @@ struct LayoutGlyph { }; // Internal state used during layout operation -class LayoutContext; +struct LayoutContext; enum { kBidi_LTR = 0, diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 48d06c0847a..293ebde9c75 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -48,6 +48,7 @@ minikin_shared_libraries := \ LOCAL_MODULE := libminikin LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_SRC_FILES := $(minikin_src_files) +LOCAL_CFLAGS := -Wno-unused-parameter LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) LOCAL_CLANG := true @@ -60,8 +61,8 @@ include $(BUILD_SHARED_LIBRARY) include $(CLEAR_VARS) LOCAL_MODULE := libminikin -LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include +LOCAL_CFLAGS := -Wno-unused-parameter LOCAL_SRC_FILES := $(minikin_src_files) LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) @@ -77,7 +78,6 @@ include $(CLEAR_VARS) # Reduced library (currently just hyphenation) for host LOCAL_MODULE := libminikin_host -LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_SHARED_LIBRARIES := liblog libicuuc-host diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index be29e3ca2a0..e6942477b01 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -302,7 +302,7 @@ hb_blob_t* referenceTable(hb_face_t* face, hb_tag_t tag, void* userData) { return 0; } ok = font->GetTable(tag, reinterpret_cast(buffer), &length); - printf("referenceTable %c%c%c%c length=%d %d\n", + printf("referenceTable %c%c%c%c length=%zu %d\n", (tag >>24) & 0xff, (tag>>16)&0xff, (tag>>8)&0xff, tag&0xff, length, ok); if (!ok) { free(buffer); @@ -810,7 +810,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t if (info[i].cluster - start < count) { mAdvances[info[i].cluster - start] += xAdvance; } else { - ALOGE("cluster %d (start %d) out of bounds of count %d", + ALOGE("cluster %ul (start %zu) out of bounds of count %zu", info[i].cluster - start, start, count); } x += xAdvance; From 9e8fd1dff74e2c696d3fd7a2873d982bcb0b06cd Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 11 Feb 2016 11:17:44 -0800 Subject: [PATCH 154/364] Add error logging on invalid cmap This patch logs instances of fonts with invalid cmap tables. Bug: 25645298 Bug: 26413177 Change-Id: I183985e9784a97a2b4307a22e036382b1fc90e5e --- engine/src/flutter/libs/minikin/CmapCoverage.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/engine/src/flutter/libs/minikin/CmapCoverage.cpp b/engine/src/flutter/libs/minikin/CmapCoverage.cpp index 9f3447e62af..a4503af208e 100644 --- a/engine/src/flutter/libs/minikin/CmapCoverage.cpp +++ b/engine/src/flutter/libs/minikin/CmapCoverage.cpp @@ -67,6 +67,7 @@ static bool getCoverageFormat4(vector& coverage, const uint8_t* data, uint32_t start = readU16(data, kHeaderSize + 2 * (segCount + i)); if (end < start) { // invalid segment range: size must be positive + android_errorWriteLog(0x534e4554, "26413177"); return false; } uint32_t rangeOffset = readU16(data, kHeaderSize + 2 * (3 * segCount + i)); @@ -113,6 +114,7 @@ static bool getCoverageFormat12(vector& coverage, const uint8_t* data, } uint32_t nGroups = readU32(data, kNGroupsOffset); if (nGroups >= kMaxNGroups || kFirstGroupOffset + nGroups * kGroupSize > size) { + android_errorWriteLog(0x534e4554, "25645298"); return false; } for (uint32_t i = 0; i < nGroups; i++) { @@ -121,6 +123,7 @@ static bool getCoverageFormat12(vector& coverage, const uint8_t* data, uint32_t end = readU32(data, groupOffset + kEndCharCodeOffset); if (end < start) { // invalid group range: size must be positive + android_errorWriteLog(0x534e4554, "26413177"); return false; } addRange(coverage, start, end + 1); // file is inclusive, vector is exclusive From ac3b9bc4ea57584b6b98307dc505567beaeedab1 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 11 Feb 2016 11:17:44 -0800 Subject: [PATCH 155/364] Add error logging on invalid cmap - DO NOT MERGE This patch logs instances of fonts with invalid cmap tables. Bug: 25645298 Bug: 26413177 Change-Id: I183985e9784a97a2b4307a22e036382b1fc90e5e --- engine/src/flutter/libs/minikin/CmapCoverage.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/engine/src/flutter/libs/minikin/CmapCoverage.cpp b/engine/src/flutter/libs/minikin/CmapCoverage.cpp index 4c9643a1d4a..d77253b114f 100644 --- a/engine/src/flutter/libs/minikin/CmapCoverage.cpp +++ b/engine/src/flutter/libs/minikin/CmapCoverage.cpp @@ -20,6 +20,9 @@ #include #endif +#define LOG_TAG "Minikin" +#include + #include using std::vector; @@ -68,6 +71,7 @@ static bool getCoverageFormat4(vector& coverage, const uint8_t* data, uint32_t start = readU16(data, kHeaderSize + 2 * (segCount + i)); if (end < start) { // invalid segment range: size must be positive + android_errorWriteLog(0x534e4554, "26413177"); return false; } uint32_t rangeOffset = readU16(data, kHeaderSize + 2 * (3 * segCount + i)); @@ -113,6 +117,7 @@ static bool getCoverageFormat12(vector& coverage, const uint8_t* data, } uint32_t nGroups = readU32(data, kNGroupsOffset); if (nGroups >= kMaxNGroups || kFirstGroupOffset + nGroups * kGroupSize > size) { + android_errorWriteLog(0x534e4554, "25645298"); return false; } for (uint32_t i = 0; i < nGroups; i++) { @@ -121,6 +126,7 @@ static bool getCoverageFormat12(vector& coverage, const uint8_t* data, uint32_t end = readU32(data, groupOffset + kEndCharCodeOffset); if (end < start) { // invalid group range: size must be positive + android_errorWriteLog(0x534e4554, "26413177"); return false; } addRange(coverage, start, end + 1); // file is inclusive, vector is exclusive From c3b16d88941b337c2b0b861daf610bf9ca80f908 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 4 Sep 2015 17:23:05 -0700 Subject: [PATCH 156/364] Refine hyphenation around punctuation Implement a WordBreaker that defines our concept of valid word boundaries, customizing the ICU behavior. Currently, we suppress line breaks at soft hyphens (these are handled specially). Also, the new WordBreaker class has methods that determine the start and end of the word (punctuation stripped) for the purpose of hyphenation. This patch, in its current form, doesn't handle email addresses and URLs specially, but the WordBreaker class is the correct place to do so. Also, special case handling of hyphens and dashes is still done in LineBreaker, but all of that should be moved to WordBreaker. Bug: 20126487 Bug: 20566159 Change-Id: I492cbad963f9b74a2915f010dad46bb91f97b2fe --- .../src/flutter/include/minikin/LineBreaker.h | 9 +- .../src/flutter/include/minikin/WordBreaker.h | 67 +++++++++++ engine/src/flutter/libs/minikin/Android.mk | 3 +- .../src/flutter/libs/minikin/LineBreaker.cpp | 107 ++++++++--------- .../src/flutter/libs/minikin/WordBreaker.cpp | 110 ++++++++++++++++++ engine/src/flutter/tests/Android.mk | 3 +- engine/src/flutter/tests/WordBreakerTests.cpp | 79 +++++++++++++ 7 files changed, 311 insertions(+), 67 deletions(-) create mode 100644 engine/src/flutter/include/minikin/WordBreaker.h create mode 100644 engine/src/flutter/libs/minikin/WordBreaker.cpp create mode 100644 engine/src/flutter/tests/WordBreakerTests.cpp diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index e031fb3182c..e28f11da447 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -27,6 +27,7 @@ #include #include #include "minikin/Hyphenator.h" +#include "minikin/WordBreaker.h" namespace android { @@ -102,11 +103,6 @@ class LineBreaker { public: const static int kTab_Shift = 29; // keep synchronized with TAB_MASK in StaticLayout.java - ~LineBreaker() { - utext_close(&mUText); - delete mBreakIterator; - } - // Note: Locale persists across multiple invocations (it is not cleaned up by finish()), // explicitly to avoid the cost of creating ICU BreakIterator objects. It should always // be set on the first invocation, but callers are encouraged not to call again unless @@ -214,8 +210,7 @@ class LineBreaker { void finishBreaksOptimal(); - icu::BreakIterator* mBreakIterator = nullptr; - UText mUText = UTEXT_INITIALIZER; + WordBreaker mWordBreaker; std::vectormTextBuf; std::vectormCharWidths; diff --git a/engine/src/flutter/include/minikin/WordBreaker.h b/engine/src/flutter/include/minikin/WordBreaker.h new file mode 100644 index 00000000000..22275bde847 --- /dev/null +++ b/engine/src/flutter/include/minikin/WordBreaker.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2015 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. + */ + +/** + * A wrapper around ICU's line break iterator, that gives customized line + * break opportunities, as well as identifying words for the purpose of + * hyphenation. + */ + +#ifndef MINIKIN_WORD_BREAKER_H +#define MINIKIN_WORD_BREAKER_H + +#include "unicode/brkiter.h" +#include + +namespace android { + +class WordBreaker { +public: + ~WordBreaker() { + finish(); + } + + void setLocale(const icu::Locale& locale); + + void setText(const uint16_t* data, size_t size); + + // Advance iterator to next word break. Return offset, or -1 if EOT + ssize_t next(); + + // Current offset of iterator, equal to 0 at BOT or last return from next() + ssize_t current() const; + + // After calling next(), wordStart() and wordEnd() are offsets defining the previous + // word. If wordEnd <= wordStart, it's not a word for the purpose of hyphenation. + ssize_t wordStart() const; + + ssize_t wordEnd() const; + + void finish(); + +private: + std::unique_ptr mBreakIterator; + UText mUText = UTEXT_INITIALIZER; + const uint16_t* mText = nullptr; + size_t mTextSize; + ssize_t mLast; + ssize_t mCurrent; + bool mIteratorWasReset; +}; + +} // namespace + +#endif // MINIKIN_WORD_BREAKER_H diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 1fd0e6e8a06..7cd6f6883cc 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -33,7 +33,8 @@ minikin_src_files := \ MinikinInternal.cpp \ MinikinRefCounted.cpp \ MinikinFontFreeType.cpp \ - SparseBitSet.cpp + SparseBitSet.cpp \ + WordBreaker.cpp minikin_c_includes := \ external/harfbuzz_ng/src \ diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index a2507e0ba87..214f19599d3 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -29,7 +29,6 @@ using std::vector; namespace android { const int CHAR_TAB = 0x0009; -const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; // Large scores in a hierarchy; we prefer desperate breaks to an overfull line. All these // constants are larger than any reasonable actual width score. @@ -55,23 +54,16 @@ const size_t LONGEST_HYPHENATED_WORD = 45; const size_t MAX_TEXT_BUF_RETAIN = 32678; void LineBreaker::setLocale(const icu::Locale& locale, Hyphenator* hyphenator) { - delete mBreakIterator; - UErrorCode status = U_ZERO_ERROR; - mBreakIterator = icu::BreakIterator::createLineInstance(locale, status); - // TODO: check status + mWordBreaker.setLocale(locale); - // TODO: load actual resource dependent on locale; letting Minikin do it is a hack mHyphenator = hyphenator; } void LineBreaker::setText() { - UErrorCode status = U_ZERO_ERROR; - utext_openUChars(&mUText, mTextBuf.data(), mTextBuf.size(), &status); - mBreakIterator->setText(&mUText, status); - mBreakIterator->first(); + mWordBreaker.setText(mTextBuf.data(), mTextBuf.size()); // handle initial break here because addStyleRun may never be called - mBreakIterator->next(); + mWordBreaker.next(); mCandidates.clear(); Candidate cand = {0, 0, 0.0, 0.0, 0.0, 0.0, 0, 0}; mCandidates.push_back(cand); @@ -151,8 +143,8 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa mLinePenalty = std::max(mLinePenalty, hyphenPenalty * LINE_PENALTY_MULTIPLIER); } - size_t current = (size_t)mBreakIterator->current(); - size_t wordEnd = start; + size_t current = (size_t)mWordBreaker.current(); + size_t afterWord = start; size_t lastBreak = start; ParaWidth lastBreakWidth = mWidth; ParaWidth postBreak = mWidth; @@ -170,58 +162,56 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa mWidth += mCharWidths[i]; if (!isLineEndSpace(c)) { postBreak = mWidth; - wordEnd = i + 1; + afterWord = i + 1; } } if (i + 1 == current) { - // Override ICU's treatment of soft hyphen as a break opportunity, because we want it - // to be a hyphen break, with penalty and drawing behavior. - if (c != CHAR_SOFT_HYPHEN) { - // TODO: Add a new type of HyphenEdit for breaks whose hyphen already exists, so - // we can pass the whole word down to Hyphenator like the soft hyphen case. - bool wordEndsInHyphen = isLineBreakingHyphen(c); - if (paint != nullptr && mHyphenator != nullptr && - mHyphenationFrequency != kHyphenationFrequency_None && - !wordEndsInHyphen && !temporarilySkipHyphenation && - wordEnd > lastBreak && wordEnd - lastBreak <= LONGEST_HYPHENATED_WORD) { - mHyphenator->hyphenate(&mHyphBuf, &mTextBuf[lastBreak], wordEnd - lastBreak); - #if VERBOSE_DEBUG - std::string hyphenatedString; - for (size_t j = lastBreak; j < wordEnd; j++) { - if (mHyphBuf[j - lastBreak]) hyphenatedString.push_back('-'); - // Note: only works with ASCII, should do UTF-8 conversion here - hyphenatedString.push_back(buffer()[j]); - } - ALOGD("hyphenated string: %s", hyphenatedString.c_str()); - #endif + // TODO: Add a new type of HyphenEdit for breaks whose hyphen already exists, so + // we can pass the whole word down to Hyphenator like the soft hyphen case. + bool wordEndsInHyphen = isLineBreakingHyphen(c); + size_t wordStart = mWordBreaker.wordStart(); + size_t wordEnd = mWordBreaker.wordEnd(); + if (paint != nullptr && mHyphenator != nullptr && + mHyphenationFrequency != kHyphenationFrequency_None && + !wordEndsInHyphen && !temporarilySkipHyphenation && + wordEnd > wordStart && wordEnd - wordStart <= LONGEST_HYPHENATED_WORD) { + mHyphenator->hyphenate(&mHyphBuf, &mTextBuf[wordStart], wordEnd - wordStart); +#if VERBOSE_DEBUG + std::string hyphenatedString; + for (size_t j = wordStart; j < wordEnd; j++) { + if (mHyphBuf[j - wordStart]) hyphenatedString.push_back('-'); + // Note: only works with ASCII, should do UTF-8 conversion here + hyphenatedString.push_back(buffer()[j]); + } + ALOGD("hyphenated string: %s", hyphenatedString.c_str()); +#endif - // measure hyphenated substrings - for (size_t j = lastBreak; j < wordEnd; j++) { - uint8_t hyph = mHyphBuf[j - lastBreak]; - if (hyph) { - paint->hyphenEdit = hyph; - layout.doLayout(mTextBuf.data(), lastBreak, j - lastBreak, - mTextBuf.size(), bidiFlags, style, *paint); - ParaWidth hyphPostBreak = lastBreakWidth + layout.getAdvance(); - paint->hyphenEdit = 0; - layout.doLayout(mTextBuf.data(), j, wordEnd - j, - mTextBuf.size(), bidiFlags, style, *paint); - ParaWidth hyphPreBreak = postBreak - layout.getAdvance(); - addWordBreak(j, hyphPreBreak, hyphPostBreak, hyphenPenalty, hyph); - } + // measure hyphenated substrings + for (size_t j = wordStart; j < wordEnd; j++) { + uint8_t hyph = mHyphBuf[j - wordStart]; + if (hyph) { + paint->hyphenEdit = hyph; + layout.doLayout(mTextBuf.data(), lastBreak, j - lastBreak, + mTextBuf.size(), bidiFlags, style, *paint); + ParaWidth hyphPostBreak = lastBreakWidth + layout.getAdvance(); + paint->hyphenEdit = 0; + layout.doLayout(mTextBuf.data(), j, afterWord - j, + mTextBuf.size(), bidiFlags, style, *paint); + ParaWidth hyphPreBreak = postBreak - layout.getAdvance(); + addWordBreak(j, hyphPreBreak, hyphPostBreak, hyphenPenalty, hyph); } } - // Skip hyphenating the next word if and only if the present word ends in a hyphen - temporarilySkipHyphenation = wordEndsInHyphen; - - // Skip break for zero-width characters inside replacement span - if (paint != nullptr || current == end || mCharWidths[current] > 0) { - addWordBreak(current, mWidth, postBreak, 0.0, 0); - } - lastBreak = current; - lastBreakWidth = mWidth; } - current = (size_t)mBreakIterator->next(); + // Skip hyphenating the next word if and only if the present word ends in a hyphen + temporarilySkipHyphenation = wordEndsInHyphen; + + // Skip break for zero-width characters inside replacement span + if (paint != nullptr || current == end || mCharWidths[current] > 0) { + addWordBreak(current, mWidth, postBreak, 0.0, 0); + } + lastBreak = current; + lastBreakWidth = mWidth; + current = (size_t)mWordBreaker.next(); } } @@ -425,6 +415,7 @@ size_t LineBreaker::computeBreaks() { } void LineBreaker::finish() { + mWordBreaker.finish(); mWidth = 0; mCandidates.clear(); mBreaks.clear(); diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp new file mode 100644 index 00000000000..b422a62af85 --- /dev/null +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2015 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. + */ + +#define LOG_TAG "Minikin" +#include + +#include "minikin/WordBreaker.h" + +#include +#include + +namespace android { + +const uint32_t CHAR_SOFT_HYPHEN = 0x00AD; + +void WordBreaker::setLocale(const icu::Locale& locale) { + UErrorCode status = U_ZERO_ERROR; + mBreakIterator.reset(icu::BreakIterator::createLineInstance(locale, status)); + // TODO: handle failure status + if (mText != nullptr) { + mBreakIterator->setText(&mUText, status); + } + mIteratorWasReset = true; +} + +void WordBreaker::setText(const uint16_t* data, size_t size) { + mText = data; + mTextSize = size; + mIteratorWasReset = false; + mLast = 0; + mCurrent = 0; + UErrorCode status = U_ZERO_ERROR; + utext_openUChars(&mUText, data, size, &status); + mBreakIterator->setText(&mUText, status); + mBreakIterator->first(); +} + +ssize_t WordBreaker::current() const { + return mCurrent; +} + +ssize_t WordBreaker::next() { + int32_t result; + mLast = mCurrent; + do { + if (mIteratorWasReset) { + result = mBreakIterator->following(mCurrent); + mIteratorWasReset = false; + } else { + result = mBreakIterator->next(); + } + } while (result != icu::BreakIterator::DONE && (size_t)result != mTextSize + && mText[result - 1] == CHAR_SOFT_HYPHEN); + mCurrent = (ssize_t)result; + return mCurrent; +} + +ssize_t WordBreaker::wordStart() const { + ssize_t result = mLast; + while (result < mCurrent) { + UChar32 c; + ssize_t ix = result; + U16_NEXT(mText, ix, mCurrent, c); + int32_t lb = u_getIntPropertyValue(c, UCHAR_LINE_BREAK); + // strip leading punctuation, defined as OP and QU line breaking classes, + // see UAX #14 + if (!(lb == U_LB_OPEN_PUNCTUATION || lb == U_LB_QUOTATION)) { + break; + } + result = ix; + } + return result; +} + +ssize_t WordBreaker::wordEnd() const { + ssize_t result = mCurrent; + while (result > mLast) { + UChar32 c; + ssize_t ix = result; + U16_PREV(mText, mLast, ix, c); + int32_t gc_mask = U_GET_GC_MASK(c); + // strip trailing space and punctuation + if ((gc_mask & (U_GC_ZS_MASK | U_GC_P_MASK)) == 0) { + break; + } + result = ix; + } + return result; +} + +void WordBreaker::finish() { + mText = nullptr; + // Note: calling utext_close multiply is safe + utext_close(&mUText); +} + +} // namespace android diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index d2aa5fd107f..e6586d7178c 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -79,7 +79,8 @@ LOCAL_SRC_FILES += \ MinikinFontForTest.cpp \ GraphemeBreakTests.cpp \ LayoutUtilsTest.cpp \ - UnicodeUtils.cpp + UnicodeUtils.cpp \ + WordBreakerTests.cpp LOCAL_C_INCLUDES := \ $(LOCAL_PATH)/../libs/minikin/ \ diff --git a/engine/src/flutter/tests/WordBreakerTests.cpp b/engine/src/flutter/tests/WordBreakerTests.cpp new file mode 100644 index 00000000000..d389d58cd1b --- /dev/null +++ b/engine/src/flutter/tests/WordBreakerTests.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2015 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 +#include "ICUTestBase.h" +#include "UnicodeUtils.h" +#include +#include +#include +#include + +#define LOG_TAG "Minikin" +#include + +#ifndef NELEM +#define NELEM(x) ((sizeof(x) / sizeof((x)[0]))) +#endif + +using namespace android; + +typedef ICUTestBase WordBreakerTest; + +TEST_F(WordBreakerTest, basic) { + uint16_t buf[] = {'h', 'e', 'l', 'l' ,'o', ' ', 'w', 'o', 'r', 'l', 'd'}; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(6, breaker.next()); // after "hello " + EXPECT_EQ(0, breaker.wordStart()); // "hello" + EXPECT_EQ(5, breaker.wordEnd()); + EXPECT_EQ(6, breaker.current()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_EQ(6, breaker.wordStart()); // "world" + EXPECT_EQ(11, breaker.wordEnd()); + EXPECT_EQ(11, breaker.current()); +} + +TEST_F(WordBreakerTest, softHyphen) { + uint16_t buf[] = {'h', 'e', 'l', 0x00AD, 'l' ,'o', ' ', 'w', 'o', 'r', 'l', 'd'}; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(7, breaker.next()); // after "hel{SOFT HYPHEN}lo " + EXPECT_EQ(0, breaker.wordStart()); // "hel{SOFT HYPHEN}lo" + EXPECT_EQ(6, breaker.wordEnd()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_EQ(7, breaker.wordStart()); // "world" + EXPECT_EQ(12, breaker.wordEnd()); +} + +TEST_F(WordBreakerTest, punct) { + uint16_t buf[] = {0x00A1, 0x00A1, 'h', 'e', 'l', 'l' ,'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', + '!', '!'}; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(9, breaker.next()); // after "¡¡hello, " + EXPECT_EQ(2, breaker.wordStart()); // "hello" + EXPECT_EQ(7, breaker.wordEnd()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_EQ(9, breaker.wordStart()); // "world" + EXPECT_EQ(14, breaker.wordEnd()); +} From 650392314e87e94c252b5792bd51d55bb0db4303 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 2 Feb 2016 15:42:37 +0900 Subject: [PATCH 157/364] Improve Paint.measureText and Paint.hasGlyph for variation sequences. Before this patch, the font fallback chain iterated all installed font families if a variation selector was specified. This CL narrows down the range of iteration. To decide the font family for the variation sequence, we need to search for both the variation sequence and its base code point. The new range of the iteration is a union of them. With this change, the running time of Paint.hasGlyph for the variation sequence improves 50% and the running time of Paint.measureText for the variation sequence improves 40% for the large text case on Nexus 6 userdebug. Bug: 26784699 Bug: 11750374 Change-Id: Iced1349e3ca750821d8882c551551f65bb569794 --- .../flutter/include/minikin/CmapCoverage.h | 3 +- .../flutter/include/minikin/FontCollection.h | 3 ++ .../src/flutter/include/minikin/FontFamily.h | 10 ++++- .../src/flutter/libs/minikin/CmapCoverage.cpp | 13 +++++- .../flutter/libs/minikin/FontCollection.cpp | 41 ++++++++++++------- .../src/flutter/libs/minikin/FontFamily.cpp | 12 +++++- engine/src/flutter/tests/FontFamilyTest.cpp | 27 ++++++++++++ 7 files changed, 91 insertions(+), 18 deletions(-) diff --git a/engine/src/flutter/include/minikin/CmapCoverage.h b/engine/src/flutter/include/minikin/CmapCoverage.h index 7054e315fdc..56abac7bec3 100644 --- a/engine/src/flutter/include/minikin/CmapCoverage.h +++ b/engine/src/flutter/include/minikin/CmapCoverage.h @@ -23,7 +23,8 @@ namespace android { class CmapCoverage { public: - static bool getCoverage(SparseBitSet &coverage, const uint8_t* cmap_data, size_t cmap_size); + static bool getCoverage(SparseBitSet &coverage, const uint8_t* cmap_data, size_t cmap_size, + bool* has_cmap_format14_subtable); }; } // namespace android diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 3a63c079480..5b9424c958b 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -89,6 +89,9 @@ private: // This vector contains pointers into mInstances std::vector mFamilyVec; + // This vector has pointers to the font family instance which has cmap 14 subtable. + std::vector mVSFamilyVec; + // These are offsets into mInstanceVec, one range per page std::vector mRanges; }; diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 2b59160ffad..149dc7b798d 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -104,7 +104,11 @@ public: FontFamily(int variant); - FontFamily(uint32_t langId, int variant) : mLangId(langId), mVariant(variant) { + FontFamily(uint32_t langId, int variant) + : mLangId(langId), + mVariant(variant), + mHasVSTable(false), + mCoverageValid(false) { } ~FontFamily(); @@ -131,6 +135,9 @@ public: // Caller should acquire a lock before calling the method. bool hasVariationSelector(uint32_t codepoint, uint32_t variationSelector); + // Returns true if this font family has a variaion sequence table (cmap format 14 subtable). + bool hasVSTable() const; + private: void addFontLocked(MinikinFont* typeface, FontStyle style); @@ -146,6 +153,7 @@ private: std::vector mFonts; SparseBitSet mCoverage; + bool mHasVSTable; bool mCoverageValid; }; diff --git a/engine/src/flutter/libs/minikin/CmapCoverage.cpp b/engine/src/flutter/libs/minikin/CmapCoverage.cpp index 9f3447e62af..7d8446a44b7 100644 --- a/engine/src/flutter/libs/minikin/CmapCoverage.cpp +++ b/engine/src/flutter/libs/minikin/CmapCoverage.cpp @@ -128,7 +128,8 @@ static bool getCoverageFormat12(vector& coverage, const uint8_t* data, return true; } -bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, size_t cmap_size) { +bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, size_t cmap_size, + bool* has_cmap_format14_subtable) { vector coverageVec; const size_t kHeaderSize = 4; const size_t kNumTablesOffset = 2; @@ -136,8 +137,10 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, const size_t kPlatformIdOffset = 0; const size_t kEncodingIdOffset = 2; const size_t kOffsetOffset = 4; + const uint16_t kUnicodePlatformId = 0; const uint16_t kMicrosoftPlatformId = 3; const uint16_t kUnicodeBmpEncodingId = 1; + const uint16_t kVariationSequencesEncodingId = 5; const uint16_t kUnicodeUcs4EncodingId = 10; const uint32_t kNoTable = UINT32_MAX; if (kHeaderSize > cmap_size) { @@ -148,6 +151,7 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, return false; } uint32_t bestTable = kNoTable; + bool hasCmapFormat14Subtable = false; for (uint32_t i = 0; i < numTables; i++) { uint16_t platformId = readU16(cmap_data, kHeaderSize + i * kTableSize + kPlatformIdOffset); uint16_t encodingId = readU16(cmap_data, kHeaderSize + i * kTableSize + kEncodingIdOffset); @@ -156,8 +160,15 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, break; } else if (platformId == kMicrosoftPlatformId && encodingId == kUnicodeBmpEncodingId) { bestTable = i; + } else if (platformId == kUnicodePlatformId && + encodingId == kVariationSequencesEncodingId) { + uint32_t offset = readU32(cmap_data, kHeaderSize + i * kTableSize + kOffsetOffset); + if (offset <= cmap_size - 2 && readU16(cmap_data, offset) == 14) { + hasCmapFormat14Subtable = true; + } } } + *has_cmap_format14_subtable = hasCmapFormat14Subtable; #ifdef VERBOSE_DEBUG ALOGD("best table = %d\n", bestTable); #endif diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 26aefe44906..dd905a3442f 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -62,6 +62,9 @@ FontCollection::FontCollection(const vector& typefaces) : continue; } mFamilies.push_back(family); // emplace_back would be better + if (family->hasVSTable()) { + mVSFamilyVec.push_back(family); + } mMaxChar = max(mMaxChar, coverage->length()); lastChar.push_back(coverage->nextSetBit(0)); } @@ -233,15 +236,22 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, return NULL; } - // Even if the font supports variation sequence, mRanges isn't aware of the base character of - // the sequence. Search all FontFamilies if variation sequence is specified. - // TODO: Always use mRanges for font search. - const std::vector& familyVec = (vs == 0) ? mFamilyVec : mFamilies; - Range range; - if (vs == 0) { - range = mRanges[ch >> kLogCharsPerPage]; - } else { - range = { 0, mFamilies.size() }; + const std::vector* familyVec = &mFamilyVec; + Range range = mRanges[ch >> kLogCharsPerPage]; + + std::vector familyVecForVS; + if (vs != 0) { + // If variation selector is specified, need to search for both the variation sequence and + // its base codepoint. Compute the union vector of them. + familyVecForVS = mVSFamilyVec; + familyVecForVS.insert(familyVecForVS.end(), + mFamilyVec.begin() + range.start, mFamilyVec.begin() + range.end); + std::sort(familyVecForVS.begin(), familyVecForVS.end()); + auto last = std::unique(familyVecForVS.begin(), familyVecForVS.end()); + familyVecForVS.erase(last, familyVecForVS.end()); + + familyVec = &familyVecForVS; + range = { 0, familyVecForVS.size() }; } #ifdef VERBOSE_DEBUG @@ -250,7 +260,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, FontFamily* bestFamily = nullptr; uint32_t bestScore = kUnsupportedFontScore; for (size_t i = range.start; i < range.end; i++) { - FontFamily* family = familyVec[i]; + FontFamily* family = (*familyVec)[i]; const uint32_t score = calcFamilyScore(ch, vs, variant, langListId, family); if (score == kFirstFontScore) { // If the first font family supports the given character or variation sequence, always @@ -310,12 +320,15 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, if (baseCodepoint >= mMaxChar) { return false; } + if (variationSelector == 0) { + return false; + } + // Currently mRanges can not be used here since it isn't aware of the variation sequence. - // TODO: Use mRanges for narrowing down the search range. - for (size_t i = 0; i < mFamilies.size(); i++) { + for (size_t i = 0; i < mVSFamilyVec.size(); i++) { AutoMutex _l(gMinikinLock); - if (mFamilies[i]->hasVariationSelector(baseCodepoint, variationSelector)) { - return true; + if (mVSFamilyVec[i]->hasVariationSelector(baseCodepoint, variationSelector)) { + return true; } } return false; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 9eda3c2498e..88448a10fd0 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -177,7 +177,8 @@ const SparseBitSet* FontFamily::getCoverage() { ALOGE("Unexpected failure to read cmap table!\n"); return nullptr; } - CmapCoverage::getCoverage(mCoverage, cmapData.get(), cmapSize); // TODO: Error check? + // TODO: Error check? + CmapCoverage::getCoverage(mCoverage, cmapData.get(), cmapSize, &mHasVSTable); #ifdef VERBOSE_DEBUG ALOGD("font coverage length=%d, first ch=%x\n", mCoverage.length(), mCoverage.nextSetBit(0)); @@ -189,6 +190,10 @@ const SparseBitSet* FontFamily::getCoverage() { bool FontFamily::hasVariationSelector(uint32_t codepoint, uint32_t variationSelector) { assertMinikinLocked(); + if (!mHasVSTable) { + return false; + } + const FontStyle defaultStyle; MinikinFont* minikinFont = getClosestMatch(defaultStyle).font; hb_font_t* font = getHbFontLocked(minikinFont); @@ -196,4 +201,9 @@ bool FontFamily::hasVariationSelector(uint32_t codepoint, uint32_t variationSele return hb_font_get_glyph(font, codepoint, variationSelector, &unusedGlyph); } +bool FontFamily::hasVSTable() const { + LOG_ALWAYS_FATAL_IF(!mCoverageValid, "Do not call this method before getCoverage() call"); + return mHasVSTable; +} + } // namespace android diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index fef464f1d77..11407a3722e 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -378,4 +378,31 @@ TEST_F(FontFamilyTest, hasVariationSelectorTest) { expectVSGlyphs(&family, kNotSupportedChar, std::set()); } +TEST_F(FontFamilyTest, hasVSTableTest) { + struct TestCase { + const std::string fontPath; + bool hasVSTable; + } testCases[] = { + { kTestFontDir "Ja.ttf", true }, + { kTestFontDir "ZhHant.ttf", true }, + { kTestFontDir "ZhHans.ttf", true }, + { kTestFontDir "Italic.ttf", false }, + { kTestFontDir "Bold.ttf", false }, + { kTestFontDir "BoldItalic.ttf", false }, + }; + + for (auto testCase : testCases) { + SCOPED_TRACE(testCase.hasVSTable ? + "Font " + testCase.fontPath + " should have a variation sequence table." : + "Font " + testCase.fontPath + " shouldn't have a variation sequence table."); + + MinikinFontForTest minikinFont(testCase.fontPath); + FontFamily family; + family.addFont(&minikinFont); + family.getCoverage(); + + EXPECT_EQ(testCase.hasVSTable, family.hasVSTable()); + } +} + } // namespace android From 76022a08e3f01db804d97c10277ee2704ef68f45 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 8 Sep 2015 17:12:10 -0700 Subject: [PATCH 158/364] Special-case URLs and email addresses for line breaking Detect URLs and email addresses, and suppress both line breaking and hyphenation within them. Bug: 20126487 Bug: 20566159 Change-Id: I43629347a063dcf579e355e5b678d7195f453ad9 --- .../src/flutter/include/minikin/WordBreaker.h | 4 ++ .../src/flutter/libs/minikin/WordBreaker.cpp | 61 +++++++++++++++- engine/src/flutter/tests/WordBreakerTests.cpp | 70 +++++++++++++++++++ 3 files changed, 134 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/include/minikin/WordBreaker.h b/engine/src/flutter/include/minikin/WordBreaker.h index 22275bde847..8c0050236e2 100644 --- a/engine/src/flutter/include/minikin/WordBreaker.h +++ b/engine/src/flutter/include/minikin/WordBreaker.h @@ -60,6 +60,10 @@ private: ssize_t mLast; ssize_t mCurrent; bool mIteratorWasReset; + + // state for the email address / url detector + ssize_t mScanOffset; + bool mSuppressHyphen; }; } // namespace diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index b422a62af85..f438cd5546e 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -42,6 +42,8 @@ void WordBreaker::setText(const uint16_t* data, size_t size) { mIteratorWasReset = false; mLast = 0; mCurrent = 0; + mScanOffset = 0; + mSuppressHyphen = false; UErrorCode status = U_ZERO_ERROR; utext_openUChars(&mUText, data, size, &status); mBreakIterator->setText(&mUText, status); @@ -52,9 +54,60 @@ ssize_t WordBreaker::current() const { return mCurrent; } +enum ScanState { + START, + SAW_AT, + SAW_COLON, + SAW_COLON_SLASH, + SAW_COLON_SLASH_SLASH, +}; + ssize_t WordBreaker::next() { - int32_t result; mLast = mCurrent; + + // scan forward from current ICU position for email address or URL + if (mLast >= mScanOffset) { + ScanState state = START; + size_t i; + for (i = mLast; i < mTextSize; i++) { + uint16_t c = mText[i]; + // scan only ASCII characters, stop at space + if (!(' ' < c && c <= 0x007E)) { + break; + } + if (state == START && c == '@') { + state = SAW_AT; + } else if (state == START && c == ':') { + state = SAW_COLON; + } else if (state == SAW_COLON || state == SAW_COLON_SLASH) { + if (c == '/') { + state = static_cast((int)state + 1); // next state adds a slash + } else { + state = START; + } + } + } + if (state == SAW_AT || state == SAW_COLON_SLASH_SLASH) { + // no line breaks in entire email address or url + // TODO: refine this according to Chicago Manual of Style rules + while (i < mTextSize && mText[i] == ' ') { + i++; + } + mCurrent = i; + mSuppressHyphen = true; + // Setting mIteratorWasReset will cause next break to be computed following + // mCurrent, rather than following the current ICU iterator location. + mIteratorWasReset = true; + if (mBreakIterator->isBoundary(mCurrent)) { + return mCurrent; + } + } else { + mScanOffset = i; + mSuppressHyphen = false; + } + } + + int32_t result; do { if (mIteratorWasReset) { result = mBreakIterator->following(mCurrent); @@ -69,6 +122,9 @@ ssize_t WordBreaker::next() { } ssize_t WordBreaker::wordStart() const { + if (mSuppressHyphen) { + return mLast; + } ssize_t result = mLast; while (result < mCurrent) { UChar32 c; @@ -86,6 +142,9 @@ ssize_t WordBreaker::wordStart() const { } ssize_t WordBreaker::wordEnd() const { + if (mSuppressHyphen) { + return mLast; + } ssize_t result = mCurrent; while (result > mLast) { UChar32 c; diff --git a/engine/src/flutter/tests/WordBreakerTests.cpp b/engine/src/flutter/tests/WordBreakerTests.cpp index d389d58cd1b..4111a1b1f4c 100644 --- a/engine/src/flutter/tests/WordBreakerTests.cpp +++ b/engine/src/flutter/tests/WordBreakerTests.cpp @@ -77,3 +77,73 @@ TEST_F(WordBreakerTest, punct) { EXPECT_EQ(9, breaker.wordStart()); // "world" EXPECT_EQ(14, breaker.wordEnd()); } + +TEST_F(WordBreakerTest, email) { + uint16_t buf[] = {'f', 'o', 'o', '@', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', + ' ', 'x'}; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(16, breaker.next()); // after "foo@example.com " + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_EQ(16, breaker.wordStart()); // "x" + EXPECT_EQ(17, breaker.wordEnd()); +} + +TEST_F(WordBreakerTest, mailto) { + uint16_t buf[] = {'m', 'a', 'i', 'l', 't', 'o', ':', 'f', 'o', 'o', '@', + 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', ' ', 'x'}; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(23, breaker.next()); // after "mailto:foo@example.com " + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_EQ(23, breaker.wordStart()); // "x" + EXPECT_EQ(24, breaker.wordEnd()); +} + +TEST_F(WordBreakerTest, emailNonAscii) { + uint16_t buf[] = {'f', 'o', 'o', '@', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', + 0x4E00}; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(15, breaker.next()); // after "foo@example.com" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_EQ(15, breaker.wordStart()); // "一" + EXPECT_EQ(16, breaker.wordEnd()); +} + +TEST_F(WordBreakerTest, emailCombining) { + uint16_t buf[] = {'f', 'o', 'o', '@', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', + 0x0303, ' ', 'x'}; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(17, breaker.next()); // after "foo@example.com̃" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_EQ(17, breaker.wordStart()); // "x" + EXPECT_EQ(18, breaker.wordEnd()); +} + +TEST_F(WordBreakerTest, url) { + uint16_t buf[] = {'h', 't', 't', 'p', ':', '/', '/', 'e', 'x', 'a', 'm', 'p', 'l', 'e', + '.', 'c', 'o', 'm', ' ', 'x'}; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(19, breaker.next()); // after "http://example.com " + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_EQ(19, breaker.wordStart()); // "x" + EXPECT_EQ(20, breaker.wordEnd()); +} From 5102c20dd50fde7ab9cdcdce173f53a6cacbd9e0 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 8 Sep 2015 18:19:53 -0700 Subject: [PATCH 159/364] Add line breaks to email addresses and URLs This change adds accceptable line breaks according to sections 7.42 (Dividing URLs and e-mail addresses) and 14.12 (URLs or DOIs and line breaks) of the Chicago Manual of Style (16th ed.). In general, these place breaks before punctuation symbols, and suppresses them after hyphens. Bug: 20126487 Bug: 20566159 Change-Id: I2d07d516b920a506a2f718c38fb435c5eb1ee1f8 --- .../src/flutter/include/minikin/WordBreaker.h | 2 +- .../src/flutter/libs/minikin/WordBreaker.cpp | 65 ++++++--- engine/src/flutter/tests/WordBreakerTests.cpp | 130 +++++++++++++++++- 3 files changed, 175 insertions(+), 22 deletions(-) diff --git a/engine/src/flutter/include/minikin/WordBreaker.h b/engine/src/flutter/include/minikin/WordBreaker.h index 8c0050236e2..c4aa1514a05 100644 --- a/engine/src/flutter/include/minikin/WordBreaker.h +++ b/engine/src/flutter/include/minikin/WordBreaker.h @@ -63,7 +63,7 @@ private: // state for the email address / url detector ssize_t mScanOffset; - bool mSuppressHyphen; + bool mInEmailOrUrl; }; } // namespace diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index f438cd5546e..edac993d444 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -43,7 +43,7 @@ void WordBreaker::setText(const uint16_t* data, size_t size) { mLast = 0; mCurrent = 0; mScanOffset = 0; - mSuppressHyphen = false; + mInEmailOrUrl = false; UErrorCode status = U_ZERO_ERROR; utext_openUChars(&mUText, data, size, &status); mBreakIterator->setText(&mUText, status); @@ -62,6 +62,17 @@ enum ScanState { SAW_COLON_SLASH_SLASH, }; +// Chicago Manual of Style recommends breaking after these characters in URLs and email addresses +static bool breakAfter(uint16_t c) { + return c == ':' || c == '=' || c == '&'; +} + +// Chicago Manual of Style recommends breaking before these characters in URLs and email addresses +static bool breakBefore(uint16_t c) { + return c == '~' || c == '.' || c == ',' || c == '-' || c == '_' || c == '?' || c == '#' + || c == '%' || c == '=' || c == '&'; +} + ssize_t WordBreaker::next() { mLast = mCurrent; @@ -88,23 +99,45 @@ ssize_t WordBreaker::next() { } } if (state == SAW_AT || state == SAW_COLON_SLASH_SLASH) { - // no line breaks in entire email address or url - // TODO: refine this according to Chicago Manual of Style rules - while (i < mTextSize && mText[i] == ' ') { - i++; + if (!mBreakIterator->isBoundary(i)) { + i = mBreakIterator->following(i); } - mCurrent = i; - mSuppressHyphen = true; - // Setting mIteratorWasReset will cause next break to be computed following - // mCurrent, rather than following the current ICU iterator location. + mInEmailOrUrl = true; mIteratorWasReset = true; - if (mBreakIterator->isBoundary(mCurrent)) { - return mCurrent; - } } else { - mScanOffset = i; - mSuppressHyphen = false; + mInEmailOrUrl = false; } + mScanOffset = i; + } + + if (mInEmailOrUrl) { + // special rules for email addresses and URL's as per Chicago Manual of Style (16th ed.) + uint16_t lastChar = mText[mLast]; + ssize_t i; + for (i = mLast + 1; i < mScanOffset; i++) { + if (breakAfter(lastChar)) { + break; + } + // break after double slash + if (lastChar == '/' && i >= mLast + 2 && mText[i - 2] == '/') { + break; + } + uint16_t thisChar = mText[i]; + // never break after hyphen + if (lastChar != '-') { + if (breakBefore(thisChar)) { + break; + } + // break before single slash + if (thisChar == '/' && lastChar != '/' && + !(i + 1 < mScanOffset && mText[i + 1] == '/')) { + break; + } + } + lastChar = thisChar; + } + mCurrent = i; + return mCurrent; } int32_t result; @@ -122,7 +155,7 @@ ssize_t WordBreaker::next() { } ssize_t WordBreaker::wordStart() const { - if (mSuppressHyphen) { + if (mInEmailOrUrl) { return mLast; } ssize_t result = mLast; @@ -142,7 +175,7 @@ ssize_t WordBreaker::wordStart() const { } ssize_t WordBreaker::wordEnd() const { - if (mSuppressHyphen) { + if (mInEmailOrUrl) { return mLast; } ssize_t result = mCurrent; diff --git a/engine/src/flutter/tests/WordBreakerTests.cpp b/engine/src/flutter/tests/WordBreakerTests.cpp index 4111a1b1f4c..284b02cb28a 100644 --- a/engine/src/flutter/tests/WordBreakerTests.cpp +++ b/engine/src/flutter/tests/WordBreakerTests.cpp @@ -85,7 +85,9 @@ TEST_F(WordBreakerTest, email) { breaker.setLocale(icu::Locale::getEnglish()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); - EXPECT_EQ(16, breaker.next()); // after "foo@example.com " + EXPECT_EQ(11, breaker.next()); // after "foo@example" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(16, breaker.next()); // after ".com " EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_EQ(16, breaker.wordStart()); // "x" @@ -99,13 +101,19 @@ TEST_F(WordBreakerTest, mailto) { breaker.setLocale(icu::Locale::getEnglish()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); - EXPECT_EQ(23, breaker.next()); // after "mailto:foo@example.com " + EXPECT_EQ(7, breaker.next()); // after "mailto:" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(18, breaker.next()); // after "foo@example" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(23, breaker.next()); // after ".com " EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_EQ(23, breaker.wordStart()); // "x" EXPECT_EQ(24, breaker.wordEnd()); } +// The current logic always places a line break after a detected email address or URL +// and an immediately following non-ASCII character. TEST_F(WordBreakerTest, emailNonAscii) { uint16_t buf[] = {'f', 'o', 'o', '@', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', 0x4E00}; @@ -113,7 +121,9 @@ TEST_F(WordBreakerTest, emailNonAscii) { breaker.setLocale(icu::Locale::getEnglish()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); - EXPECT_EQ(15, breaker.next()); // after "foo@example.com" + EXPECT_EQ(11, breaker.next()); // after "foo@example" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(15, breaker.next()); // after ".com" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_EQ(15, breaker.wordStart()); // "一" @@ -127,13 +137,31 @@ TEST_F(WordBreakerTest, emailCombining) { breaker.setLocale(icu::Locale::getEnglish()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); - EXPECT_EQ(17, breaker.next()); // after "foo@example.com̃" + EXPECT_EQ(11, breaker.next()); // after "foo@example" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(17, breaker.next()); // after ".com̃ " EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_EQ(17, breaker.wordStart()); // "x" EXPECT_EQ(18, breaker.wordEnd()); } +TEST_F(WordBreakerTest, lonelyAt) { + uint16_t buf[] = {'a', ' ', '@', ' ', 'b'}; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(2, breaker.next()); // after "a " + EXPECT_EQ(0, breaker.wordStart()); // "a" + EXPECT_EQ(1, breaker.wordEnd()); + EXPECT_EQ(4, breaker.next()); // after "@ " + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_EQ(4, breaker.wordStart()); // "b" + EXPECT_EQ(5, breaker.wordEnd()); +} + TEST_F(WordBreakerTest, url) { uint16_t buf[] = {'h', 't', 't', 'p', ':', '/', '/', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', ' ', 'x'}; @@ -141,9 +169,101 @@ TEST_F(WordBreakerTest, url) { breaker.setLocale(icu::Locale::getEnglish()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); - EXPECT_EQ(19, breaker.next()); // after "http://example.com " + EXPECT_EQ(5, breaker.next()); // after "http:" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(7, breaker.next()); // after "//" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(14, breaker.next()); // after "example" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(19, breaker.next()); // after ".com " EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_EQ(19, breaker.wordStart()); // "x" EXPECT_EQ(20, breaker.wordEnd()); } + +// Breaks according to section 14.12 of Chicago Manual of Style, *URLs or DOIs and line breaks* +TEST_F(WordBreakerTest, urlBreakChars) { + uint16_t buf[] = {'h', 't', 't', 'p', ':', '/', '/', 'a', '.', 'b', '/', '~', 'c', ',', 'd', + '-', 'e', '?', 'f', '=', 'g', '&', 'h', '#', 'i', '%', 'j', '_', 'k', '/', 'l'}; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(5, breaker.next()); // after "http:" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(7, breaker.next()); // after "//" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(8, breaker.next()); // after "a" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(10, breaker.next()); // after ".b" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(11, breaker.next()); // after "/" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(13, breaker.next()); // after "~c" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(15, breaker.next()); // after ",d" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(17, breaker.next()); // after "-e" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(19, breaker.next()); // after "?f" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(20, breaker.next()); // after "=" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(21, breaker.next()); // after "g" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(22, breaker.next()); // after "&" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(23, breaker.next()); // after "h" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(25, breaker.next()); // after "#i" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(27, breaker.next()); // after "%j" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(29, breaker.next()); // after "_k" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); +} + +TEST_F(WordBreakerTest, urlNoHyphenBreak) { + uint16_t buf[] = {'h', 't', 't', 'p', ':', '/', '/', 'a', '-', '/', 'b'}; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(5, breaker.next()); // after "http:" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(7, breaker.next()); // after "//" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(8, breaker.next()); // after "a" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); +} + +TEST_F(WordBreakerTest, urlEndsWithSlash) { + uint16_t buf[] = {'h', 't', 't', 'p', ':', '/', '/', 'a', '/'}; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(5, breaker.next()); // after "http:" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(7, breaker.next()); // after "//" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(8, breaker.next()); // after "a" + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); +} + +TEST_F(WordBreakerTest, emailStartsWithSlash) { + uint16_t buf[] = {'/', 'a', '@', 'b'}; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); +} From 76772e8ad4a88cbe87edc873dd66af7d0baf6a25 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 8 Sep 2015 20:52:56 -0700 Subject: [PATCH 160/364] Add penalty for breaks in URLs and email addresses Recent changes have added special cases for line breaks within URLs and email addresses. Such breaks are undesirable when they can be avoided, but at other times are needed to avoid huge gaps, or indeed to make the line fit at all. This patch assigns a penalty for such breaks, equal to the hyphenation penalty. The mechanism is currently very simple, but would be easy to fine-tune based on more detailed information about break quality. Bug: 20126487 Bug: 20566159 Change-Id: I0d3323897737a2850f1e734fa17b96b065eabd9c --- .../src/flutter/include/minikin/WordBreaker.h | 2 + .../src/flutter/libs/minikin/LineBreaker.cpp | 3 +- .../src/flutter/libs/minikin/WordBreaker.cpp | 4 ++ engine/src/flutter/tests/WordBreakerTests.cpp | 44 +++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/include/minikin/WordBreaker.h b/engine/src/flutter/include/minikin/WordBreaker.h index c4aa1514a05..4eff9d1755b 100644 --- a/engine/src/flutter/include/minikin/WordBreaker.h +++ b/engine/src/flutter/include/minikin/WordBreaker.h @@ -50,6 +50,8 @@ public: ssize_t wordEnd() const; + int breakBadness() const; + void finish(); private: diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 214f19599d3..9cf07d5d9e9 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -207,7 +207,8 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa // Skip break for zero-width characters inside replacement span if (paint != nullptr || current == end || mCharWidths[current] > 0) { - addWordBreak(current, mWidth, postBreak, 0.0, 0); + float penalty = hyphenPenalty * mWordBreaker.breakBadness(); + addWordBreak(current, mWidth, postBreak, penalty, 0); } lastBreak = current; lastBreakWidth = mWidth; diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index edac993d444..ca69a50307c 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -193,6 +193,10 @@ ssize_t WordBreaker::wordEnd() const { return result; } +int WordBreaker::breakBadness() const { + return (mInEmailOrUrl && mCurrent < mScanOffset) ? 1 : 0; +} + void WordBreaker::finish() { mText = nullptr; // Note: calling utext_close multiply is safe diff --git a/engine/src/flutter/tests/WordBreakerTests.cpp b/engine/src/flutter/tests/WordBreakerTests.cpp index 284b02cb28a..9662b2f7a4f 100644 --- a/engine/src/flutter/tests/WordBreakerTests.cpp +++ b/engine/src/flutter/tests/WordBreakerTests.cpp @@ -42,10 +42,12 @@ TEST_F(WordBreakerTest, basic) { EXPECT_EQ(6, breaker.next()); // after "hello " EXPECT_EQ(0, breaker.wordStart()); // "hello" EXPECT_EQ(5, breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); EXPECT_EQ(6, breaker.current()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_EQ(6, breaker.wordStart()); // "world" EXPECT_EQ(11, breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); EXPECT_EQ(11, breaker.current()); } @@ -58,9 +60,11 @@ TEST_F(WordBreakerTest, softHyphen) { EXPECT_EQ(7, breaker.next()); // after "hel{SOFT HYPHEN}lo " EXPECT_EQ(0, breaker.wordStart()); // "hel{SOFT HYPHEN}lo" EXPECT_EQ(6, breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_EQ(7, breaker.wordStart()); // "world" EXPECT_EQ(12, breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); } TEST_F(WordBreakerTest, punct) { @@ -73,9 +77,11 @@ TEST_F(WordBreakerTest, punct) { EXPECT_EQ(9, breaker.next()); // after "¡¡hello, " EXPECT_EQ(2, breaker.wordStart()); // "hello" EXPECT_EQ(7, breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_EQ(9, breaker.wordStart()); // "world" EXPECT_EQ(14, breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); } TEST_F(WordBreakerTest, email) { @@ -87,11 +93,14 @@ TEST_F(WordBreakerTest, email) { EXPECT_EQ(0, breaker.current()); EXPECT_EQ(11, breaker.next()); // after "foo@example" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(16, breaker.next()); // after ".com " EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_EQ(16, breaker.wordStart()); // "x" EXPECT_EQ(17, breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); } TEST_F(WordBreakerTest, mailto) { @@ -103,13 +112,17 @@ TEST_F(WordBreakerTest, mailto) { EXPECT_EQ(0, breaker.current()); EXPECT_EQ(7, breaker.next()); // after "mailto:" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(18, breaker.next()); // after "foo@example" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(23, breaker.next()); // after ".com " EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_EQ(23, breaker.wordStart()); // "x" EXPECT_EQ(24, breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); } // The current logic always places a line break after a detected email address or URL @@ -123,11 +136,14 @@ TEST_F(WordBreakerTest, emailNonAscii) { EXPECT_EQ(0, breaker.current()); EXPECT_EQ(11, breaker.next()); // after "foo@example" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(15, breaker.next()); // after ".com" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_EQ(15, breaker.wordStart()); // "一" EXPECT_EQ(16, breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); } TEST_F(WordBreakerTest, emailCombining) { @@ -139,11 +155,14 @@ TEST_F(WordBreakerTest, emailCombining) { EXPECT_EQ(0, breaker.current()); EXPECT_EQ(11, breaker.next()); // after "foo@example" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(17, breaker.next()); // after ".com̃ " EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_EQ(17, breaker.wordStart()); // "x" EXPECT_EQ(18, breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); } TEST_F(WordBreakerTest, lonelyAt) { @@ -155,11 +174,14 @@ TEST_F(WordBreakerTest, lonelyAt) { EXPECT_EQ(2, breaker.next()); // after "a " EXPECT_EQ(0, breaker.wordStart()); // "a" EXPECT_EQ(1, breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); EXPECT_EQ(4, breaker.next()); // after "@ " EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_EQ(4, breaker.wordStart()); // "b" EXPECT_EQ(5, breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); } TEST_F(WordBreakerTest, url) { @@ -171,15 +193,20 @@ TEST_F(WordBreakerTest, url) { EXPECT_EQ(0, breaker.current()); EXPECT_EQ(5, breaker.next()); // after "http:" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(7, breaker.next()); // after "//" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(14, breaker.next()); // after "example" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(19, breaker.next()); // after ".com " EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_EQ(19, breaker.wordStart()); // "x" EXPECT_EQ(20, breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); } // Breaks according to section 14.12 of Chicago Manual of Style, *URLs or DOIs and line breaks* @@ -192,38 +219,55 @@ TEST_F(WordBreakerTest, urlBreakChars) { EXPECT_EQ(0, breaker.current()); EXPECT_EQ(5, breaker.next()); // after "http:" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(7, breaker.next()); // after "//" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(8, breaker.next()); // after "a" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(10, breaker.next()); // after ".b" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(11, breaker.next()); // after "/" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(13, breaker.next()); // after "~c" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(15, breaker.next()); // after ",d" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(17, breaker.next()); // after "-e" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(19, breaker.next()); // after "?f" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(20, breaker.next()); // after "=" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(21, breaker.next()); // after "g" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(22, breaker.next()); // after "&" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(23, breaker.next()); // after "h" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(25, breaker.next()); // after "#i" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(27, breaker.next()); // after "%j" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ(29, breaker.next()); // after "_k" EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(1, breaker.breakBadness()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); } TEST_F(WordBreakerTest, urlNoHyphenBreak) { From 77c3f8eb24dce937de1406c4832f34fbd7f788ec Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Fri, 22 Jan 2016 18:35:52 +0900 Subject: [PATCH 161/364] Support Hanb script. Hanb is a union of Han and Bopomofo. Bug: 26687969 Change-Id: Ic696bcbbc9607f3842fd0115668b8e7bd917e62b --- .../src/flutter/libs/minikin/FontLanguage.cpp | 7 +++++++ engine/src/flutter/libs/minikin/FontLanguage.h | 17 +++++++++-------- engine/src/flutter/tests/FontFamilyTest.cpp | 12 ++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontLanguage.cpp b/engine/src/flutter/libs/minikin/FontLanguage.cpp index 8e5c9c481f6..db630592b8e 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguage.cpp @@ -61,9 +61,16 @@ FontLanguage::FontLanguage(const char* buf, size_t length) : FontLanguage() { uint8_t FontLanguage::scriptToSubScriptBits(uint32_t script) { uint8_t subScriptBits = 0u; switch (script) { + case SCRIPT_TAG('B', 'o', 'p', 'o'): + subScriptBits = kBopomofoFlag; + break; case SCRIPT_TAG('H', 'a', 'n', 'g'): subScriptBits = kHangulFlag; break; + case SCRIPT_TAG('H', 'a', 'n', 'b'): + // Bopomofo is almost exclusively used in Taiwan. + subScriptBits = kHanFlag | kBopomofoFlag; + break; case SCRIPT_TAG('H', 'a', 'n', 'i'): subScriptBits = kHanFlag; break; diff --git a/engine/src/flutter/libs/minikin/FontLanguage.h b/engine/src/flutter/libs/minikin/FontLanguage.h index ee0b505bdde..1a20480fb55 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.h +++ b/engine/src/flutter/libs/minikin/FontLanguage.h @@ -68,14 +68,15 @@ private: // mLanguage = 0 means the FontLanguage is unsupported. uint32_t mLanguage; - // For faster comparing, use 7 bits for specific scripts. - static const uint8_t kEmojiFlag = 1u; - static const uint8_t kHanFlag = 1u << 1; - static const uint8_t kHangulFlag = 1u << 2; - static const uint8_t kHiraganaFlag = 1u << 3; - static const uint8_t kKatakanaFlag = 1u << 4; - static const uint8_t kSimplifiedChineseFlag = 1u << 5; - static const uint8_t kTraditionalChineseFlag = 1u << 6; + // For faster comparing, use 8 bits for specific scripts. + static const uint8_t kBopomofoFlag = 1u; + static const uint8_t kEmojiFlag = 1u << 1; + static const uint8_t kHanFlag = 1u << 2; + static const uint8_t kHangulFlag = 1u << 3; + static const uint8_t kHiraganaFlag = 1u << 4; + static const uint8_t kKatakanaFlag = 1u << 5; + static const uint8_t kSimplifiedChineseFlag = 1u << 6; + static const uint8_t kTraditionalChineseFlag = 1u << 7; uint8_t mSubScriptBits; static uint8_t scriptToSubScriptBits(uint32_t script); diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index fef464f1d77..beaa05488f5 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -131,6 +131,7 @@ TEST_F(FontLanguageTest, ScriptMatchTest) { { "zh-Hani", "Hani", SUPPORTED }, { "ko-Kore", "Kore", SUPPORTED }, { "ko-Hang", "Hang", SUPPORTED }, + { "zh-Hanb", "Hanb", SUPPORTED }, // Japanese supports Hiragana, Katakanara, etc. { "ja-Jpan", "Hira", SUPPORTED }, @@ -142,6 +143,10 @@ TEST_F(FontLanguageTest, ScriptMatchTest) { // Chinese supports Han. { "zh-Hans", "Hani", SUPPORTED }, { "zh-Hant", "Hani", SUPPORTED }, + { "zh-Hanb", "Hani", SUPPORTED }, + + // Hanb supports Bopomofo. + { "zh-Hanb", "Bopo", SUPPORTED }, // Korean supports Hangul. { "ko-Kore", "Hang", SUPPORTED }, @@ -176,12 +181,19 @@ TEST_F(FontLanguageTest, ScriptMatchTest) { // Kanji doesn't support Chinese, etc. { "zh-Hani", "Hant", NOT_SUPPORTED }, { "zh-Hani", "Hans", NOT_SUPPORTED }, + { "zh-Hani", "Hanb", NOT_SUPPORTED }, // Hangul doesn't support Korean, etc. { "ko-Hang", "Kore", NOT_SUPPORTED }, { "ko-Hani", "Kore", NOT_SUPPORTED }, { "ko-Hani", "Hang", NOT_SUPPORTED }, { "ko-Hang", "Hani", NOT_SUPPORTED }, + + // Han with botomofo doesn't support simplified Chinese, etc. + { "zh-Hanb", "Hant", NOT_SUPPORTED }, + { "zh-Hanb", "Hans", NOT_SUPPORTED }, + { "zh-Hanb", "Jpan", NOT_SUPPORTED }, + { "zh-Hanb", "Kore", NOT_SUPPORTED }, }; for (auto testCase : testCases) { From 72ab39455f2fe587116066d5ec66d75cd89f0114 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 18 Feb 2016 10:27:38 -0800 Subject: [PATCH 162/364] Disable hyphenation when word overlaps style boundary In cases when a word (as defined by the ICU break iterator) overlaps a style boundary, the returned wordStart can be extend before the range currently being measured for layout. When we try to hyphenate the resulting substrings, we get a negative range, which crashes. This patch disables hyphenation in this case. Bug: 27237112 Change-Id: I76d04b39dd3b4d6d267aaaf4bebc9ab361891646 --- engine/src/flutter/libs/minikin/LineBreaker.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 9cf07d5d9e9..22c39547ae6 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -174,7 +174,8 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa if (paint != nullptr && mHyphenator != nullptr && mHyphenationFrequency != kHyphenationFrequency_None && !wordEndsInHyphen && !temporarilySkipHyphenation && - wordEnd > wordStart && wordEnd - wordStart <= LONGEST_HYPHENATED_WORD) { + wordStart >= start && wordEnd > wordStart && + wordEnd - wordStart <= LONGEST_HYPHENATED_WORD) { mHyphenator->hyphenate(&mHyphBuf, &mTextBuf[wordStart], wordEnd - wordStart); #if VERBOSE_DEBUG std::string hyphenatedString; From 761218bce9059c4c73e5089ce5924913cbd5fb6f Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi Date: Thu, 18 Feb 2016 11:35:42 -0800 Subject: [PATCH 163/364] Optimize: Use measureText instead of doLayout. With this CL, measureText is used for getRunAdvance, getOffsetForAdvance and line breaking. Bug: 24505153 Change-Id: Ib699f6b1391b46537736fc274cdb41686586b550 --- .../src/flutter/include/minikin/Measurement.h | 5 ++-- .../src/flutter/libs/minikin/LineBreaker.cpp | 24 +++++++++---------- .../src/flutter/libs/minikin/Measurement.cpp | 20 ++++++++-------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/engine/src/flutter/include/minikin/Measurement.h b/engine/src/flutter/include/minikin/Measurement.h index fc47fa31620..7bcab669dea 100644 --- a/engine/src/flutter/include/minikin/Measurement.h +++ b/engine/src/flutter/include/minikin/Measurement.h @@ -21,9 +21,10 @@ namespace android { -float getRunAdvance(Layout& layout, const uint16_t* buf, size_t start, size_t count, size_t offset); +float getRunAdvance(const float* advances, const uint16_t* buf, size_t start, size_t count, + size_t offset); -size_t getOffsetForAdvance(Layout& layout, const uint16_t* buf, size_t start, size_t count, +size_t getOffsetForAdvance(const float* advances, const uint16_t* buf, size_t start, size_t count, float advance); } diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 22c39547ae6..9c4ff6f3bea 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -122,17 +122,13 @@ static bool isLineBreakingHyphen(uint16_t c) { // to addCandidate. float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typeface, FontStyle style, size_t start, size_t end, bool isRtl) { - Layout layout; // performance TODO: move layout to self object to reduce allocation cost? float width = 0.0f; int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR; float hyphenPenalty = 0.0; if (paint != nullptr) { - layout.setFontCollection(typeface); - layout.doLayout(mTextBuf.data(), start, end - start, mTextBuf.size(), bidiFlags, style, - *paint); - layout.getAdvances(mCharWidths.data() + start); - width = layout.getAdvance(); + width = Layout::measureText(mTextBuf.data(), start, end - start, mTextBuf.size(), bidiFlags, + style, *paint, typeface, mCharWidths.data() + start); // a heuristic that seems to perform well hyphenPenalty = 0.5 * paint->size * paint->scaleX * mLineWidths.getLineWidth(0); @@ -192,13 +188,17 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa uint8_t hyph = mHyphBuf[j - wordStart]; if (hyph) { paint->hyphenEdit = hyph; - layout.doLayout(mTextBuf.data(), lastBreak, j - lastBreak, - mTextBuf.size(), bidiFlags, style, *paint); - ParaWidth hyphPostBreak = lastBreakWidth + layout.getAdvance(); + + const float firstPartWidth = Layout::measureText(mTextBuf.data(), + lastBreak, j - lastBreak, mTextBuf.size(), bidiFlags, style, + *paint, typeface, nullptr); + ParaWidth hyphPostBreak = lastBreakWidth + firstPartWidth; paint->hyphenEdit = 0; - layout.doLayout(mTextBuf.data(), j, afterWord - j, - mTextBuf.size(), bidiFlags, style, *paint); - ParaWidth hyphPreBreak = postBreak - layout.getAdvance(); + + const float secondPartWith = Layout::measureText(mTextBuf.data(), j, + afterWord - j, mTextBuf.size(), bidiFlags, style, *paint, + typeface, nullptr); + ParaWidth hyphPreBreak = postBreak - secondPartWith; addWordBreak(j, hyphPreBreak, hyphPostBreak, hyphenPenalty, hyph); } } diff --git a/engine/src/flutter/libs/minikin/Measurement.cpp b/engine/src/flutter/libs/minikin/Measurement.cpp index 0b68ac5f640..1ba6678373b 100644 --- a/engine/src/flutter/libs/minikin/Measurement.cpp +++ b/engine/src/flutter/libs/minikin/Measurement.cpp @@ -28,26 +28,26 @@ namespace android { // These could be considered helper methods of layout, but need only be loosely coupled, so // are separate. -static float getRunAdvance(Layout& layout, const uint16_t* buf, size_t layoutStart, size_t start, - size_t count, size_t offset) { +static float getRunAdvance(const float* advances, const uint16_t* buf, size_t layoutStart, + size_t start, size_t count, size_t offset) { float advance = 0.0f; size_t lastCluster = start; float clusterWidth = 0.0f; for (size_t i = start; i < offset; i++) { - float charAdvance = layout.getCharAdvance(i - layoutStart); + float charAdvance = advances[i - layoutStart]; if (charAdvance != 0.0f) { advance += charAdvance; lastCluster = i; clusterWidth = charAdvance; } } - if (offset < start + count && layout.getCharAdvance(offset - layoutStart) == 0.0f) { + if (offset < start + count && advances[offset - layoutStart] == 0.0f) { // In the middle of a cluster, distribute width of cluster so that each grapheme cluster // gets an equal share. // TODO: get caret information out of font when that's available size_t nextCluster; for (nextCluster = offset + 1; nextCluster < start + count; nextCluster++) { - if (layout.getCharAdvance(nextCluster - layoutStart) != 0.0f) break; + if (advances[nextCluster - layoutStart] != 0.0f) break; } int numGraphemeClusters = 0; int numGraphemeClustersAfter = 0; @@ -67,9 +67,9 @@ static float getRunAdvance(Layout& layout, const uint16_t* buf, size_t layoutSta return advance; } -float getRunAdvance(Layout& layout, const uint16_t* buf, size_t start, size_t count, +float getRunAdvance(const float* advances, const uint16_t* buf, size_t start, size_t count, size_t offset) { - return getRunAdvance(layout, buf, start, start, count, offset); + return getRunAdvance(advances, buf, start, start, count, offset); } /** @@ -80,7 +80,7 @@ float getRunAdvance(Layout& layout, const uint16_t* buf, size_t start, size_t co * The actual implementation fast-forwards through clusters to get "close", then does a finer-grain * search within the cluster and grapheme breaks. */ -size_t getOffsetForAdvance(Layout& layout, const uint16_t* buf, size_t start, size_t count, +size_t getOffsetForAdvance(const float* advances, const uint16_t* buf, size_t start, size_t count, float advance) { float x = 0.0f, xLastClusterStart = 0.0f, xSearchStart = 0.0f; size_t lastClusterStart = start, searchStart = start; @@ -89,7 +89,7 @@ size_t getOffsetForAdvance(Layout& layout, const uint16_t* buf, size_t start, si searchStart = lastClusterStart; xSearchStart = xLastClusterStart; } - float width = layout.getCharAdvance(i - start); + float width = advances[i - start]; if (width != 0.0f) { lastClusterStart = i; xLastClusterStart = x; @@ -104,7 +104,7 @@ size_t getOffsetForAdvance(Layout& layout, const uint16_t* buf, size_t start, si for (size_t i = searchStart; i <= start + count; i++) { if (GraphemeBreak::isGraphemeBreak(buf, start, count, i)) { // "getRunAdvance(layout, buf, start, count, i) - advance" but more efficient - float delta = getRunAdvance(layout, buf, start, searchStart, count - searchStart, i) + float delta = getRunAdvance(advances, buf, start, searchStart, count - searchStart, i) + xSearchStart - advance; if (std::abs(delta) < bestDist) { From a14712eaf83ce4e1108f8b9f12e9ab0ec16acbf8 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 18 Feb 2016 15:00:24 -0800 Subject: [PATCH 164/364] Suppress linebreaks in emoji ZWJ sequences Due to the way emoji ZWJ sequences are defined, the ICU line breaking algorithm determines that there are valid line breaks inside the sequence. This patch suppresses these line breaks. This is an adaptation of I225ebebc0f4186e4b8f48fee399c4a62b3f0218a into the nyc-dev branch. Bug: 25433289 Change-Id: I84b50b1e6ef13d436965eab389659d02a30d100f --- .../src/flutter/libs/minikin/WordBreaker.cpp | 29 ++++++++++++++++++- engine/src/flutter/tests/WordBreakerTests.cpp | 24 +++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index ca69a50307c..ec84c39f9a7 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -25,6 +25,7 @@ namespace android { const uint32_t CHAR_SOFT_HYPHEN = 0x00AD; +const uint16_t CHAR_ZWJ = 0x200D; void WordBreaker::setLocale(const icu::Locale& locale) { UErrorCode status = U_ZERO_ERROR; @@ -62,6 +63,32 @@ enum ScanState { SAW_COLON_SLASH_SLASH, }; +/** + * Determine whether a line break at position i within the buffer buf is valid. This + * represents customization beyond the ICU behavior, because plain ICU provides some + * line break opportunities that we don't want. + **/ +static bool isBreakValid(uint16_t codeUnit, const uint16_t* buf, size_t bufEnd, size_t i) { + if (codeUnit == CHAR_SOFT_HYPHEN) { + return false; + } + if (codeUnit == CHAR_ZWJ) { + // Possible emoji ZWJ sequence + uint32_t next_codepoint; + U16_NEXT(buf, i, bufEnd, next_codepoint); + if (next_codepoint == 0x2764 || // HEAVY BLACK HEART + next_codepoint == 0x1F466 || // BOY + next_codepoint == 0x1F467 || // GIRL + next_codepoint == 0x1F468 || // MAN + next_codepoint == 0x1F469 || // WOMAN + next_codepoint == 0x1F48B || // KISS MARK + next_codepoint == 0x1F5E8) { // LEFT SPEECH BUBBLE + return false; + } + } + return true; +} + // Chicago Manual of Style recommends breaking after these characters in URLs and email addresses static bool breakAfter(uint16_t c) { return c == ':' || c == '=' || c == '&'; @@ -149,7 +176,7 @@ ssize_t WordBreaker::next() { result = mBreakIterator->next(); } } while (result != icu::BreakIterator::DONE && (size_t)result != mTextSize - && mText[result - 1] == CHAR_SOFT_HYPHEN); + && !isBreakValid(mText[result - 1], mText, mTextSize, result)); mCurrent = (ssize_t)result; return mCurrent; } diff --git a/engine/src/flutter/tests/WordBreakerTests.cpp b/engine/src/flutter/tests/WordBreakerTests.cpp index 9662b2f7a4f..6c5e4795c89 100644 --- a/engine/src/flutter/tests/WordBreakerTests.cpp +++ b/engine/src/flutter/tests/WordBreakerTests.cpp @@ -67,6 +67,30 @@ TEST_F(WordBreakerTest, softHyphen) { EXPECT_EQ(0, breaker.breakBadness()); } +TEST_F(WordBreakerTest, zwjEmojiSequences) { + uint16_t buf[] = { + // man + zwj + heart + zwj + man + 0xD83D, 0xDC68, 0x200D, 0x2764, 0x200D, 0xD83D, 0xDC68, + // woman + zwj + heart + zwj + woman + 0xD83D, 0xDC69, 0x200D, 0x2764, 0x200D, 0xD83D, 0xDC8B, 0x200D, 0xD83D, 0xDC69, + // eye + zwj + left speech bubble + 0xD83D, 0xDC41, 0x200D, 0xD83D, 0xDDE8, + }; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(7, breaker.next()); // after man + zwj + heart + zwj + man + EXPECT_EQ(0, breaker.wordStart()); + EXPECT_EQ(7, breaker.wordEnd()); + EXPECT_EQ(17, breaker.next()); // after woman + zwj + heart + zwj + woman + EXPECT_EQ(7, breaker.wordStart()); + EXPECT_EQ(17, breaker.wordEnd()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_EQ(17, breaker.wordStart()); + EXPECT_EQ(22, breaker.wordEnd()); +} + TEST_F(WordBreakerTest, punct) { uint16_t buf[] = {0x00A1, 0x00A1, 'h', 'e', 'l', 'l' ,'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '!'}; From 675933f27148de3495761ed8348728b3337ddd9a Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Mon, 22 Feb 2016 13:28:44 -0800 Subject: [PATCH 165/364] Suppress grapheme cluster breaks in emoji with modifiers An emoji with a modifier should be treated as a single grapheme, i.e. it should not be possible to place the cursor between the base and modifier. This patch implements the proposed Rule GB9c from Mark Davis's proposal entitled "Fixing breaking properties for emoji", L2/16-011R3. The patch also skips over variation sequences attached the to the preceding character, for computing grapheme cluster boundaries. Bug: 26829153 Change-Id: Iff5bc2bb8e5246223a017c7cf33acfbf63817f16 --- .../flutter/libs/minikin/GraphemeBreak.cpp | 53 +++++++++++++++++++ .../src/flutter/tests/GraphemeBreakTests.cpp | 24 +++++++++ 2 files changed, 77 insertions(+) diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index 7865d1d0458..41410917d4e 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -77,6 +77,48 @@ bool isZwjEmoji(uint32_t c) { || c == 0x1F5E8); // LEFT SPEECH BUBBLE } +// Based on Modifiers from http://www.unicode.org/L2/L2016/16011-data-file.txt +bool isEmojiModifier(uint32_t c) { + return (0x1F3FB <= c && c <= 0x1F3FF); +} + +// Based on Emoji_Modifier_Base from +// http://www.unicode.org/Public/emoji/3.0/emoji-data.txt +bool isEmojiBase(uint32_t c) { + if (0x261D <= c && c <= 0x270D) { + return (c == 0x261D || c == 0x26F9 || (0x270A <= c && c <= 0x270D)); + } else if (0x1F385 <= c && c <= 0x1F93E) { + return (c == 0x1F385 + || (0x1F3C3 <= c || c <= 0x1F3C4) + || (0x1F3CA <= c || c <= 0x1F3CB) + || (0x1F442 <= c || c <= 0x1F443) + || (0x1F446 <= c || c <= 0x1F450) + || (0x1F466 <= c || c <= 0x1F469) + || c == 0x1F46E + || (0x1F470 <= c || c <= 0x1F478) + || c == 0x1F47C + || (0x1F481 <= c || c <= 0x1F483) + || (0x1F485 <= c || c <= 0x1F487) + || c == 0x1F4AA + || c == 0x1F575 + || c == 0x1F57A + || c == 0x1F590 + || (0x1F595 <= c || c <= 0x1F596) + || (0x1F645 <= c || c <= 0x1F647) + || (0x1F64B <= c || c <= 0x1F64F) + || c == 0x1F6A3 + || (0x1F6B4 <= c || c <= 0x1F6B6) + || c == 0x1F6C0 + || (0x1F918 <= c || c <= 0x1F91E) + || c == 0x1F926 + || c == 0x1F930 + || (0x1F933 <= c || c <= 0x1F939) + || (0x1F93B <= c || c <= 0x1F93E)); + } else { + return false; + } +} + bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t count, size_t offset) { // This implementation closely follows Unicode Standard Annex #29 on @@ -165,6 +207,17 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co return false; } } + // Proposed Rule GB9c from http://www.unicode.org/L2/L2016/16011r3-break-prop-emoji.pdf + // E_Base x E_Modifier + if (isEmojiModifier(c2)) { + if (c1 == 0xFE0F && offset_back > start) { + // skip over emoji variation selector + U16_PREV(buf, start, offset_back, c1); + } + if (isEmojiBase(c1)) { + return false; + } + } // Rule GB10, Any ÷ Any return true; } diff --git a/engine/src/flutter/tests/GraphemeBreakTests.cpp b/engine/src/flutter/tests/GraphemeBreakTests.cpp index d6746bc2b09..dbd73be2b15 100644 --- a/engine/src/flutter/tests/GraphemeBreakTests.cpp +++ b/engine/src/flutter/tests/GraphemeBreakTests.cpp @@ -136,6 +136,30 @@ TEST(GraphemeBreak, tailoring) { EXPECT_TRUE(IsBreak("U+0628 U+200D | U+2764")); } +TEST(GraphemeBreak, emojiModifiers) { + EXPECT_FALSE(IsBreak("U+261D | U+1F3FB")); // white up pointing index + modifier + EXPECT_FALSE(IsBreak("U+270C | U+1F3FB")); // victory hand + modifier + EXPECT_FALSE(IsBreak("U+1F466 | U+1F3FB")); // boy + modifier + EXPECT_FALSE(IsBreak("U+1F466 | U+1F3FC")); // boy + modifier + EXPECT_FALSE(IsBreak("U+1F466 | U+1F3FD")); // boy + modifier + EXPECT_FALSE(IsBreak("U+1F466 | U+1F3FE")); // boy + modifier + EXPECT_FALSE(IsBreak("U+1F466 | U+1F3FF")); // boy + modifier + EXPECT_FALSE(IsBreak("U+1F918 | U+1F3FF")); // sign of the horns + modifier + EXPECT_FALSE(IsBreak("U+1F933 | U+1F3FF")); // selfie (Unicode 9) + modifier + + // adding emoji style variation selector doesn't affect grapheme cluster + EXPECT_TRUE(IsBreak("U+270C U+FE0E | U+1F3FB")); // victory hand + text style + modifier + EXPECT_FALSE(IsBreak("U+270C U+FE0F | U+1F3FB")); // heart + emoji style + modifier + + // heart is not an emoji base + EXPECT_TRUE(IsBreak("U+2764 | U+1F3FB")); // heart + modifier + EXPECT_TRUE(IsBreak("U+2764 U+FE0E | U+1F3FB")); // heart + emoji style + modifier + EXPECT_TRUE(IsBreak("U+2764 U+FE0F | U+1F3FB")); // heart + emoji style + modifier + + // rat is not an emoji modifer + EXPECT_TRUE(IsBreak("U+1F466 | U+1F400")); // boy + rat +} + TEST(GraphemeBreak, offsets) { uint16_t string[] = { 0x0041, 0x06DD, 0x0045, 0x0301, 0x0049, 0x0301 }; EXPECT_TRUE(GraphemeBreak::isGraphemeBreak(string, 2, 3, 2)); From b7d66e3db0473ace4ddfd3b553c4e9796e49c410 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 25 Feb 2016 17:07:42 +0900 Subject: [PATCH 166/364] Use color font if skin tone is specified. If skin tone is specified, the base emoji should be emoji style even if it is text presentation default emoji. This patch also removes wrong test case which expects default emoji presentation but it is controlled by family order in /etc/fonts.xml and there is no special logic for default presentation in minikin. Thus the default presentation unit test should not be in minikin. Bug: 27342346 Change-Id: I74a2b2feab4d559535049e368cfd833063cce81c --- .../flutter/libs/minikin/FontCollection.cpp | 10 +- .../flutter/libs/minikin/GraphemeBreak.cpp | 43 +------ .../flutter/libs/minikin/MinikinInternal.cpp | 42 +++++++ .../flutter/libs/minikin/MinikinInternal.h | 6 + .../tests/FontCollectionItemizeTest.cpp | 110 ++++++------------ 5 files changed, 93 insertions(+), 118 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index dd905a3442f..4541af84757 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -379,11 +379,13 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty langListId, variant); if (utf16Pos == 0 || family != lastFamily) { size_t start = utf16Pos; - // Workaround for Emoji keycap until we implement per-cluster font - // selection: if keycap is found in a different font that also - // supports previous char, attach previous char to the new run. + // Workaround for Emoji keycap and emoji modifier until we implement per-cluster + // font selection: if a keycap or an emoji modifier is found in a different font + // that also supports previous char, attach previous char to the new run. // Bug 7557244. - if (ch == KEYCAP && utf16Pos != 0 && family && family->getCoverage()->get(prevCh)) { + if (utf16Pos != 0 && + (ch == KEYCAP || (isEmojiModifier(ch) && isEmojiBase(prevCh))) && + family && family->getCoverage()->get(prevCh)) { const size_t prevChLength = U16_LENGTH(prevCh); run->end -= prevChLength; if (run->start == run->end) { diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index 41410917d4e..ef323d5d489 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -19,6 +19,7 @@ #include #include +#include "MinikinInternal.h" namespace android { @@ -77,48 +78,6 @@ bool isZwjEmoji(uint32_t c) { || c == 0x1F5E8); // LEFT SPEECH BUBBLE } -// Based on Modifiers from http://www.unicode.org/L2/L2016/16011-data-file.txt -bool isEmojiModifier(uint32_t c) { - return (0x1F3FB <= c && c <= 0x1F3FF); -} - -// Based on Emoji_Modifier_Base from -// http://www.unicode.org/Public/emoji/3.0/emoji-data.txt -bool isEmojiBase(uint32_t c) { - if (0x261D <= c && c <= 0x270D) { - return (c == 0x261D || c == 0x26F9 || (0x270A <= c && c <= 0x270D)); - } else if (0x1F385 <= c && c <= 0x1F93E) { - return (c == 0x1F385 - || (0x1F3C3 <= c || c <= 0x1F3C4) - || (0x1F3CA <= c || c <= 0x1F3CB) - || (0x1F442 <= c || c <= 0x1F443) - || (0x1F446 <= c || c <= 0x1F450) - || (0x1F466 <= c || c <= 0x1F469) - || c == 0x1F46E - || (0x1F470 <= c || c <= 0x1F478) - || c == 0x1F47C - || (0x1F481 <= c || c <= 0x1F483) - || (0x1F485 <= c || c <= 0x1F487) - || c == 0x1F4AA - || c == 0x1F575 - || c == 0x1F57A - || c == 0x1F590 - || (0x1F595 <= c || c <= 0x1F596) - || (0x1F645 <= c || c <= 0x1F647) - || (0x1F64B <= c || c <= 0x1F64F) - || c == 0x1F6A3 - || (0x1F6B4 <= c || c <= 0x1F6B6) - || c == 0x1F6C0 - || (0x1F918 <= c || c <= 0x1F91E) - || c == 0x1F926 - || c == 0x1F930 - || (0x1F933 <= c || c <= 0x1F939) - || (0x1F93B <= c || c <= 0x1F93E)); - } else { - return false; - } -} - bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t count, size_t offset) { // This implementation closely follows Unicode Standard Annex #29 on diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index c2aa01ac198..7fa7ce9d4db 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -30,4 +30,46 @@ void assertMinikinLocked() { #endif } +// Based on Modifiers from http://www.unicode.org/L2/L2016/16011-data-file.txt +bool isEmojiModifier(uint32_t c) { + return (0x1F3FB <= c && c <= 0x1F3FF); +} + +// Based on Emoji_Modifier_Base from +// http://www.unicode.org/Public/emoji/3.0/emoji-data.txt +bool isEmojiBase(uint32_t c) { + if (0x261D <= c && c <= 0x270D) { + return (c == 0x261D || c == 0x26F9 || (0x270A <= c && c <= 0x270D)); + } else if (0x1F385 <= c && c <= 0x1F93E) { + return (c == 0x1F385 + || (0x1F3C3 <= c || c <= 0x1F3C4) + || (0x1F3CA <= c || c <= 0x1F3CB) + || (0x1F442 <= c || c <= 0x1F443) + || (0x1F446 <= c || c <= 0x1F450) + || (0x1F466 <= c || c <= 0x1F469) + || c == 0x1F46E + || (0x1F470 <= c || c <= 0x1F478) + || c == 0x1F47C + || (0x1F481 <= c || c <= 0x1F483) + || (0x1F485 <= c || c <= 0x1F487) + || c == 0x1F4AA + || c == 0x1F575 + || c == 0x1F57A + || c == 0x1F590 + || (0x1F595 <= c || c <= 0x1F596) + || (0x1F645 <= c || c <= 0x1F647) + || (0x1F64B <= c || c <= 0x1F64F) + || c == 0x1F6A3 + || (0x1F6B4 <= c || c <= 0x1F6B6) + || c == 0x1F6C0 + || (0x1F918 <= c || c <= 0x1F91E) + || c == 0x1F926 + || c == 0x1F930 + || (0x1F933 <= c || c <= 0x1F939) + || (0x1F93B <= c || c <= 0x1F93E)); + } else { + return false; + } +} + } diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.h b/engine/src/flutter/libs/minikin/MinikinInternal.h index 34a95bb3d12..3d68691b35d 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.h +++ b/engine/src/flutter/libs/minikin/MinikinInternal.h @@ -32,6 +32,12 @@ extern Mutex gMinikinLock; // Aborts if gMinikinLock is not acquired. Do nothing on the release build. void assertMinikinLocked(); +// Returns true if c is emoji modifier base. +bool isEmojiBase(uint32_t c); + +// Returns true if c is emoji modifier. +bool isEmojiModifier(uint32_t c); + } #endif // MINIKIN_INTERNAL_H diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index 446efc6b565..031f3f98f3a 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -1119,78 +1119,6 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageAndCoverage) { } } -TEST_F(FontCollectionItemizeTest, itemize_emojiSelection) { - std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); - std::vector runs; - - const FontStyle kDefaultFontStyle; - - // U+00A9 is a text default emoji which is only available in TextEmojiFont.ttf. - // TextEmojiFont.ttf should be selected. - itemize(collection.get(), "U+00A9", kDefaultFontStyle, &runs); - ASSERT_EQ(1U, runs.size()); - EXPECT_EQ(0, runs[0].start); - EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); - - // U+00AE is a text default emoji which is only available in ColorEmojiFont.ttf. - // ColorEmojiFont.ttf should be selected. - itemize(collection.get(), "U+00AE", kDefaultFontStyle, &runs); - ASSERT_EQ(1U, runs.size()); - EXPECT_EQ(0, runs[0].start); - EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); - - // U+203C is a text default emoji which is available in both TextEmojiFont.ttf and - // ColorEmojiFont.ttf. TextEmojiFont.ttf should be selected. - itemize(collection.get(), "U+203C", kDefaultFontStyle, &runs); - ASSERT_EQ(1U, runs.size()); - EXPECT_EQ(0, runs[0].start); - EXPECT_EQ(1, runs[0].end); - // TODO: use text font for text default emoji. - // EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); - - // U+2049 is a text default emoji which is not available in either TextEmojiFont.ttf or - // ColorEmojiFont.ttf. No font should be selected. - itemize(collection.get(), "U+2049", kDefaultFontStyle, &runs); - ASSERT_EQ(1U, runs.size()); - EXPECT_EQ(0, runs[0].start); - EXPECT_EQ(1, runs[0].end); - EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); - - // U+231A is a emoji default emoji which is available only in TextEmojiFont.ttf. - // TextEmojiFont.ttf should be selected. - itemize(collection.get(), "U+231A", kDefaultFontStyle, &runs); - ASSERT_EQ(1U, runs.size()); - EXPECT_EQ(0, runs[0].start); - EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); - - // U+231B is a emoji default emoji which is available only in ColorEmojiFont.ttf. - // ColorEmojiFont.ttf should be selected. - itemize(collection.get(), "U+231B", kDefaultFontStyle, &runs); - ASSERT_EQ(1U, runs.size()); - EXPECT_EQ(0, runs[0].start); - EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); - - // U+23E9 is a emoji default emoji which is available in both TextEmojiFont.ttf and - // ColorEmojiFont.ttf. ColorEmojiFont should be selected. - itemize(collection.get(), "U+23E9", kDefaultFontStyle, &runs); - ASSERT_EQ(1U, runs.size()); - EXPECT_EQ(0, runs[0].start); - EXPECT_EQ(1, runs[0].end); - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); - - // U+23EA is a emoji default emoji which is not avaialble in either TextEmojiFont.ttf and - // ColorEmojiFont.ttf. No font should b e selected. - itemize(collection.get(), "U+23EA", kDefaultFontStyle, &runs); - ASSERT_EQ(1U, runs.size()); - EXPECT_EQ(0, runs[0].start); - EXPECT_EQ(1, runs[0].end); - EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); -} - TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); std::vector runs; @@ -1355,3 +1283,41 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { EXPECT_EQ(kMixedEmojiFont, getFontPath(runs[0])); } +TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_with_skinTone) { + std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); + std::vector runs; + + const FontStyle kDefaultFontStyle; + + // TextEmoji font is selected since it is listed before ColorEmoji font. + itemize(collection.get(), "U+261D", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(1, runs[0].end); + EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + + // If skin tone is specified, it should be colored. + itemize(collection.get(), "U+261D U+1F3FD", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(3, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + // Still color font is selected if an emoji variation selector is specified. + itemize(collection.get(), "U+261D U+FE0F U+1F3FD", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(4, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + // Text font should be selected if a text variation selector is specified and skin tone is + // rendered by itself. + itemize(collection.get(), "U+261D U+FE0E U+1F3FD", kDefaultFontStyle, &runs); + ASSERT_EQ(2U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); + EXPECT_EQ(2, runs[1].start); + EXPECT_EQ(4, runs[1].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[1])); +} From 7f9de429d43556e288e512313421c2a54513c8c4 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 25 Feb 2016 13:50:33 -0800 Subject: [PATCH 167/364] Suppress line breaks in emoji + modifier An emoji base with an emoji modifier renders as a single glyph and thus should not be a line break. Current (Unicode 8) logic does indicate a line break, so we override the results of the ICU line break iterator. The code references a proposal to improve Unicode behavior; when that is adopted and we upgrade ICU accordingly, the special-case code should be deleted, but the tests can remain. Bug: 27343378 Change-Id: I5de9c53e9a34c503816f9131e3d894e6f7a57d13 --- .../src/flutter/libs/minikin/WordBreaker.cpp | 32 ++++++++++++++----- engine/src/flutter/tests/WordBreakerTests.cpp | 27 +++++++++++++--- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index ec84c39f9a7..721c5bf0ebe 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -17,7 +17,8 @@ #define LOG_TAG "Minikin" #include -#include "minikin/WordBreaker.h" +#include +#include "MinikinInternal.h" #include #include @@ -25,7 +26,7 @@ namespace android { const uint32_t CHAR_SOFT_HYPHEN = 0x00AD; -const uint16_t CHAR_ZWJ = 0x200D; +const uint32_t CHAR_ZWJ = 0x200D; void WordBreaker::setLocale(const icu::Locale& locale) { UErrorCode status = U_ZERO_ERROR; @@ -68,14 +69,18 @@ enum ScanState { * represents customization beyond the ICU behavior, because plain ICU provides some * line break opportunities that we don't want. **/ -static bool isBreakValid(uint16_t codeUnit, const uint16_t* buf, size_t bufEnd, size_t i) { - if (codeUnit == CHAR_SOFT_HYPHEN) { +static bool isBreakValid(const uint16_t* buf, size_t bufEnd, size_t i) { + uint32_t codePoint; + size_t prev_offset = i; + U16_PREV(buf, 0, prev_offset, codePoint); + if (codePoint == CHAR_SOFT_HYPHEN) { return false; } - if (codeUnit == CHAR_ZWJ) { + uint32_t next_codepoint; + size_t next_offset = i; + U16_NEXT(buf, next_offset, bufEnd, next_codepoint); + if (codePoint == CHAR_ZWJ) { // Possible emoji ZWJ sequence - uint32_t next_codepoint; - U16_NEXT(buf, i, bufEnd, next_codepoint); if (next_codepoint == 0x2764 || // HEAVY BLACK HEART next_codepoint == 0x1F466 || // BOY next_codepoint == 0x1F467 || // GIRL @@ -86,6 +91,17 @@ static bool isBreakValid(uint16_t codeUnit, const uint16_t* buf, size_t bufEnd, return false; } } + // Proposed Rule LB30b from http://www.unicode.org/L2/L2016/16011r3-break-prop-emoji.pdf + // EB x EM + if (isEmojiModifier(next_codepoint)) { + if (codePoint == 0xFE0F && prev_offset > 0) { + // skip over emoji variation selector + U16_PREV(buf, 0, prev_offset, codePoint); + } + if (isEmojiBase(codePoint)) { + return false; + } + } return true; } @@ -176,7 +192,7 @@ ssize_t WordBreaker::next() { result = mBreakIterator->next(); } } while (result != icu::BreakIterator::DONE && (size_t)result != mTextSize - && !isBreakValid(mText[result - 1], mText, mTextSize, result)); + && !isBreakValid(mText, mTextSize, result)); mCurrent = (ssize_t)result; return mCurrent; } diff --git a/engine/src/flutter/tests/WordBreakerTests.cpp b/engine/src/flutter/tests/WordBreakerTests.cpp index 6c5e4795c89..cb12722562e 100644 --- a/engine/src/flutter/tests/WordBreakerTests.cpp +++ b/engine/src/flutter/tests/WordBreakerTests.cpp @@ -29,6 +29,8 @@ #define NELEM(x) ((sizeof(x) / sizeof((x)[0]))) #endif +#define UTF16(codepoint) U16_LEAD(codepoint), U16_TRAIL(codepoint) + using namespace android; typedef ICUTestBase WordBreakerTest; @@ -70,11 +72,11 @@ TEST_F(WordBreakerTest, softHyphen) { TEST_F(WordBreakerTest, zwjEmojiSequences) { uint16_t buf[] = { // man + zwj + heart + zwj + man - 0xD83D, 0xDC68, 0x200D, 0x2764, 0x200D, 0xD83D, 0xDC68, - // woman + zwj + heart + zwj + woman - 0xD83D, 0xDC69, 0x200D, 0x2764, 0x200D, 0xD83D, 0xDC8B, 0x200D, 0xD83D, 0xDC69, + UTF16(0x1F468), 0x200D, 0x2764, 0x200D, UTF16(0x1F468), + // woman + zwj + heart + zwj + kiss mark + zwj + woman + UTF16(0x1F469), 0x200D, 0x2764, 0x200D, UTF16(0x1F48B), 0x200D, UTF16(0x1F469), // eye + zwj + left speech bubble - 0xD83D, 0xDC41, 0x200D, 0xD83D, 0xDDE8, + UTF16(0x1F441), 0x200D, UTF16(0x1F5E8), }; WordBreaker breaker; breaker.setLocale(icu::Locale::getEnglish()); @@ -91,6 +93,23 @@ TEST_F(WordBreakerTest, zwjEmojiSequences) { EXPECT_EQ(22, breaker.wordEnd()); } +TEST_F(WordBreakerTest, emojiWithModifier) { + uint16_t buf[] = { + UTF16(0x1F466), UTF16(0x1F3FB), // boy + type 1-2 fitzpatrick modifier + 0x270C, 0xFE0F, UTF16(0x1F3FF) // victory hand + emoji style + type 6 fitzpatrick modifier + }; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(4, breaker.next()); // after man + type 6 fitzpatrick modifier + EXPECT_EQ(0, breaker.wordStart()); + EXPECT_EQ(4, breaker.wordEnd()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_EQ(4, breaker.wordStart()); + EXPECT_EQ(8, breaker.wordEnd()); +} + TEST_F(WordBreakerTest, punct) { uint16_t buf[] = {0x00A1, 0x00A1, 'h', 'e', 'l', 'l' ,'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '!'}; From a58530bccc426e86dd6ae3f6be6703599b7d52a4 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Sat, 27 Feb 2016 07:43:56 -0800 Subject: [PATCH 168/364] Fix wrong conditions in isEmojiBase I computed ranges using low <= c || c <= high, should be &&. Bug: 26829153 Change-Id: Ic1002d90b6a408a0b415f2d117d0e57adcbc2fa9 --- .../flutter/libs/minikin/MinikinInternal.cpp | 30 +++++++++---------- .../src/flutter/tests/GraphemeBreakTests.cpp | 1 + 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index 7fa7ce9d4db..175ced8c772 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -42,31 +42,31 @@ bool isEmojiBase(uint32_t c) { return (c == 0x261D || c == 0x26F9 || (0x270A <= c && c <= 0x270D)); } else if (0x1F385 <= c && c <= 0x1F93E) { return (c == 0x1F385 - || (0x1F3C3 <= c || c <= 0x1F3C4) - || (0x1F3CA <= c || c <= 0x1F3CB) - || (0x1F442 <= c || c <= 0x1F443) - || (0x1F446 <= c || c <= 0x1F450) - || (0x1F466 <= c || c <= 0x1F469) + || (0x1F3C3 <= c && c <= 0x1F3C4) + || (0x1F3CA <= c && c <= 0x1F3CB) + || (0x1F442 <= c && c <= 0x1F443) + || (0x1F446 <= c && c <= 0x1F450) + || (0x1F466 <= c && c <= 0x1F469) || c == 0x1F46E - || (0x1F470 <= c || c <= 0x1F478) + || (0x1F470 <= c && c <= 0x1F478) || c == 0x1F47C - || (0x1F481 <= c || c <= 0x1F483) - || (0x1F485 <= c || c <= 0x1F487) + || (0x1F481 <= c && c <= 0x1F483) + || (0x1F485 <= c && c <= 0x1F487) || c == 0x1F4AA || c == 0x1F575 || c == 0x1F57A || c == 0x1F590 - || (0x1F595 <= c || c <= 0x1F596) - || (0x1F645 <= c || c <= 0x1F647) - || (0x1F64B <= c || c <= 0x1F64F) + || (0x1F595 <= c && c <= 0x1F596) + || (0x1F645 <= c && c <= 0x1F647) + || (0x1F64B <= c && c <= 0x1F64F) || c == 0x1F6A3 - || (0x1F6B4 <= c || c <= 0x1F6B6) + || (0x1F6B4 <= c && c <= 0x1F6B6) || c == 0x1F6C0 - || (0x1F918 <= c || c <= 0x1F91E) + || (0x1F918 <= c && c <= 0x1F91E) || c == 0x1F926 || c == 0x1F930 - || (0x1F933 <= c || c <= 0x1F939) - || (0x1F93B <= c || c <= 0x1F93E)); + || (0x1F933 <= c && c <= 0x1F939) + || (0x1F93B <= c && c <= 0x1F93E)); } else { return false; } diff --git a/engine/src/flutter/tests/GraphemeBreakTests.cpp b/engine/src/flutter/tests/GraphemeBreakTests.cpp index dbd73be2b15..7e1720384cf 100644 --- a/engine/src/flutter/tests/GraphemeBreakTests.cpp +++ b/engine/src/flutter/tests/GraphemeBreakTests.cpp @@ -155,6 +155,7 @@ TEST(GraphemeBreak, emojiModifiers) { EXPECT_TRUE(IsBreak("U+2764 | U+1F3FB")); // heart + modifier EXPECT_TRUE(IsBreak("U+2764 U+FE0E | U+1F3FB")); // heart + emoji style + modifier EXPECT_TRUE(IsBreak("U+2764 U+FE0F | U+1F3FB")); // heart + emoji style + modifier + EXPECT_TRUE(IsBreak("U+1F3FB | U+1F3FB")); // modifier + modifier // rat is not an emoji modifer EXPECT_TRUE(IsBreak("U+1F466 | U+1F400")); // boy + rat From f4c679ca680ed79d2a9dee20d375c87f187149b6 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 2 Mar 2016 13:53:54 -0800 Subject: [PATCH 169/364] Break regional indicators at even numbered code points. Bug: 23288449 Change-Id: If1419ff9e44e8e640616979bae88311f414b42a1 --- .../flutter/libs/minikin/GraphemeBreak.cpp | 27 ++++++++++++------- .../src/flutter/tests/GraphemeBreakTests.cpp | 16 +++++++++++ 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index ef323d5d489..1f361ba1a75 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -15,6 +15,7 @@ */ #include +#include #include #include @@ -124,17 +125,25 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co if ((p1 == U_GCB_LVT || p1 == U_GCB_T) && p2 == U_GCB_T) { return false; } - // Rule GB8a, Regional_Indicator x Regional_Indicator + // Rule GB8a that looks at even-off cases. // - // Known limitation: This is overly conservative, and returns no grapheme breaks between two - // flags, such as in the character sequence "U+1F1FA U+1F1F8 [potential break] U+1F1FA U+1F1F8". - // Also, it assumes that all combinations of Regional Indicators produce a flag, where they - // don't. - // - // There is no easy solution for doing this correctly, except for querying the font and doing - // some lookback. + // sot (RI RI)* RI x RI + // [^RI] (RI RI)* RI x RI + // RI ÷ RI if (p1 == U_GCB_REGIONAL_INDICATOR && p2 == U_GCB_REGIONAL_INDICATOR) { - return false; + // Look at up to 1000 code units. + start = std::max((ssize_t)start, (ssize_t)offset_back - 1000); + while (offset_back > start) { + U16_PREV(buf, start, offset_back, c1); + if (tailoredGraphemeClusterBreak(c1) != U_GCB_REGIONAL_INDICATOR) { + offset_back += U16_LENGTH(c1); + break; + } + } + + // Note that the offset has moved forwared 2 code units by U16_NEXT. + // The number 4 comes from the number of code units in a whole flag. + return (offset - 2 - offset_back) % 4 == 0; } // Rule GB9, x Extend; Rule GB9a, x SpacingMark; Rule GB9b, Prepend x if (p2 == U_GCB_EXTEND || p2 == U_GCB_SPACING_MARK || p1 == U_GCB_PREPEND) { diff --git a/engine/src/flutter/tests/GraphemeBreakTests.cpp b/engine/src/flutter/tests/GraphemeBreakTests.cpp index 7e1720384cf..3bfa5ecd8be 100644 --- a/engine/src/flutter/tests/GraphemeBreakTests.cpp +++ b/engine/src/flutter/tests/GraphemeBreakTests.cpp @@ -84,6 +84,22 @@ TEST(GraphemeBreak, rules) { // Rule GB8a, Regional_Indicator x Regional_Indicator EXPECT_FALSE(IsBreak("U+1F1FA | U+1F1F8")); + EXPECT_TRUE(IsBreak("U+1F1FA U+1F1F8 | U+1F1FA U+1F1F8")); // Regional indicator pair (flag) + EXPECT_FALSE(IsBreak("U+1F1FA | U+1F1F8 U+1F1FA U+1F1F8")); // Regional indicator pair (flag) + EXPECT_FALSE(IsBreak("U+1F1FA U+1F1F8 U+1F1FA | U+1F1F8")); // Regional indicator pair (flag) + + EXPECT_TRUE(IsBreak("U+1F1FA U+1F1F8 | U+1F1FA")); // Regional indicator pair (flag) + EXPECT_FALSE(IsBreak("U+1F1FA | U+1F1F8 U+1F1FA")); // Regional indicator pair (flag) + + EXPECT_TRUE(IsBreak("'a' U+1F1FA U+1F1F8 | U+1F1FA")); // Regional indicator pair (flag) + EXPECT_FALSE(IsBreak("'a' U+1F1FA | U+1F1F8 U+1F1FA")); // Regional indicator pair (flag) + + EXPECT_TRUE( + IsBreak("'a' U+1F1FA U+1F1F8 | U+1F1FA U+1F1F8")); // Regional indicator pair (flag) + EXPECT_FALSE( + IsBreak("'a' U+1F1FA | U+1F1F8 U+1F1FA U+1F1F8")); // Regional indicator pair (flag) + EXPECT_FALSE( + IsBreak("'a' U+1F1FA U+1F1F8 U+1F1FA | U+1F1F8")); // Regional indicator pair (flag) // Rule GB9, x Extend EXPECT_FALSE(IsBreak("'a' | U+0301")); // combining accent From 5ccdf654f5695be1b582a3bd89482bc6915cc22a Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 3 Mar 2016 15:33:33 -0800 Subject: [PATCH 170/364] Suppress log span due to returning null for itemize result. Bug: 26808815 Change-Id: I2a5a52f2c441d27c7ef270342b4ef93c3de9e56e --- .../flutter/include/minikin/FontCollection.h | 2 ++ .../flutter/libs/minikin/FontCollection.cpp | 14 +++------- .../tests/FontCollectionItemizeTest.cpp | 28 ++++++++++++++++--- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 5b9424c958b..c3c183db3b0 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -84,9 +84,11 @@ private: uint32_t mMaxChar; // This vector has ownership of the bitsets and typeface objects. + // This vector can't be empty. std::vector mFamilies; // This vector contains pointers into mInstances + // This vector can't be empty. std::vector mFamilyVec; // This vector has pointers to the font family instance which has cmap 14 subtable. diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 4541af84757..e2582508ef1 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -230,10 +230,11 @@ uint32_t FontCollection::calcVariantMatchingScore(int variant, const FontFamily& // 1. If first font in the collection has the character, it wins. // 2. Calculate a score for the font family. See comments in calcFamilyScore for the detail. // 3. Highest score wins, with ties resolved to the first font. +// This method never returns nullptr. FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const { if (ch >= mMaxChar) { - return NULL; + return mFamilies[0]; } const std::vector* familyVec = &mFamilyVec; @@ -272,7 +273,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, bestFamily = family; } } - if (bestFamily == nullptr && !mFamilyVec.empty()) { + if (bestFamily == nullptr) { UErrorCode errorCode = U_ZERO_ERROR; const UNormalizer2* normalizer = unorm2_getNFDInstance(&errorCode); if (U_SUCCESS(errorCode)) { @@ -396,11 +397,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty Run dummy; result->push_back(dummy); run = &result->back(); - if (family == NULL) { - run->fakedFont.font = NULL; - } else { - run->fakedFont = family->getClosestMatch(style); - } + run->fakedFont = family->getClosestMatch(style); lastFamily = family; run->start = start; } @@ -415,9 +412,6 @@ MinikinFont* FontCollection::baseFont(FontStyle style) { } FakedFont FontCollection::baseFontFaked(FontStyle style) { - if (mFamilies.empty()) { - return FakedFont(); - } return mFamilies[0]->getClosestMatch(style); } diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index 031f3f98f3a..22971c8523f 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -1156,7 +1156,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); + EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); // U+231A is a emoji default emoji which is available only in TextEmojifFont. // TextEmojiFont.ttf sohuld be selected. @@ -1190,7 +1190,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); + EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); // U+26FA U+FE0E is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. @@ -1239,7 +1239,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); + EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); // U+231A is a emoji default emoji which is available only in TextEmojiFont.ttf. // TextEmojiFont.ttf should be selected. @@ -1272,7 +1272,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); - EXPECT_TRUE(runs[0].fakedFont.font == NULL || kNoGlyphFont == getFontPath(runs[0])); + EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); // U+26F9 U+FE0F is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. @@ -1321,3 +1321,23 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_with_skinTone) { EXPECT_EQ(4, runs[1].end); EXPECT_EQ(kColorEmojiFont, getFontPath(runs[1])); } + +TEST_F(FontCollectionItemizeTest, itemize_PrivateUseArea) { + std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); + std::vector runs; + + const FontStyle kDefaultFontStyle; + + // Should not set nullptr to the result run. (Issue 26808815) + itemize(collection.get(), "U+FEE10", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(2, runs[0].end); + EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+FEE40 U+FE4C5", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(4, runs[0].end); + EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); +} From 0eaf80b016b6780250227b8273692d2b8978816f Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 16 Mar 2016 15:23:20 -0700 Subject: [PATCH 171/364] Do not allow line breaks before currency symbols Implement the change proposed in UTC document L2/16-043R (http://www.unicode.org/L2/L2016/16043r-line-break-pr-po.txt) to make sure we do not break between letters and currency symbols. Bug: 24959657 Change-Id: Ia29d0e5625f84870bd910d0c6e19036d17206704 --- engine/src/flutter/libs/minikin/WordBreaker.cpp | 13 +++++++++++++ engine/src/flutter/tests/WordBreakerTests.cpp | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index 721c5bf0ebe..d420a6a0a87 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -79,6 +79,18 @@ static bool isBreakValid(const uint16_t* buf, size_t bufEnd, size_t i) { uint32_t next_codepoint; size_t next_offset = i; U16_NEXT(buf, next_offset, bufEnd, next_codepoint); + + // Proposed change to LB24 from http://www.unicode.org/L2/L2016/16043r-line-break-pr-po.txt + //(AL | HL) × (PR | PO) + int32_t lineBreak = u_getIntPropertyValue(codePoint, UCHAR_LINE_BREAK); + if (lineBreak == U_LB_ALPHABETIC || lineBreak == U_LB_HEBREW_LETTER) { + lineBreak = u_getIntPropertyValue(next_codepoint, UCHAR_LINE_BREAK); + if (lineBreak == U_LB_PREFIX_NUMERIC || lineBreak == U_LB_POSTFIX_NUMERIC) { + return false; + } + } + + // Known emoji ZWJ sequences if (codePoint == CHAR_ZWJ) { // Possible emoji ZWJ sequence if (next_codepoint == 0x2764 || // HEAVY BLACK HEART @@ -91,6 +103,7 @@ static bool isBreakValid(const uint16_t* buf, size_t bufEnd, size_t i) { return false; } } + // Proposed Rule LB30b from http://www.unicode.org/L2/L2016/16011r3-break-prop-emoji.pdf // EB x EM if (isEmojiModifier(next_codepoint)) { diff --git a/engine/src/flutter/tests/WordBreakerTests.cpp b/engine/src/flutter/tests/WordBreakerTests.cpp index cb12722562e..480c57da965 100644 --- a/engine/src/flutter/tests/WordBreakerTests.cpp +++ b/engine/src/flutter/tests/WordBreakerTests.cpp @@ -69,6 +69,22 @@ TEST_F(WordBreakerTest, softHyphen) { EXPECT_EQ(0, breaker.breakBadness()); } +TEST_F(WordBreakerTest, postfixAndPrefix) { + uint16_t buf[] = {'U', 'S', 0x00A2, ' ', 'J', 'P', 0x00A5}; // US¢ JP¥ + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + + EXPECT_EQ(4, breaker.next()); // after CENT SIGN + EXPECT_EQ(0, breaker.wordStart()); // "US¢" + EXPECT_EQ(3, breaker.wordEnd()); + + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end of string + EXPECT_EQ(4, breaker.wordStart()); // "JP¥" + EXPECT_EQ((ssize_t)NELEM(buf), breaker.wordEnd()); +} + TEST_F(WordBreakerTest, zwjEmojiSequences) { uint16_t buf[] = { // man + zwj + heart + zwj + man From c9c0359b1d0711c0dceeef7c853c6377c6a2af08 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 30 Mar 2016 17:48:34 -0700 Subject: [PATCH 172/364] Try putting combining marks in the same font run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Indic combining marks, when combined with a common character such as a hyphen or a dotted circle, used to get rendered in a different font due to the greedy algorithm used in determining runs, which resulted in the base character and the combining mark getting rendered in separate font runs, resulting in a dotted circle appearing in phrases such as "100-ാം" (0031 0030 0030 002D 0D3E 0D02). This change makes combining marks change the font run of the base character if the base character is supported in the same font as the combining mark, similar to the support for emoji modifiers and the combining keycap. Bug: 25036888 Bug: 24535344 Change-Id: I8e2798e8ecb8efaf723a0fd02c05c6fbdef8b365 --- .../src/flutter/libs/minikin/FontCollection.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index e2582508ef1..5f669a176a0 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -293,14 +293,13 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, const uint32_t NBSP = 0xa0; const uint32_t ZWJ = 0x200c; const uint32_t ZWNJ = 0x200d; -const uint32_t KEYCAP = 0x20e3; const uint32_t HYPHEN = 0x2010; const uint32_t NB_HYPHEN = 0x2011; // Characters where we want to continue using existing font run instead of // recomputing the best match in the fallback list. static const uint32_t stickyWhitelist[] = { '!', ',', '-', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ, - KEYCAP, HYPHEN, NB_HYPHEN }; + HYPHEN, NB_HYPHEN }; static bool isStickyWhitelisted(uint32_t c) { for (size_t i = 0; i < sizeof(stickyWhitelist) / sizeof(stickyWhitelist[0]); i++) { @@ -380,12 +379,14 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty langListId, variant); if (utf16Pos == 0 || family != lastFamily) { size_t start = utf16Pos; - // Workaround for Emoji keycap and emoji modifier until we implement per-cluster - // font selection: if a keycap or an emoji modifier is found in a different font - // that also supports previous char, attach previous char to the new run. - // Bug 7557244. + // Workaround for combining marks and emoji modifiers until we implement + // per-cluster font selection: if a combining mark or an emoji modifier is found in + // a different font that also supports the previous character, attach previous + // character to the new run. U+20E3 COMBINING ENCLOSING KEYCAP, used in emoji, is + // handled properly by this since it's a combining mark too. if (utf16Pos != 0 && - (ch == KEYCAP || (isEmojiModifier(ch) && isEmojiBase(prevCh))) && + ((U_GET_GC_MASK(ch) & U_GC_M_MASK) != 0 || + (isEmojiModifier(ch) && isEmojiBase(prevCh))) && family && family->getCoverage()->get(prevCh)) { const size_t prevChLength = U16_LENGTH(prevCh); run->end -= prevChLength; From dbcbe1f426b17242f2c548fb3df5e2b6a659ac50 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Mon, 25 Jan 2016 15:25:16 +0900 Subject: [PATCH 173/364] Support multiple locales for font language settings. Some fonts support multiple scripts, for example, some fonts for Korean supports not only "Kore" but also "Jamo". To select fonts based on their multiple languages, this CL introduces the following changes: - Compares all languages of the font family and use the maximum score for font selection. - Even if each language of the font family doesn't support the requested language, the font get score of 2 if the requested font is covered by all of the languages of the font family. For example, the font for "ko-Hang,ko-Hani" gets score of 2 for the requested language "ko-Kore". Bug: 26687969 Change-Id: I7f13b51464c9b01982bb573251d77052b9ddbd70 --- .../flutter/libs/minikin/FontCollection.cpp | 21 ++-- .../src/flutter/libs/minikin/FontLanguage.cpp | 55 +++++++-- .../src/flutter/libs/minikin/FontLanguage.h | 44 ++++++- .../libs/minikin/FontLanguageListCache.cpp | 10 +- .../tests/FontCollectionItemizeTest.cpp | 114 +++++++++++------- engine/src/flutter/tests/FontFamilyTest.cpp | 35 +++--- .../tests/FontLanguageListCacheTest.cpp | 16 +-- 7 files changed, 197 insertions(+), 98 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 5f669a176a0..75cbd768937 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -177,9 +177,15 @@ uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, FontFamily* } if (vs == 0xFE0F || vs == 0xFE0E) { - // TODO use all language in the list. - const FontLanguage lang = FontLanguageListCache::getById(fontFamily->langId())[0]; - const bool hasEmojiFlag = lang.hasEmojiFlag(); + const FontLanguages& langs = FontLanguageListCache::getById(fontFamily->langId()); + bool hasEmojiFlag = false; + for (size_t i = 0; i < langs.size(); ++i) { + if (langs[i].hasEmojiFlag()) { + hasEmojiFlag = true; + break; + } + } + if (vs == 0xFE0F) { return hasEmojiFlag ? 2 : 1; } else { // vs == 0xFE0E @@ -208,13 +214,12 @@ uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, FontFamily* uint32_t FontCollection::calcLanguageMatchingScore( uint32_t userLangListId, const FontFamily& fontFamily) { const FontLanguages& langList = FontLanguageListCache::getById(userLangListId); - // TODO use all language in the list. - FontLanguage fontLanguage = FontLanguageListCache::getById(fontFamily.langId())[0]; + const FontLanguages& fontLanguages = FontLanguageListCache::getById(fontFamily.langId()); const size_t maxCompareNum = std::min(langList.size(), FONT_LANGUAGES_LIMIT); - uint32_t score = fontLanguage.getScoreFor(langList[0]); // maxCompareNum can't be zero. - for (size_t i = 1; i < maxCompareNum; ++i) { - score = score * 3u + fontLanguage.getScoreFor(langList[i]); + uint32_t score = 0; + for (size_t i = 0; i < maxCompareNum; ++i) { + score = score * 3u + langList[i].calcScoreFor(fontLanguages); } return score; } diff --git a/engine/src/flutter/libs/minikin/FontLanguage.cpp b/engine/src/flutter/libs/minikin/FontLanguage.cpp index db630592b8e..bccb4bf9e8f 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguage.cpp @@ -126,24 +126,59 @@ bool FontLanguage::isEqualScript(const FontLanguage& other) const { return other.mScript == mScript; } -bool FontLanguage::supportsScript(uint8_t requestedBits) const { - return requestedBits != 0 && (mSubScriptBits & requestedBits) == requestedBits; +// static +bool FontLanguage::supportsScript(uint8_t providedBits, uint8_t requestedBits) { + return requestedBits != 0 && (providedBits & requestedBits) == requestedBits; } bool FontLanguage::supportsHbScript(hb_script_t script) const { static_assert(SCRIPT_TAG('J', 'p', 'a', 'n') == HB_TAG('J', 'p', 'a', 'n'), "The Minikin script and HarfBuzz hb_script_t have different encodings."); if (script == mScript) return true; - return supportsScript(scriptToSubScriptBits(script)); + return supportsScript(mSubScriptBits, scriptToSubScriptBits(script)); } -int FontLanguage::getScoreFor(const FontLanguage other) const { - if (isUnsupported() || other.isUnsupported()) { - return 0; - } else if (isEqualScript(other) || supportsScript(other.mSubScriptBits)) { - return mLanguage == other.mLanguage ? 2 : 1; - } else { - return 0; +int FontLanguage::calcScoreFor(const FontLanguages& supported) const { + int score = 0; + for (size_t i = 0; i < supported.size(); ++i) { + if (isEqualScript(supported[i]) || + supportsScript(supported[i].mSubScriptBits, mSubScriptBits)) { + if (mLanguage == supported[i].mLanguage) { + return 2; + } else { + score = 1; + } + } + } + + if (score == 1) { + return score; + } + + if (supportsScript(supported.getUnionOfSubScriptBits(), mSubScriptBits)) { + // Gives score of 2 only if the language matches all of the font languages except for the + // exact match case handled above. + return (mLanguage == supported[0].mLanguage && supported.isAllTheSameLanguage()) ? 2 : 1; + } + + return 0; +} + +FontLanguages::FontLanguages(std::vector&& languages) + : mLanguages(std::move(languages)) { + if (mLanguages.empty()) { + return; + } + + const FontLanguage& lang = mLanguages[0]; + + mIsAllTheSameLanguage = true; + mUnionOfSubScriptBits = lang.mSubScriptBits; + for (size_t i = 1; i < mLanguages.size(); ++i) { + mUnionOfSubScriptBits |= mLanguages[i].mSubScriptBits; + if (mIsAllTheSameLanguage && lang.mLanguage != mLanguages[i].mLanguage) { + mIsAllTheSameLanguage = false; + } } } diff --git a/engine/src/flutter/libs/minikin/FontLanguage.h b/engine/src/flutter/libs/minikin/FontLanguage.h index 1a20480fb55..f944174a865 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.h +++ b/engine/src/flutter/libs/minikin/FontLanguage.h @@ -24,6 +24,11 @@ namespace android { +// Due to the limits in font fallback score calculation, we can't use anything more than 17 +// languages. +const size_t FONT_LANGUAGES_LIMIT = 17; +class FontLanguages; + // FontLanguage is a compact representation of a BCP 47 language tag. It // does not capture all possible information, only what directly affects // font rendering. @@ -54,12 +59,16 @@ public: std::string getString() const; + // Calculates a matching score. This score represents how well the input languages cover this + // language. The maximum score in the language list is returned. // 0 = no match, 1 = script match, 2 = script and primary language match. - int getScoreFor(const FontLanguage other) const; + int calcScoreFor(const FontLanguages& supported) const; uint64_t getIdentifier() const { return (uint64_t)mScript << 32 | (uint64_t)mLanguage; } private: + friend class FontLanguages; // for FontLanguages constructor + // ISO 15924 compliant script code. The 4 chars script code are packed into a 32 bit integer. uint32_t mScript; @@ -80,12 +89,37 @@ private: uint8_t mSubScriptBits; static uint8_t scriptToSubScriptBits(uint32_t script); - bool supportsScript(uint8_t requestedBits) const; + + // Returns true if the provide subscript bits has the requested subscript bits. + // Note that this function returns false if the requested subscript bits are empty. + static bool supportsScript(uint8_t providedBits, uint8_t requestedBits); }; -// Due to the limit of font fallback cost calculation, we can't use anything more than 17 languages. -const size_t FONT_LANGUAGES_LIMIT = 17; -typedef std::vector FontLanguages; +// An immutable list of languages. +class FontLanguages { +public: + FontLanguages(std::vector&& languages); + FontLanguages() : mUnionOfSubScriptBits(0), mIsAllTheSameLanguage(false) {} + FontLanguages(FontLanguages&&) = default; + + size_t size() const { return mLanguages.size(); } + bool empty() const { return mLanguages.empty(); } + const FontLanguage& operator[] (size_t n) const { return mLanguages[n]; } + +private: + friend struct FontLanguage; // for calcScoreFor + + std::vector mLanguages; + uint8_t mUnionOfSubScriptBits; + bool mIsAllTheSameLanguage; + + uint8_t getUnionOfSubScriptBits() const { return mUnionOfSubScriptBits; } + bool isAllTheSameLanguage() const { return mIsAllTheSameLanguage; } + + // Do not copy and assign. + FontLanguages(const FontLanguages&) = delete; + void operator=(const FontLanguages&) = delete; +}; } // namespace android diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp index 5d177b5827a..6b661f03846 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp @@ -76,8 +76,8 @@ static size_t toLanguageTag(char* output, size_t outSize, const std::string& loc return outLength; } -static FontLanguages constructFontLanguages(const std::string& input) { - FontLanguages result; +static std::vector parseLanguageList(const std::string& input) { + std::vector result; size_t currentIdx = 0; size_t commaLoc = 0; char langTag[ULOC_FULLNAME_CAPACITY]; @@ -121,11 +121,11 @@ uint32_t FontLanguageListCache::getId(const std::string& languages) { // Given language list is not in cache. Insert it and return newly assigned ID. const uint32_t nextId = inst->mLanguageLists.size(); - FontLanguages fontLanguages = constructFontLanguages(languages); + FontLanguages fontLanguages(parseLanguageList(languages)); if (fontLanguages.empty()) { return kEmptyListId; } - inst->mLanguageLists.push_back(fontLanguages); + inst->mLanguageLists.push_back(std::move(fontLanguages)); inst->mLanguageListLookupTable.insert(std::make_pair(languages, nextId)); return nextId; } @@ -146,7 +146,7 @@ FontLanguageListCache* FontLanguageListCache::getInstance() { // Insert an empty language list for mapping default language list to kEmptyListId. // The default language list has only one FontLanguage and it is the unsupported language. - instance->mLanguageLists.push_back(FontLanguages({FontLanguage()})); + instance->mLanguageLists.push_back(FontLanguages()); instance->mLanguageListLookupTable.insert(std::make_pair("", kEmptyListId)); } return instance; diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index 22971c8523f..45587e9d891 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -698,72 +698,104 @@ TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { struct TestCase { std::string userPreferredLanguages; - std::string fontLanguages; + std::vector fontLanguages; int selectedFontIndex; } testCases[] = { + // Font can specify empty language. + { "und", { "", "" }, 0 }, + { "und", { "", "en-Latn" }, 0 }, + { "en-Latn", { "", "" }, 0 }, + { "en-Latn", { "", "en-Latn" }, 1 }, + // Single user preferred language. // Exact match case - { "en-Latn", "en-Latn,ja-Jpan", 0 }, - { "ja-Jpan", "en-Latn,ja-Jpan", 1 }, - { "en-Latn", "en-Latn,nl-Latn,es-Latn", 0 }, - { "nl-Latn", "en-Latn,nl-Latn,es-Latn", 1 }, - { "es-Latn", "en-Latn,nl-Latn,es-Latn", 2 }, - { "es-Latn", "en-Latn,en-Latn,nl-Latn", 0 }, + { "en-Latn", { "en-Latn", "ja-Jpan" }, 0 }, + { "ja-Jpan", { "en-Latn", "ja-Jpan" }, 1 }, + { "en-Latn", { "en-Latn", "nl-Latn", "es-Latn" }, 0 }, + { "nl-Latn", { "en-Latn", "nl-Latn", "es-Latn" }, 1 }, + { "es-Latn", { "en-Latn", "nl-Latn", "es-Latn" }, 2 }, + { "es-Latn", { "en-Latn", "en-Latn", "nl-Latn" }, 0 }, // Exact script match case - { "en-Latn", "nl-Latn,be-Latn", 0 }, - { "en-Arab", "nl-Latn,ar-Arab", 1 }, - { "en-Latn", "be-Latn,ar-Arab,bd-Beng", 0 }, - { "en-Arab", "be-Latn,ar-Arab,bd-Beng", 1 }, - { "en-Beng", "be-Latn,ar-Arab,bd-Beng", 2 }, - { "en-Beng", "be-Latn,ar-Beng,bd-Beng", 1 }, - { "zh-Hant", "zh-Hant,zh-Hans", 0 }, - { "zh-Hans", "zh-Hant,zh-Hans", 1 }, + { "en-Latn", { "nl-Latn", "e-Latn" }, 0 }, + { "en-Arab", { "nl-Latn", "ar-Arab" }, 1 }, + { "en-Latn", { "be-Latn", "ar-Arab", "d-Beng" }, 0 }, + { "en-Arab", { "be-Latn", "ar-Arab", "d-Beng" }, 1 }, + { "en-Beng", { "be-Latn", "ar-Arab", "d-Beng" }, 2 }, + { "en-Beng", { "be-Latn", "ar-Beng", "d-Beng" }, 1 }, + { "zh-Hant", { "zh-Hant", "zh-Hans" }, 0 }, + { "zh-Hans", { "zh-Hant", "zh-Hans" }, 1 }, // Subscript match case, e.g. Jpan supports Hira. - { "en-Hira", "ja-Jpan", 0 }, - { "zh-Hani", "zh-Hans,zh-Hant", 0 }, - { "zh-Hani", "zh-Hant,zh-Hans", 0 }, - { "en-Hira", "zh-Hant,ja-Jpan,ja-Jpan", 1 }, + { "en-Hira", { "ja-Jpan" }, 0 }, + { "zh-Hani", { "zh-Hans", "zh-Hant" }, 0 }, + { "zh-Hani", { "zh-Hant", "zh-Hans" }, 0 }, + { "en-Hira", { "zh-Hant", "ja-Jpan", "ja-Jpan" }, 1 }, // Language match case - { "ja-Latn", "zh-Latn,ja-Latn", 1 }, - { "zh-Latn", "zh-Latn,ja-Latn", 0 }, - { "ja-Latn", "zh-Latn,ja-Latn", 1 }, - { "ja-Latn", "zh-Latn,ja-Latn,ja-Latn", 1 }, + { "ja-Latn", { "zh-Latn", "ja-Latn" }, 1 }, + { "zh-Latn", { "zh-Latn", "ja-Latn" }, 0 }, + { "ja-Latn", { "zh-Latn", "ja-Latn" }, 1 }, + { "ja-Latn", { "zh-Latn", "ja-Latn", "ja-Latn" }, 1 }, // Mixed case // Script/subscript match is strongest. - { "ja-Jpan", "en-Latn,ja-Latn,en-Jpan", 2 }, - { "ja-Hira", "en-Latn,ja-Latn,en-Jpan", 2 }, - { "ja-Hira", "en-Latn,ja-Latn,en-Jpan,en-Jpan", 2 }, + { "ja-Jpan", { "en-Latn", "ja-Latn", "en-Jpan" }, 2 }, + { "ja-Hira", { "en-Latn", "ja-Latn", "en-Jpan" }, 2 }, + { "ja-Hira", { "en-Latn", "ja-Latn", "en-Jpan", "en-Jpan" }, 2 }, // Language match only happens if the script matches. - { "ja-Hira", "en-Latn,ja-Latn", 0 }, - { "ja-Hira", "en-Jpan,ja-Jpan", 1 }, + { "ja-Hira", { "en-Latn", "ja-Latn" }, 0 }, + { "ja-Hira", { "en-Jpan", "ja-Jpan" }, 1 }, // Multiple languages. // Even if all fonts have the same score, use the 2nd language for better selection. - { "en-Latn,ja-Jpan", "zh-Hant,zh-Hans,ja-Jpan", 2 }, - { "en-Latn,nl-Latn", "es-Latn,be-Latn,nl-Latn", 2 }, - { "en-Latn,br-Latn,nl-Latn", "es-Latn,be-Latn,nl-Latn", 2 }, - { "en-Latn,br-Latn,nl-Latn", "es-Latn,be-Latn,nl-Latn,nl-Latn", 2 }, + { "en-Latn,ja-Jpan", { "zh-Hant", "zh-Hans", "ja-Jpan" }, 2 }, + { "en-Latn,nl-Latn", { "es-Latn", "be-Latn", "nl-Latn" }, 2 }, + { "en-Latn,br-Latn,nl-Latn", { "es-Latn", "be-Latn", "nl-Latn" }, 2 }, + { "en-Latn,br-Latn,nl-Latn", { "es-Latn", "be-Latn", "nl-Latn", "nl-Latn" }, 2 }, // Script score. - { "en-Latn,ja-Jpan", "en-Arab,en-Jpan", 1 }, - { "en-Latn,ja-Jpan", "en-Arab,en-Jpan,en-Jpan", 1 }, + { "en-Latn,ja-Jpan", { "en-Arab", "en-Jpan" }, 1 }, + { "en-Latn,ja-Jpan", { "en-Arab", "en-Jpan", "en-Jpan" }, 1 }, // Language match case - { "en-Latn,ja-Latn", "bd-Latn,ja-Latn", 1 }, - { "en-Latn,ja-Latn", "bd-Latn,ja-Latn,ja-Latn", 1 }, + { "en-Latn,ja-Latn", { "bd-Latn", "ja-Latn" }, 1 }, + { "en-Latn,ja-Latn", { "bd-Latn", "ja-Latn", "ja-Latn" }, 1 }, // Language match only happens if the script matches. - { "en-Latn,ar-Arab", "en-Beng,ar-Arab", 1 }, + { "en-Latn,ar-Arab", { "en-Beng", "ar-Arab" }, 1 }, + + // Multiple languages in the font settings. + { "ko-Jamo", { "ja-Jpan", "ko-Kore", "ko-Kore,ko-Jamo"}, 2 }, + { "en-Latn", { "ja-Jpan", "en-Latn,ja-Jpan"}, 1 }, + { "en-Latn", { "ja-Jpan", "ja-Jpan,en-Latn"}, 1 }, + { "en-Latn", { "ja-Jpan,zh-Hant", "en-Latn,ja-Jpan", "en-Latn"}, 1 }, + { "en-Latn", { "zh-Hant,ja-Jpan", "ja-Jpan,en-Latn", "en-Latn"}, 1 }, + + // Kore = Hang + Hani, etc. + { "ko-Kore", { "ko-Hang", "ko-Jamo,ko-Hani", "ko-Hang,ko-Hani"}, 2 }, + { "ja-Hrkt", { "ja-Hira", "ja-Kana", "ja-Hira,ja-Kana"}, 2 }, + { "ja-Jpan", { "ja-Hira", "ja-Kana", "ja-Hani", "ja-Hira,ja-Kana,ja-Hani"}, 3 }, + { "zh-Hanb", { "zh-Hant", "zh-Bopo", "zh-Hant,zh-Bopo"}, 2 }, + { "zh-Hanb", { "ja-Hanb", "zh-Hant,zh-Bopo"}, 1 }, + + // Language match with unified subscript bits. + { "zh-Hanb", { "zh-Hant", "zh-Bopo", "ja-Hant,ja-Bopo", "zh-Hant,zh-Bopo"}, 3 }, + { "zh-Hanb", { "zh-Hant", "zh-Bopo", "ja-Hant,zh-Bopo", "zh-Hant,zh-Bopo"}, 3 }, }; for (auto testCase : testCases) { + std::string fontLanguagesStr = "{"; + for (size_t i = 0; i < testCase.fontLanguages.size(); ++i) { + if (i != 0) { + fontLanguagesStr += ", "; + } + fontLanguagesStr += "\"" + testCase.fontLanguages[i] + "\""; + } + fontLanguagesStr += "}"; SCOPED_TRACE("Test of user preferred languages: \"" + testCase.userPreferredLanguages + - "\" with font languages: " + testCase.fontLanguages); + "\" with font languages: " + fontLanguagesStr); std::vector families; @@ -778,12 +810,10 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { // Each font family is associated with a specified language. All font families except for // the first font support U+9AA8. std::unordered_map fontLangIdxMap; - const FontLanguages& fontLanguages = registerAndGetFontLanguages(testCase.fontLanguages); - for (size_t i = 0; i < fontLanguages.size(); ++i) { - const FontLanguage& fontLanguage = fontLanguages[i]; + for (size_t i = 0; i < testCase.fontLanguages.size(); ++i) { FontFamily* family = new FontFamily( - FontStyle::registerLanguageList(fontLanguage.getString()), 0 /* variant */); + FontStyle::registerLanguageList(testCase.fontLanguages[i]), 0 /* variant */); MinikinFont* minikin_font = new MinikinFontForTest(kJAFont); family->addFont(minikin_font); families.push_back(family); diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index 34a92964dc6..907f3950bf8 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -30,7 +30,7 @@ namespace android { typedef ICUTestBase FontLanguagesTest; typedef ICUTestBase FontLanguageTest; -static FontLanguages createFontLanguages(const std::string& input) { +static const FontLanguages& createFontLanguages(const std::string& input) { AutoMutex _l(gMinikinLock); uint32_t langId = FontLanguageListCache::getId(input); return FontLanguageListCache::getById(langId); @@ -217,35 +217,30 @@ TEST_F(FontLanguagesTest, basicTests) { EXPECT_EQ(0u, emptyLangs.size()); FontLanguage english = createFontLanguage("en"); - FontLanguages singletonLangs = createFontLanguages("en"); + const FontLanguages& singletonLangs = createFontLanguages("en"); EXPECT_EQ(1u, singletonLangs.size()); EXPECT_EQ(english, singletonLangs[0]); FontLanguage french = createFontLanguage("fr"); - FontLanguages twoLangs = createFontLanguages("en,fr"); + const FontLanguages& twoLangs = createFontLanguages("en,fr"); EXPECT_EQ(2u, twoLangs.size()); EXPECT_EQ(english, twoLangs[0]); EXPECT_EQ(french, twoLangs[1]); } TEST_F(FontLanguagesTest, unsupportedLanguageTests) { - FontLanguage unsupportedLang = createFontLanguage("abcd"); - ASSERT_TRUE(unsupportedLang.isUnsupported()); + const FontLanguages& oneUnsupported = createFontLanguages("abcd-example"); + EXPECT_TRUE(oneUnsupported.empty()); - FontLanguages oneUnsupported = createFontLanguages("abcd-example"); - EXPECT_EQ(1u, oneUnsupported.size()); - EXPECT_TRUE(oneUnsupported[0].isUnsupported()); - - FontLanguages twoUnsupporteds = createFontLanguages("abcd-example,abcd-example"); - EXPECT_EQ(1u, twoUnsupporteds.size()); - EXPECT_TRUE(twoUnsupporteds[0].isUnsupported()); + const FontLanguages& twoUnsupporteds = createFontLanguages("abcd-example,abcd-example"); + EXPECT_TRUE(twoUnsupporteds.empty()); FontLanguage english = createFontLanguage("en"); - FontLanguages firstUnsupported = createFontLanguages("abcd-example,en"); + const FontLanguages& firstUnsupported = createFontLanguages("abcd-example,en"); EXPECT_EQ(1u, firstUnsupported.size()); EXPECT_EQ(english, firstUnsupported[0]); - FontLanguages lastUnsupported = createFontLanguages("en,abcd-example"); + const FontLanguages& lastUnsupported = createFontLanguages("en,abcd-example"); EXPECT_EQ(1u, lastUnsupported.size()); EXPECT_EQ(english, lastUnsupported[0]); } @@ -256,20 +251,20 @@ TEST_F(FontLanguagesTest, repeatedLanguageTests) { FontLanguage englishInLatn = createFontLanguage("en-Latn"); ASSERT_TRUE(english == englishInLatn); - FontLanguages langs = createFontLanguages("en,en-Latn"); + const FontLanguages& langs = createFontLanguages("en,en-Latn"); EXPECT_EQ(1u, langs.size()); EXPECT_EQ(english, langs[0]); // Country codes are ignored. - FontLanguages fr = createFontLanguages("fr,fr-CA,fr-FR"); + const FontLanguages& fr = createFontLanguages("fr,fr-CA,fr-FR"); EXPECT_EQ(1u, fr.size()); EXPECT_EQ(french, fr[0]); // The order should be kept. - langs = createFontLanguages("en,fr,en-Latn"); - EXPECT_EQ(2u, langs.size()); - EXPECT_EQ(english, langs[0]); - EXPECT_EQ(french, langs[1]); + const FontLanguages& langs2 = createFontLanguages("en,fr,en-Latn"); + EXPECT_EQ(2u, langs2.size()); + EXPECT_EQ(english, langs2[0]); + EXPECT_EQ(french, langs2[1]); } TEST_F(FontLanguagesTest, undEmojiTests) { diff --git a/engine/src/flutter/tests/FontLanguageListCacheTest.cpp b/engine/src/flutter/tests/FontLanguageListCacheTest.cpp index fbbd9376f04..2a046713c9c 100644 --- a/engine/src/flutter/tests/FontLanguageListCacheTest.cpp +++ b/engine/src/flutter/tests/FontLanguageListCacheTest.cpp @@ -56,18 +56,18 @@ TEST_F(FontLanguageListCacheTest, getById) { FontLanguage english = FontLanguageListCache::getById(enLangId)[0]; FontLanguage japanese = FontLanguageListCache::getById(jpLangId)[0]; - FontLanguages defLangs = FontLanguageListCache::getById(0); - EXPECT_EQ(1UL, defLangs.size()); - EXPECT_TRUE(defLangs[0].isUnsupported()); + const FontLanguages& defLangs = FontLanguageListCache::getById(0); + EXPECT_TRUE(defLangs.empty()); - FontLanguages langs = FontLanguageListCache::getById(FontLanguageListCache::getId("en")); + const FontLanguages& langs = FontLanguageListCache::getById(FontLanguageListCache::getId("en")); ASSERT_EQ(1UL, langs.size()); EXPECT_EQ(english, langs[0]); - langs = FontLanguageListCache::getById(FontLanguageListCache::getId("en,jp")); - ASSERT_EQ(2UL, langs.size()); - EXPECT_EQ(english, langs[0]); - EXPECT_EQ(japanese, langs[1]); + const FontLanguages& langs2 = + FontLanguageListCache::getById(FontLanguageListCache::getId("en,jp")); + ASSERT_EQ(2UL, langs2.size()); + EXPECT_EQ(english, langs2[0]); + EXPECT_EQ(japanese, langs2[1]); } } // android From 1ea4165cef7651770fe28a0eada3da593bb149ad Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Thu, 7 Apr 2016 12:20:12 -0700 Subject: [PATCH 174/364] Purge hb font on Minikin font destruction This patch eagerly purges the corresponding hb_font_t object from the HbFontCache when the underlying MinikinFont is destroyed. After that, the key will no longer be accessed, so having the entry is wastes memory. Bug: 27251075 Bug: 27860101 Change-Id: I1b98016133fe3baf6525ac37d970a65ddccadb4f --- .../src/flutter/include/minikin/MinikinFont.h | 2 ++ engine/src/flutter/libs/minikin/Android.mk | 1 + .../src/flutter/libs/minikin/HbFontCache.cpp | 10 +++++++ engine/src/flutter/libs/minikin/HbFontCache.h | 1 + .../src/flutter/libs/minikin/MinikinFont.cpp | 26 +++++++++++++++++++ 5 files changed, 40 insertions(+) create mode 100644 engine/src/flutter/libs/minikin/MinikinFont.cpp diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 2ad2151a311..5c0ab0f6810 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -96,6 +96,8 @@ class MinikinFontFreeType; class MinikinFont : public MinikinRefCounted { public: + virtual ~MinikinFont(); + virtual float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const = 0; diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 7cd6f6883cc..2b5ff0667f6 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -32,6 +32,7 @@ minikin_src_files := \ Measurement.cpp \ MinikinInternal.cpp \ MinikinRefCounted.cpp \ + MinikinFont.cpp \ MinikinFontFreeType.cpp \ SparseBitSet.cpp \ WordBreaker.cpp diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index 73308efab70..7a6b3c1c433 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -75,6 +75,10 @@ public: mCache.clear(); } + void remove(int32_t fontId) { + mCache.remove(fontId); + } + private: static const size_t kMaxEntries = 100; @@ -95,6 +99,12 @@ void purgeHbFontCacheLocked() { getFontCacheLocked()->clear(); } +void purgeHbFont(const MinikinFont* minikinFont) { + AutoMutex _l(gMinikinLock); + const int32_t fontId = minikinFont->GetUniqueId(); + getFontCacheLocked()->remove(fontId); +} + hb_font_t* getHbFontLocked(MinikinFont* minikinFont) { assertMinikinLocked(); static hb_font_t* nullFaceFont = nullptr; diff --git a/engine/src/flutter/libs/minikin/HbFontCache.h b/engine/src/flutter/libs/minikin/HbFontCache.h index 62564d35b9a..92e465ac40d 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.h +++ b/engine/src/flutter/libs/minikin/HbFontCache.h @@ -23,6 +23,7 @@ namespace android { class MinikinFont; void purgeHbFontCacheLocked(); +void purgeHbFont(const MinikinFont* minikinFont); hb_font_t* getHbFontLocked(MinikinFont* minikinFont); } // namespace android diff --git a/engine/src/flutter/libs/minikin/MinikinFont.cpp b/engine/src/flutter/libs/minikin/MinikinFont.cpp new file mode 100644 index 00000000000..d56ec9c7013 --- /dev/null +++ b/engine/src/flutter/libs/minikin/MinikinFont.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2016 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 +#include "HbFontCache.h" + +namespace android { + +MinikinFont::~MinikinFont() { + purgeHbFont(this); +} + +} // namespace android From a8e8948bd792b8c13bbcd5c59496c85c24a2952b Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 6 Apr 2016 15:19:34 -0700 Subject: [PATCH 175/364] Avoid copying of font table data The hb_font_t object holds on to tables of font data, acquired through the MinikinFont::GetTable interface, which is based on copying data into caller-owned buffers. Now that we're caching lots of hb_font_t's, the cost of these buffers is significant. This patch moves to a different interface, inspired by HarfBuzz's hb_reference_table API, where the font can provide a pointer to the actual font data (which will often be mmap'ed, so it doesn't even consume physical RAM). Bug: 27860101 Change-Id: Id766ab16a8d342bf7322a90e076e801271d527d4 --- .../src/flutter/include/minikin/MinikinFont.h | 22 ++++++++- .../include/minikin/MinikinFontFreeType.h | 5 +- .../src/flutter/libs/minikin/FontFamily.cpp | 25 ++++------ .../src/flutter/libs/minikin/HbFontCache.cpp | 47 ++++++++++--------- engine/src/flutter/libs/minikin/Layout.cpp | 1 + .../libs/minikin/MinikinFontFreeType.cpp | 32 ++++++++----- .../flutter/libs/minikin/MinikinInternal.cpp | 10 ++++ .../flutter/libs/minikin/MinikinInternal.h | 33 +++++++++++++ .../src/flutter/tests/MinikinFontForTest.cpp | 22 +++++---- engine/src/flutter/tests/MinikinFontForTest.h | 2 +- 10 files changed, 137 insertions(+), 62 deletions(-) diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 5c0ab0f6810..02982359d9d 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -94,6 +94,9 @@ struct MinikinRect { class MinikinFontFreeType; +// Callback for freeing data +typedef void (*MinikinDestroyFunc) (void* data); + class MinikinFont : public MinikinRefCounted { public: virtual ~MinikinFont(); @@ -104,8 +107,23 @@ public: virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint &paint) const = 0; - // If buf is NULL, just update size - virtual bool GetTable(uint32_t tag, uint8_t *buf, size_t *size) = 0; + virtual const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) = 0; + + // Override if font can provide access to raw data + virtual const void* GetFontData() const { + return nullptr; + } + + // Override if font can provide access to raw data + virtual size_t GetFontSize() const { + return 0; + } + + // Override if font can provide access to raw data. + // Returns index within OpenType collection + virtual int GetFontIndex() const { + return 0; + } virtual int32_t GetUniqueId() const = 0; diff --git a/engine/src/flutter/include/minikin/MinikinFontFreeType.h b/engine/src/flutter/include/minikin/MinikinFontFreeType.h index a957d124c77..535c2498a25 100644 --- a/engine/src/flutter/include/minikin/MinikinFontFreeType.h +++ b/engine/src/flutter/include/minikin/MinikinFontFreeType.h @@ -48,8 +48,9 @@ public: void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint& paint) const; - // If buf is NULL, just update size - bool GetTable(uint32_t tag, uint8_t *buf, size_t *size); + const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); + + // TODO: provide access to raw data, as an optimization. int32_t GetUniqueId() const; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 88448a10fd0..0f71f511ca0 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -77,15 +77,11 @@ FontFamily::~FontFamily() { bool FontFamily::addFont(MinikinFont* typeface) { AutoMutex _l(gMinikinLock); const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2'); - size_t os2Size = 0; - bool ok = typeface->GetTable(os2Tag, NULL, &os2Size); - if (!ok) return false; - UniquePtr os2Data(new uint8_t[os2Size]); - ok = typeface->GetTable(os2Tag, os2Data.get(), &os2Size); - if (!ok) return false; + HbBlob os2Table(getFontTable(typeface, os2Tag)); + if (os2Table.get() == nullptr) return false; int weight; bool italic; - if (analyzeStyle(os2Data.get(), os2Size, &weight, &italic)) { + if (analyzeStyle(os2Table.get(), os2Table.size(), &weight, &italic)) { //ALOGD("analyzed weight = %d, italic = %s", weight, italic ? "true" : "false"); FontStyle style(weight, italic); addFontLocked(typeface, style); @@ -165,20 +161,15 @@ const SparseBitSet* FontFamily::getCoverage() { const FontStyle defaultStyle; MinikinFont* typeface = getClosestMatch(defaultStyle).font; const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); - size_t cmapSize = 0; - if (!typeface->GetTable(cmapTag, NULL, &cmapSize)) { + HbBlob cmapTable(getFontTable(typeface, cmapTag)); + if (cmapTable.get() == nullptr) { ALOGE("Could not get cmap table size!\n"); // Note: This means we will retry on the next call to getCoverage, as we can't store // the failure. This is fine, as we assume this doesn't really happen in practice. return nullptr; } - UniquePtr cmapData(new uint8_t[cmapSize]); - if (!typeface->GetTable(cmapTag, cmapData.get(), &cmapSize)) { - ALOGE("Unexpected failure to read cmap table!\n"); - return nullptr; - } // TODO: Error check? - CmapCoverage::getCoverage(mCoverage, cmapData.get(), cmapSize, &mHasVSTable); + CmapCoverage::getCoverage(mCoverage, cmapTable.get(), cmapTable.size(), &mHasVSTable); #ifdef VERBOSE_DEBUG ALOGD("font coverage length=%d, first ch=%x\n", mCoverage.length(), mCoverage.nextSetBit(0)); @@ -198,7 +189,9 @@ bool FontFamily::hasVariationSelector(uint32_t codepoint, uint32_t variationSele MinikinFont* minikinFont = getClosestMatch(defaultStyle).font; hb_font_t* font = getHbFontLocked(minikinFont); uint32_t unusedGlyph; - return hb_font_get_glyph(font, codepoint, variationSelector, &unusedGlyph); + bool result = hb_font_get_glyph(font, codepoint, variationSelector, &unusedGlyph); + hb_font_destroy(font); + return result; } bool FontFamily::hasVSTable() const { diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index 7a6b3c1c433..9544dc2b11d 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -30,26 +30,18 @@ namespace android { static hb_blob_t* referenceTable(hb_face_t* /* face */, hb_tag_t tag, void* userData) { MinikinFont* font = reinterpret_cast(userData); - size_t length = 0; - bool ok = font->GetTable(tag, NULL, &length); - if (!ok) { - return 0; + MinikinDestroyFunc destroy = 0; + size_t size = 0; + const void* buffer = font->GetTable(tag, &size, &destroy); + if (buffer == nullptr) { + return nullptr; } - char* buffer = reinterpret_cast(malloc(length)); - if (!buffer) { - return 0; - } - ok = font->GetTable(tag, reinterpret_cast(buffer), &length); #ifdef VERBOSE_DEBUG - ALOGD("referenceTable %c%c%c%c length=%zd %d", - (tag >>24)&0xff, (tag>>16)&0xff, (tag>>8)&0xff, tag&0xff, length, ok); + ALOGD("referenceTable %c%c%c%c length=%zd", + (tag >>24)&0xff, (tag>>16)&0xff, (tag>>8)&0xff, tag&0xff, size); #endif - if (!ok) { - free(buffer); - return 0; - } - return hb_blob_create(const_cast(buffer), length, - HB_MEMORY_MODE_WRITABLE, buffer, free); + return hb_blob_create(reinterpret_cast(buffer), size, + HB_MEMORY_MODE_READONLY, const_cast(buffer), destroy); } class HbFontCache : private OnEntryRemoved { @@ -105,24 +97,37 @@ void purgeHbFont(const MinikinFont* minikinFont) { getFontCacheLocked()->remove(fontId); } +// Returns a new reference to a hb_font_t object, caller is +// responsible for calling hb_font_destroy() on it. hb_font_t* getHbFontLocked(MinikinFont* minikinFont) { assertMinikinLocked(); + // TODO: get rid of nullFaceFont static hb_font_t* nullFaceFont = nullptr; if (minikinFont == nullptr) { if (nullFaceFont == nullptr) { nullFaceFont = hb_font_create(nullptr); } - return nullFaceFont; + return hb_font_reference(nullFaceFont); } HbFontCache* fontCache = getFontCacheLocked(); const int32_t fontId = minikinFont->GetUniqueId(); hb_font_t* font = fontCache->get(fontId); if (font != nullptr) { - return font; + return hb_font_reference(font); } - hb_face_t* face = hb_face_create_for_tables(referenceTable, minikinFont, nullptr); + hb_face_t* face; + const void* buf = minikinFont->GetFontData(); + if (buf == nullptr) { + face = hb_face_create_for_tables(referenceTable, minikinFont, nullptr); + } else { + size_t size = minikinFont->GetFontSize(); + hb_blob_t* blob = hb_blob_create(reinterpret_cast(buf), size, + HB_MEMORY_MODE_READONLY, nullptr, nullptr); + face = hb_face_create(blob, minikinFont->GetFontIndex()); + hb_blob_destroy(blob); + } hb_font_t* parent_font = hb_font_create(face); hb_ot_font_set_funcs(parent_font); @@ -133,7 +138,7 @@ hb_font_t* getHbFontLocked(MinikinFont* minikinFont) { hb_font_destroy(parent_font); hb_face_destroy(face); fontCache->put(fontId, font); - return font; + return hb_font_reference(font); } } // namespace android diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 3a05acfd9d6..9c1d6a873a5 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -99,6 +99,7 @@ struct LayoutContext { void clearHbFonts() { for (size_t i = 0; i < hbFonts.size(); i++) { hb_font_set_funcs(hbFonts[i], nullptr, nullptr, nullptr); + hb_font_destroy(hbFonts[i]); } hbFonts.clear(); } diff --git a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp index c9eb456be5f..b9ea5d7dff8 100644 --- a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp @@ -41,8 +41,8 @@ MinikinFontFreeType::~MinikinFontFreeType() { float MinikinFontFreeType::GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const { FT_Set_Pixel_Sizes(mTypeface, 0, paint.size); - FT_UInt32 flags = FT_LOAD_DEFAULT; // TODO: respect hinting settings - FT_Fixed advance; + FT_UInt32 flags = FT_LOAD_DEFAULT; // TODO: respect hinting settings + FT_Fixed advance; FT_Get_Advance(mTypeface, glyph_id, flags, &advance); return advance * (1.0 / 65536); } @@ -52,18 +52,28 @@ void MinikinFontFreeType::GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph // TODO: NYI } -bool MinikinFontFreeType::GetTable(uint32_t tag, uint8_t *buf, size_t *size) { - FT_ULong ftsize = *size; - FT_Error error = FT_Load_Sfnt_Table(mTypeface, tag, 0, buf, &ftsize); - if (error != 0) { - return false; - } - *size = ftsize; - return true; +const void* MinikinFontFreeType::GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) { + FT_ULong ftsize = 0; + FT_Error error = FT_Load_Sfnt_Table(mTypeface, tag, 0, nullptr, &ftsize); + if (error != 0) { + return nullptr; + } + FT_Byte* buf = reinterpret_cast(malloc(ftsize)); + if (buf == nullptr) { + return nullptr; + } + error = FT_Load_Sfnt_Table(mTypeface, tag, 0, buf, &ftsize); + if (error != 0) { + free(buf); + return nullptr; + } + *destroy = free; + *size = ftsize; + return buf; } int32_t MinikinFontFreeType::GetUniqueId() const { - return mUniqueId; + return mUniqueId; } bool MinikinFontFreeType::Render(uint32_t glyph_id, const MinikinPaint& /* paint */, diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index 175ced8c772..e00f63951bf 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -17,6 +17,7 @@ // Definitions internal to Minikin #include "MinikinInternal.h" +#include "HbFontCache.h" #include @@ -72,4 +73,13 @@ bool isEmojiBase(uint32_t c) { } } +hb_blob_t* getFontTable(MinikinFont* minikinFont, uint32_t tag) { + assertMinikinLocked(); + hb_font_t* font = getHbFontLocked(minikinFont); + hb_face_t* face = hb_font_get_face(font); + hb_blob_t* blob = hb_face_reference_table(face, tag); + hb_font_destroy(font); + return blob; +} + } diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.h b/engine/src/flutter/libs/minikin/MinikinInternal.h index 3d68691b35d..709fb9f691a 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.h +++ b/engine/src/flutter/libs/minikin/MinikinInternal.h @@ -19,8 +19,12 @@ #ifndef MINIKIN_INTERNAL_H #define MINIKIN_INTERNAL_H +#include + #include +#include + namespace android { // All external Minikin interfaces are designed to be thread-safe. @@ -38,6 +42,35 @@ bool isEmojiBase(uint32_t c); // Returns true if c is emoji modifier. bool isEmojiModifier(uint32_t c); +hb_blob_t* getFontTable(MinikinFont* minikinFont, uint32_t tag); + +// An RAII wrapper for hb_blob_t +class HbBlob { +public: + // Takes ownership of hb_blob_t object, caller is no longer + // responsible for calling hb_blob_destroy(). + HbBlob(hb_blob_t* blob) : mBlob(blob) { + } + + ~HbBlob() { + hb_blob_destroy(mBlob); + } + + const uint8_t* get() const { + const char* data = hb_blob_get_data(mBlob, nullptr); + return reinterpret_cast(data); + } + + size_t size() const { + unsigned int length = 0; + hb_blob_get_data(mBlob, &length); + return (size_t)length; + } + +private: + hb_blob_t* mBlob; +}; + } #endif // MINIKIN_INTERNAL_H diff --git a/engine/src/flutter/tests/MinikinFontForTest.cpp b/engine/src/flutter/tests/MinikinFontForTest.cpp index ed7075188b5..96f3326d2a0 100644 --- a/engine/src/flutter/tests/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/MinikinFontForTest.cpp @@ -40,16 +40,20 @@ void MinikinFontForTest::GetBounds(android::MinikinRect* /* bounds */, uint32_t LOG_ALWAYS_FATAL("MinikinFontForTest::GetBounds is not yet implemented"); } -bool MinikinFontForTest::GetTable(uint32_t tag, uint8_t *buf, size_t *size) { - if (buf == NULL) { - const size_t tableSize = mTypeface->getTableSize(tag); - *size = tableSize; - return tableSize != 0; - } else { - const size_t actualSize = mTypeface->getTableData(tag, 0, *size, buf); - *size = actualSize; - return actualSize != 0; +const void* MinikinFontForTest::GetTable(uint32_t tag, size_t* size, + android::MinikinDestroyFunc* destroy) { + const size_t tableSize = mTypeface->getTableSize(tag); + *size = tableSize; + if (tableSize == 0) { + return nullptr; } + void* buf = malloc(tableSize); + if (buf == nullptr) { + return nullptr; + } + mTypeface->getTableData(tag, 0, tableSize, buf); + *destroy = free; + return buf; } int32_t MinikinFontForTest::GetUniqueId() const { diff --git a/engine/src/flutter/tests/MinikinFontForTest.h b/engine/src/flutter/tests/MinikinFontForTest.h index 790348deaea..4686f7ab20a 100644 --- a/engine/src/flutter/tests/MinikinFontForTest.h +++ b/engine/src/flutter/tests/MinikinFontForTest.h @@ -30,7 +30,7 @@ public: float GetHorizontalAdvance(uint32_t glyph_id, const android::MinikinPaint &paint) const; void GetBounds(android::MinikinRect* bounds, uint32_t glyph_id, const android::MinikinPaint& paint) const; - bool GetTable(uint32_t tag, uint8_t *buf, size_t *size); + const void* GetTable(uint32_t tag, size_t* size, android::MinikinDestroyFunc* destroy); int32_t GetUniqueId() const; const std::string& fontPath() const { return mFontPath; } From d2161cf80f6f23bb977d92f79e49fba999846c79 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Fri, 8 Apr 2016 10:28:47 -0700 Subject: [PATCH 176/364] Update minikin/sample code to use new GetTable We changed the signature of the MinikinFont::GetTable method. This patch updates the sample code, and fixes the build. Change-Id: I1977be868bf7636986fc802915f3dd54c418a73a --- engine/src/flutter/sample/MinikinSkia.cpp | 22 +++++++++++++--------- engine/src/flutter/sample/MinikinSkia.h | 3 +-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/engine/src/flutter/sample/MinikinSkia.cpp b/engine/src/flutter/sample/MinikinSkia.cpp index feda8adff19..c4971bb6e18 100644 --- a/engine/src/flutter/sample/MinikinSkia.cpp +++ b/engine/src/flutter/sample/MinikinSkia.cpp @@ -47,16 +47,20 @@ void MinikinFontSkia::GetBounds(MinikinRect* bounds, uint32_t glyph_id, bounds->mBottom = skBounds.fBottom; } -bool MinikinFontSkia::GetTable(uint32_t tag, uint8_t *buf, size_t *size) { - if (buf == NULL) { - const size_t tableSize = mTypeface->getTableSize(tag); - *size = tableSize; - return tableSize != 0; - } else { - const size_t actualSize = mTypeface->getTableData(tag, 0, *size, buf); - *size = actualSize; - return actualSize != 0; +const void* MinikinFontSkia::GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) { + // we don't have a buffer to the font data, copy to own buffer + const size_t tableSize = mTypeface->getTableSize(tag); + *size = tableSize; + if (tableSize == 0) { + return nullptr; } + void* buf = malloc(tableSize); + if (buf == nullptr) { + return nullptr; + } + mTypeface->getTableData(tag, 0, tableSize, buf); + *destroy = free; + return buf; } SkTypeface *MinikinFontSkia::GetSkTypeface() { diff --git a/engine/src/flutter/sample/MinikinSkia.h b/engine/src/flutter/sample/MinikinSkia.h index 25ac1b0c081..e1d7bf6da3b 100644 --- a/engine/src/flutter/sample/MinikinSkia.h +++ b/engine/src/flutter/sample/MinikinSkia.h @@ -12,8 +12,7 @@ public: void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint& paint) const; - // If buf is NULL, just update size - bool GetTable(uint32_t tag, uint8_t *buf, size_t *size); + const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); int32_t GetUniqueId() const; From bb8b7fd32fd69c8b227996c782622f7941a944cb Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Mon, 11 Apr 2016 17:53:34 +0900 Subject: [PATCH 177/364] Fix minikin_unittests This CL fixes following test cases in minikin_tests - FontFamilyTest.hasVariationSelectorTest - HbFontCacheTest.getHbFontLockedTest - HbFontCacheTest.purgeCacheTest For the fix of FontFamilyTest.hasVariationSelectorTest, removing virtual from GetUniqueId() in MinikinFont. After [1], MinikinFont's destructor started calling purgeHbCache() which calls virtual method, MinikinFont::GetUniqueId(). Fortunately, the SkTypeface::uniqueID() returns just internal value, so we can store it at the construction time and use it instead of calling SkTypeface::uniqueID() every time. This patch also changes purgeHbFont to purgeHbFontLocked, as all uses of it were already under global mutex. This change avoids deadlock on explicit unref, as when invoked by a Java finalizer from the Java object that holds a reference to the font. Some of the tests needed to change to using the ref counting protocol rather than explicitly destructing font objects, as well. [1] 1ea4165cef7651770fe28a0eada3da593bb149ad Bug: 28105730 Bug: 28105688 Change-Id: Ie5983c4869147dacabdca81af1605066cd680b3f --- .../src/flutter/include/minikin/MinikinFont.h | 8 +++- .../include/minikin/MinikinFontFreeType.h | 3 -- .../include/minikin/MinikinRefCounted.h | 17 +++++++++ .../src/flutter/libs/minikin/HbFontCache.cpp | 4 +- engine/src/flutter/libs/minikin/HbFontCache.h | 2 +- .../src/flutter/libs/minikin/MinikinFont.cpp | 2 +- .../libs/minikin/MinikinFontFreeType.cpp | 6 +-- engine/src/flutter/sample/MinikinSkia.cpp | 5 +-- engine/src/flutter/sample/MinikinSkia.h | 2 - engine/src/flutter/tests/FontFamilyTest.cpp | 37 ++++++++++--------- .../src/flutter/tests/MinikinFontForTest.cpp | 14 ++++--- engine/src/flutter/tests/MinikinFontForTest.h | 2 +- engine/src/flutter/tests/how_to_run.txt | 2 +- 13 files changed, 58 insertions(+), 46 deletions(-) diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 02982359d9d..4951514518f 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -99,6 +99,8 @@ typedef void (*MinikinDestroyFunc) (void* data); class MinikinFont : public MinikinRefCounted { public: + MinikinFont(int32_t uniqueId) : mUniqueId(uniqueId) {} + virtual ~MinikinFont(); virtual float GetHorizontalAdvance(uint32_t glyph_id, @@ -125,12 +127,14 @@ public: return 0; } - virtual int32_t GetUniqueId() const = 0; - static uint32_t MakeTag(char c1, char c2, char c3, char c4) { return ((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) | ((uint32_t)c3 << 8) | (uint32_t)c4; } + + int32_t GetUniqueId() const { return mUniqueId; } +private: + const int32_t mUniqueId; }; } // namespace android diff --git a/engine/src/flutter/include/minikin/MinikinFontFreeType.h b/engine/src/flutter/include/minikin/MinikinFontFreeType.h index 535c2498a25..baa08df3b71 100644 --- a/engine/src/flutter/include/minikin/MinikinFontFreeType.h +++ b/engine/src/flutter/include/minikin/MinikinFontFreeType.h @@ -52,8 +52,6 @@ public: // TODO: provide access to raw data, as an optimization. - int32_t GetUniqueId() const; - // Not a virtual method, as the protocol to access rendered // glyph bitmaps is probably different depending on the // backend. @@ -64,7 +62,6 @@ public: private: FT_Face mTypeface; - int32_t mUniqueId; static int32_t sIdCounter; }; diff --git a/engine/src/flutter/include/minikin/MinikinRefCounted.h b/engine/src/flutter/include/minikin/MinikinRefCounted.h index 74d27fec7d3..603aff0cce9 100644 --- a/engine/src/flutter/include/minikin/MinikinRefCounted.h +++ b/engine/src/flutter/include/minikin/MinikinRefCounted.h @@ -37,6 +37,23 @@ private: int mRefcount_; }; +// An RAII container for reference counted objects. +// Note: this is only suitable for clients which are _not_ holding the global lock. +template +class MinikinAutoUnref { +public: + MinikinAutoUnref(T* obj) : mObj(obj) { + } + ~MinikinAutoUnref() { + mObj->Unref(); + } + T& operator*() const { return *mObj; } + T* operator->() const { return mObj; } + T* get() const { return mObj; } +private: + T* mObj; +}; + } #endif // MINIKIN_REF_COUNTED_H \ No newline at end of file diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index 9544dc2b11d..3be942d7b9e 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -91,8 +91,8 @@ void purgeHbFontCacheLocked() { getFontCacheLocked()->clear(); } -void purgeHbFont(const MinikinFont* minikinFont) { - AutoMutex _l(gMinikinLock); +void purgeHbFontLocked(const MinikinFont* minikinFont) { + assertMinikinLocked(); const int32_t fontId = minikinFont->GetUniqueId(); getFontCacheLocked()->remove(fontId); } diff --git a/engine/src/flutter/libs/minikin/HbFontCache.h b/engine/src/flutter/libs/minikin/HbFontCache.h index 92e465ac40d..449b354c2db 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.h +++ b/engine/src/flutter/libs/minikin/HbFontCache.h @@ -23,7 +23,7 @@ namespace android { class MinikinFont; void purgeHbFontCacheLocked(); -void purgeHbFont(const MinikinFont* minikinFont); +void purgeHbFontLocked(const MinikinFont* minikinFont); hb_font_t* getHbFontLocked(MinikinFont* minikinFont); } // namespace android diff --git a/engine/src/flutter/libs/minikin/MinikinFont.cpp b/engine/src/flutter/libs/minikin/MinikinFont.cpp index d56ec9c7013..ef42e9b12f6 100644 --- a/engine/src/flutter/libs/minikin/MinikinFont.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFont.cpp @@ -20,7 +20,7 @@ namespace android { MinikinFont::~MinikinFont() { - purgeHbFont(this); + purgeHbFontLocked(this); } } // namespace android diff --git a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp index b9ea5d7dff8..4a1b1150828 100644 --- a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp @@ -30,8 +30,8 @@ namespace android { int32_t MinikinFontFreeType::sIdCounter = 0; MinikinFontFreeType::MinikinFontFreeType(FT_Face typeface) : + MinikinFont(sIdCounter++), mTypeface(typeface) { - mUniqueId = sIdCounter++; } MinikinFontFreeType::~MinikinFontFreeType() { @@ -72,10 +72,6 @@ const void* MinikinFontFreeType::GetTable(uint32_t tag, size_t* size, MinikinDes return buf; } -int32_t MinikinFontFreeType::GetUniqueId() const { - return mUniqueId; -} - bool MinikinFontFreeType::Render(uint32_t glyph_id, const MinikinPaint& /* paint */, GlyphBitmap *result) { FT_Error error; diff --git a/engine/src/flutter/sample/MinikinSkia.cpp b/engine/src/flutter/sample/MinikinSkia.cpp index c4971bb6e18..e2ecde02d18 100644 --- a/engine/src/flutter/sample/MinikinSkia.cpp +++ b/engine/src/flutter/sample/MinikinSkia.cpp @@ -7,6 +7,7 @@ namespace android { MinikinFontSkia::MinikinFontSkia(SkTypeface *typeface) : + MinikinFont(typeface->uniqueID()), mTypeface(typeface) { } @@ -67,8 +68,4 @@ SkTypeface *MinikinFontSkia::GetSkTypeface() { return mTypeface; } -int32_t MinikinFontSkia::GetUniqueId() const { - return mTypeface->uniqueID(); -} - } diff --git a/engine/src/flutter/sample/MinikinSkia.h b/engine/src/flutter/sample/MinikinSkia.h index e1d7bf6da3b..6eb9065cc2c 100644 --- a/engine/src/flutter/sample/MinikinSkia.h +++ b/engine/src/flutter/sample/MinikinSkia.h @@ -14,8 +14,6 @@ public: const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); - int32_t GetUniqueId() const; - SkTypeface *GetSkTypeface(); private: diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index 907f3950bf8..194063f5f81 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -350,9 +350,9 @@ void expectVSGlyphs(FontFamily* family, uint32_t codepoint, const std::set minikinFont(new MinikinFontForTest(kVsTestFont)); + MinikinAutoUnref family(new FontFamily); + family->addFont(minikinFont.get()); AutoMutex _l(gMinikinLock); @@ -365,24 +365,24 @@ TEST_F(FontFamilyTest, hasVariationSelectorTest) { const uint32_t kVS20 = 0xE0103; const uint32_t kSupportedChar1 = 0x82A6; - EXPECT_TRUE(family.getCoverage()->get(kSupportedChar1)); - expectVSGlyphs(&family, kSupportedChar1, std::set({kVS1, kVS17, kVS18, kVS19})); + EXPECT_TRUE(family->getCoverage()->get(kSupportedChar1)); + expectVSGlyphs(family.get(), kSupportedChar1, std::set({kVS1, kVS17, kVS18, kVS19})); const uint32_t kSupportedChar2 = 0x845B; - EXPECT_TRUE(family.getCoverage()->get(kSupportedChar2)); - expectVSGlyphs(&family, kSupportedChar2, std::set({kVS2, kVS18, kVS19, kVS20})); + EXPECT_TRUE(family->getCoverage()->get(kSupportedChar2)); + expectVSGlyphs(family.get(), kSupportedChar2, std::set({kVS2, kVS18, kVS19, kVS20})); const uint32_t kNoVsSupportedChar = 0x537F; - EXPECT_TRUE(family.getCoverage()->get(kNoVsSupportedChar)); - expectVSGlyphs(&family, kNoVsSupportedChar, std::set()); + EXPECT_TRUE(family->getCoverage()->get(kNoVsSupportedChar)); + expectVSGlyphs(family.get(), kNoVsSupportedChar, std::set()); const uint32_t kVsOnlySupportedChar = 0x717D; - EXPECT_FALSE(family.getCoverage()->get(kVsOnlySupportedChar)); - expectVSGlyphs(&family, kVsOnlySupportedChar, std::set({kVS3, kVS19, kVS20})); + EXPECT_FALSE(family->getCoverage()->get(kVsOnlySupportedChar)); + expectVSGlyphs(family.get(), kVsOnlySupportedChar, std::set({kVS3, kVS19, kVS20})); const uint32_t kNotSupportedChar = 0x845C; - EXPECT_FALSE(family.getCoverage()->get(kNotSupportedChar)); - expectVSGlyphs(&family, kNotSupportedChar, std::set()); + EXPECT_FALSE(family->getCoverage()->get(kNotSupportedChar)); + expectVSGlyphs(family.get(), kNotSupportedChar, std::set()); } TEST_F(FontFamilyTest, hasVSTableTest) { @@ -403,12 +403,13 @@ TEST_F(FontFamilyTest, hasVSTableTest) { "Font " + testCase.fontPath + " should have a variation sequence table." : "Font " + testCase.fontPath + " shouldn't have a variation sequence table."); - MinikinFontForTest minikinFont(testCase.fontPath); - FontFamily family; - family.addFont(&minikinFont); - family.getCoverage(); + MinikinAutoUnref minikinFont(new MinikinFontForTest(testCase.fontPath)); + MinikinAutoUnref family(new FontFamily); + family->addFont(minikinFont.get()); + AutoMutex _l(gMinikinLock); + family->getCoverage(); - EXPECT_EQ(testCase.hasVSTable, family.hasVSTable()); + EXPECT_EQ(testCase.hasVSTable, family->hasVSTable()); } } diff --git a/engine/src/flutter/tests/MinikinFontForTest.cpp b/engine/src/flutter/tests/MinikinFontForTest.cpp index 96f3326d2a0..66dd4ea4734 100644 --- a/engine/src/flutter/tests/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/MinikinFontForTest.cpp @@ -22,8 +22,14 @@ #include -MinikinFontForTest::MinikinFontForTest(const std::string& font_path) : mFontPath(font_path) { - mTypeface = SkTypeface::CreateFromFile(font_path.c_str()); +MinikinFontForTest::MinikinFontForTest(const std::string& font_path) : + MinikinFontForTest(font_path, SkTypeface::CreateFromFile(font_path.c_str())) { +} + +MinikinFontForTest::MinikinFontForTest(const std::string& font_path, SkTypeface* typeface) : + MinikinFont(typeface->uniqueID()), + mTypeface(typeface), + mFontPath(font_path) { } MinikinFontForTest::~MinikinFontForTest() { @@ -55,7 +61,3 @@ const void* MinikinFontForTest::GetTable(uint32_t tag, size_t* size, *destroy = free; return buf; } - -int32_t MinikinFontForTest::GetUniqueId() const { - return mTypeface->uniqueID(); -} diff --git a/engine/src/flutter/tests/MinikinFontForTest.h b/engine/src/flutter/tests/MinikinFontForTest.h index 4686f7ab20a..e527d21e34d 100644 --- a/engine/src/flutter/tests/MinikinFontForTest.h +++ b/engine/src/flutter/tests/MinikinFontForTest.h @@ -24,6 +24,7 @@ class SkTypeface; class MinikinFontForTest : public android::MinikinFont { public: explicit MinikinFontForTest(const std::string& font_path); + MinikinFontForTest(const std::string& font_path, SkTypeface* typeface); ~MinikinFontForTest(); // MinikinFont overrides. @@ -31,7 +32,6 @@ public: void GetBounds(android::MinikinRect* bounds, uint32_t glyph_id, const android::MinikinPaint& paint) const; const void* GetTable(uint32_t tag, size_t* size, android::MinikinDestroyFunc* destroy); - int32_t GetUniqueId() const; const std::string& fontPath() const { return mFontPath; } private: diff --git a/engine/src/flutter/tests/how_to_run.txt b/engine/src/flutter/tests/how_to_run.txt index a135c30e130..bee367bd179 100644 --- a/engine/src/flutter/tests/how_to_run.txt +++ b/engine/src/flutter/tests/how_to_run.txt @@ -1,5 +1,5 @@ mmm -j8 frameworks/minikin/tests && adb push $OUT/data/nativetest/minikin_tests/minikin_tests \ /data/nativetest/minikin_tests/minikin_tests && -adb push frameworks/minikin/tests/data /data/nativetest/minikin_tests/data && +adb push frameworks/minikin/tests/data /data/nativetest/minikin_tests/ && adb shell /data/nativetest/minikin_tests/minikin_tests From 0ae37ab603d853cef13857c17ee48eaa8ec76a99 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 12 Apr 2016 15:27:17 -0700 Subject: [PATCH 178/364] Clear mLineWidths in LineBreaker::finish() There was the possibility of stale indents from previous invocations persisting in the mLineWidths across multiple invocations. This patch clears them. Bug: 28090810 Change-Id: I3621dfbe983512046289373711709aeade52eab4 --- engine/src/flutter/include/minikin/LineBreaker.h | 3 +++ engine/src/flutter/libs/minikin/LineBreaker.cpp | 1 + 2 files changed, 4 insertions(+) diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index e28f11da447..1d814040455 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -69,6 +69,9 @@ class LineWidths { } return width; } + void clear() { + mIndents.clear(); + } private: float mFirstWidth; int mFirstWidthLineCount; diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 9c4ff6f3bea..2a71f044d23 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -419,6 +419,7 @@ size_t LineBreaker::computeBreaks() { void LineBreaker::finish() { mWordBreaker.finish(); mWidth = 0; + mLineWidths.clear(); mCandidates.clear(); mBreaks.clear(); mWidths.clear(); From 0f5d87990b2cc56994f1a3f1de3d0341213f62ce Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Mon, 7 Mar 2016 18:43:15 -0800 Subject: [PATCH 179/364] Returns hasVariationSelector true for VS15/VS16 Minikin has a special font fallback for VS15/VS16, so hasVariationSelector for emojis with VS15/VS16 should always return true. Bug: 27531970 Change-Id: Ieebd58f48b135b6ec50d999df68dcc09b1284606 --- .../src/flutter/include/minikin/FontFamily.h | 5 +- .../flutter/libs/minikin/FontCollection.cpp | 64 ++++++++++++++++--- .../src/flutter/libs/minikin/FontFamily.cpp | 19 +++++- .../tests/FontCollectionItemizeTest.cpp | 27 ++++---- .../src/flutter/tests/FontCollectionTest.cpp | 32 ++++++++++ engine/src/flutter/tests/FontFamilyTest.cpp | 4 +- engine/src/flutter/tests/FontTestUtils.cpp | 8 +-- engine/src/flutter/tests/FontTestUtils.h | 5 +- 8 files changed, 130 insertions(+), 34 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 149dc7b798d..81033d23fda 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -100,7 +100,7 @@ struct FakedFont { class FontFamily : public MinikinRefCounted { public: - FontFamily() {} + FontFamily(); FontFamily(int variant); @@ -126,6 +126,7 @@ public: size_t getNumFonts() const; MinikinFont* getFont(size_t index) const; FontStyle getStyle(size_t index) const; + bool isColorEmojiFamily() const; // Get Unicode coverage. Lifetime of returned bitset is same as receiver. May return nullptr on // error. @@ -133,7 +134,7 @@ public: // Returns true if the font has a glyph for the code point and variation selector pair. // Caller should acquire a lock before calling the method. - bool hasVariationSelector(uint32_t codepoint, uint32_t variationSelector); + bool hasGlyph(uint32_t codepoint, uint32_t variationSelector); // Returns true if this font family has a variaion sequence table (cmap format 14 subtable). bool hasVSTable() const; diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 75cbd768937..b1b0aaf95f7 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -37,6 +37,42 @@ static inline T max(T a, T b) { return a>b ? a : b; } +const uint32_t EMOJI_STYLE_VS = 0xFE0F; +const uint32_t TEXT_STYLE_VS = 0xFE0E; + +// See http://www.unicode.org/Public/9.0.0/ucd/StandardizedVariants-9.0.0d1.txt +// Must be sorted. +const uint32_t EMOJI_STYLE_VS_BASES[] = { + 0x0023, 0x002A, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, + 0x00A9, 0x00AE, 0x203C, 0x2049, 0x2122, 0x2139, 0x2194, 0x2195, 0x2196, 0x2197, 0x2198, 0x2199, + 0x21A9, 0x21AA, 0x231A, 0x231B, 0x2328, 0x23CF, 0x23ED, 0x23EE, 0x23EF, 0x23F1, 0x23F2, 0x23F8, + 0x23F9, 0x23FA, 0x24C2, 0x25AA, 0x25AB, 0x25B6, 0x25C0, 0x25FB, 0x25FC, 0x25FD, 0x25FE, 0x2600, + 0x2601, 0x2602, 0x2603, 0x2604, 0x260E, 0x2611, 0x2614, 0x2615, 0x2618, 0x261D, 0x2620, 0x2622, + 0x2623, 0x2626, 0x262A, 0x262E, 0x262F, 0x2638, 0x2639, 0x263A, 0x2648, 0x2649, 0x264A, 0x264B, + 0x264C, 0x264D, 0x264E, 0x264F, 0x2650, 0x2651, 0x2652, 0x2653, 0x2660, 0x2663, 0x2665, 0x2666, + 0x2668, 0x267B, 0x267F, 0x2692, 0x2693, 0x2694, 0x2696, 0x2697, 0x2699, 0x269B, 0x269C, 0x26A0, + 0x26A1, 0x26AA, 0x26AB, 0x26B0, 0x26B1, 0x26BD, 0x26BE, 0x26C4, 0x26C5, 0x26C8, 0x26CF, 0x26D1, + 0x26D3, 0x26D4, 0x26E9, 0x26EA, 0x26F0, 0x26F1, 0x26F2, 0x26F3, 0x26F4, 0x26F5, 0x26F7, 0x26F8, + 0x26F9, 0x26FA, 0x26FD, 0x2702, 0x2708, 0x2709, 0x270C, 0x270D, 0x270F, 0x2712, 0x2714, 0x2716, + 0x271D, 0x2721, 0x2733, 0x2734, 0x2744, 0x2747, 0x2757, 0x2763, 0x2764, 0x27A1, 0x2934, 0x2935, + 0x2B05, 0x2B06, 0x2B07, 0x2B1B, 0x2B1C, 0x2B50, 0x2B55, 0x3030, 0x303D, 0x3297, 0x3299, + 0x1F004, 0x1F170, 0x1F171, 0x1F17E, 0x1F17F, 0x1F202, 0x1F21A, 0x1F22F, 0x1F237, 0x1F321, + 0x1F324, 0x1F325, 0x1F326, 0x1F327, 0x1F328, 0x1F329, 0x1F32A, 0x1F32B, 0x1F32C, 0x1F336, + 0x1F37D, 0x1F396, 0x1F397, 0x1F399, 0x1F39A, 0x1F39B, 0x1F39E, 0x1F39F, 0x1F3CB, 0x1F3CC, + 0x1F3CD, 0x1F3CE, 0x1F3D4, 0x1F3D5, 0x1F3D6, 0x1F3D7, 0x1F3D8, 0x1F3D9, 0x1F3DA, 0x1F3DB, + 0x1F3DC, 0x1F3DD, 0x1F3DE, 0x1F3DF, 0x1F3F3, 0x1F3F5, 0x1F3F7, 0x1F43F, 0x1F441, 0x1F4FD, + 0x1F549, 0x1F54A, 0x1F56F, 0x1F570, 0x1F573, 0x1F574, 0x1F575, 0x1F576, 0x1F577, 0x1F578, + 0x1F579, 0x1F587, 0x1F58A, 0x1F58B, 0x1F58C, 0x1F58D, 0x1F590, 0x1F5A5, 0x1F5A8, 0x1F5B1, + 0x1F5B2, 0x1F5BC, 0x1F5C2, 0x1F5C3, 0x1F5C4, 0x1F5D1, 0x1F5D2, 0x1F5D3, 0x1F5DC, 0x1F5DD, + 0x1F5DE, 0x1F5E1, 0x1F5E3, 0x1F5E8, 0x1F5EF, 0x1F5F3, 0x1F5FA, 0x1F6CB, 0x1F6CD, 0x1F6CE, + 0x1F6CF, 0x1F6E0, 0x1F6E1, 0x1F6E2, 0x1F6E3, 0x1F6E4, 0x1F6E5, 0x1F6E9, 0x1F6F0, 0x1F6F3, +}; + +static bool isEmojiStyleVSBase(uint32_t cp) { + const size_t length = sizeof(EMOJI_STYLE_VS_BASES) / sizeof(EMOJI_STYLE_VS_BASES[0]); + return std::binary_search(EMOJI_STYLE_VS_BASES, EMOJI_STYLE_VS_BASES + length, cp); +} + uint32_t FontCollection::sNextId = 0; FontCollection::FontCollection(const vector& typefaces) : @@ -156,7 +192,7 @@ uint32_t FontCollection::calcFamilyScore(uint32_t ch, uint32_t vs, int variant, // - Returns 1 if the variation selector is not specified or if the font family only supports the // variation sequence's base character. uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, FontFamily* fontFamily) const { - const bool hasVSGlyph = (vs != 0) && fontFamily->hasVariationSelector(ch, vs); + const bool hasVSGlyph = (vs != 0) && fontFamily->hasGlyph(ch, vs); if (!hasVSGlyph && !fontFamily->getCoverage()->get(ch)) { // The font doesn't support either variation sequence or even the base character. return kUnsupportedFontScore; @@ -176,7 +212,7 @@ uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, FontFamily* return 3; } - if (vs == 0xFE0F || vs == 0xFE0E) { + if (vs == EMOJI_STYLE_VS || vs == TEXT_STYLE_VS) { const FontLanguages& langs = FontLanguageListCache::getById(fontFamily->langId()); bool hasEmojiFlag = false; for (size_t i = 0; i < langs.size(); ++i) { @@ -186,9 +222,9 @@ uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, FontFamily* } } - if (vs == 0xFE0F) { + if (vs == EMOJI_STYLE_VS) { return hasEmojiFlag ? 2 : 1; - } else { // vs == 0xFE0E + } else { // vs == TEXT_STYLE_VS return hasEmojiFlag ? 1 : 2; } } @@ -325,17 +361,27 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, if (baseCodepoint >= mMaxChar) { return false; } - if (variationSelector == 0) { - return false; - } + + AutoMutex _l(gMinikinLock); // Currently mRanges can not be used here since it isn't aware of the variation sequence. for (size_t i = 0; i < mVSFamilyVec.size(); i++) { - AutoMutex _l(gMinikinLock); - if (mVSFamilyVec[i]->hasVariationSelector(baseCodepoint, variationSelector)) { + if (mVSFamilyVec[i]->hasGlyph(baseCodepoint, variationSelector)) { return true; } } + + // Even if there is no cmap format 14 subtable entry for the given sequence, should return true + // for emoji + U+FE0E case since we have special fallback rule for the sequence. + if (isEmojiStyleVSBase(baseCodepoint) && variationSelector == TEXT_STYLE_VS) { + for (size_t i = 0; i < mFamilies.size(); ++i) { + if (!mFamilies[i]->isColorEmojiFamily() && variationSelector == TEXT_STYLE_VS && + mFamilies[i]->hasGlyph(baseCodepoint, 0)) { + return true; + } + } + } + return false; } diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 0f71f511ca0..e2d86f0bbb0 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -65,6 +65,9 @@ uint32_t FontStyle::pack(int variant, int weight, bool italic) { return (weight & kWeightMask) | (italic ? kItalicMask : 0) | (variant << kVariantShift); } +FontFamily::FontFamily() : FontFamily(0 /* variant */) { +} + FontFamily::FontFamily(int variant) : FontFamily(FontLanguageListCache::kEmptyListId, variant) { } @@ -156,6 +159,16 @@ FontStyle FontFamily::getStyle(size_t index) const { return mFonts[index].style; } +bool FontFamily::isColorEmojiFamily() const { + const FontLanguages& languageList = FontLanguageListCache::getById(mLangId); + for (size_t i = 0; i < languageList.size(); ++i) { + if (languageList[i].hasEmojiFlag()) { + return true; + } + } + return false; +} + const SparseBitSet* FontFamily::getCoverage() { if (!mCoverageValid) { const FontStyle defaultStyle; @@ -179,9 +192,11 @@ const SparseBitSet* FontFamily::getCoverage() { return &mCoverage; } -bool FontFamily::hasVariationSelector(uint32_t codepoint, uint32_t variationSelector) { +bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) { assertMinikinLocked(); - if (!mHasVSTable) { + if (variationSelector != 0 && !mHasVSTable) { + // Early exit if the variation selector is specified but the font doesn't have a cmap format + // 14 subtable. return false; } diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index 45587e9d891..8ad9472490a 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -32,6 +32,7 @@ using android::FontLanguage; using android::FontLanguages; using android::FontLanguageListCache; using android::FontStyle; +using android::MinikinAutoUnref; using android::MinikinFont; using android::gMinikinLock; @@ -80,7 +81,7 @@ const FontLanguages& registerAndGetFontLanguages(const std::string& lang_string) } TEST_F(FontCollectionItemizeTest, itemize_latin) { - std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; const FontStyle kRegularStyle = FontStyle(); @@ -150,7 +151,7 @@ TEST_F(FontCollectionItemizeTest, itemize_latin) { } TEST_F(FontCollectionItemizeTest, itemize_emoji) { - std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; itemize(collection.get(), "U+1F469 U+1F467", FontStyle(), &runs); @@ -211,7 +212,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emoji) { } TEST_F(FontCollectionItemizeTest, itemize_non_latin) { - std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; FontStyle kJAStyle = FontStyle(FontStyle::registerLanguageList("ja_JP")); @@ -300,7 +301,7 @@ TEST_F(FontCollectionItemizeTest, itemize_non_latin) { } TEST_F(FontCollectionItemizeTest, itemize_mixed) { - std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; FontStyle kUSStyle = FontStyle(FontStyle::registerLanguageList("en_US")); @@ -339,7 +340,7 @@ TEST_F(FontCollectionItemizeTest, itemize_mixed) { } TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { - std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; // A glyph for U+4FAE is provided by both Japanese font and Simplified @@ -478,7 +479,7 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { } TEST_F(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { - std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; // A glyph for U+845B is provided by both Japanese font and Simplified @@ -603,7 +604,7 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { } TEST_F(FontCollectionItemizeTest, itemize_no_crash) { - std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; // Broken Surrogate pairs. Check only not crashing. @@ -627,7 +628,7 @@ TEST_F(FontCollectionItemizeTest, itemize_no_crash) { } TEST_F(FontCollectionItemizeTest, itemize_fakery) { - std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; FontStyle kJABoldStyle = FontStyle(FontStyle::registerLanguageList("ja_JP"), 0, 7, false); @@ -1134,7 +1135,7 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageAndCoverage) { { "U+1F469", "zh-Hant,ja-Jpan,zh-Hans", kEmojiFont }, }; - std::unique_ptr collection = getFontCollection(kTestFontDir, kItemizeFontXml); + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); for (auto testCase : testCases) { SCOPED_TRACE("Test for \"" + testCase.testString + "\" with languages " + @@ -1150,7 +1151,7 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageAndCoverage) { } TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { - std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); std::vector runs; const FontStyle kDefaultFontStyle; @@ -1232,7 +1233,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { } TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { - std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); std::vector runs; const FontStyle kDefaultFontStyle; @@ -1314,7 +1315,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { } TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_with_skinTone) { - std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); std::vector runs; const FontStyle kDefaultFontStyle; @@ -1353,7 +1354,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_with_skinTone) { } TEST_F(FontCollectionItemizeTest, itemize_PrivateUseArea) { - std::unique_ptr collection = getFontCollection(kTestFontDir, kEmojiXmlFile); + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); std::vector runs; const FontStyle kDefaultFontStyle; diff --git a/engine/src/flutter/tests/FontCollectionTest.cpp b/engine/src/flutter/tests/FontCollectionTest.cpp index bbc53e3645f..5a03f60d26f 100644 --- a/engine/src/flutter/tests/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/FontCollectionTest.cpp @@ -17,6 +17,7 @@ #include #include +#include "FontTestUtils.h" #include "MinikinFontForTest.h" #include "MinikinInternal.h" @@ -75,4 +76,35 @@ TEST(FontCollectionTest, hasVariationSelectorTest) { expectVSGlyphs(fc, 0x717D, std::set({0xFE02, 0xE0102, 0xE0103})); } +const char kEmojiXmlFile[] = kTestFontDir "emoji.xml"; + +TEST(FontCollectionTest, hasVariationSelectorTest_emoji) { + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + + // Both text/color font have cmap format 14 subtable entry for VS15/VS16 respectively. + EXPECT_TRUE(collection->hasVariationSelector(0x2623, 0xFE0E)); + EXPECT_TRUE(collection->hasVariationSelector(0x2623, 0xFE0F)); + + // The text font has cmap format 14 subtable entry for VS15 but the color font doesn't have for + // VS16 + EXPECT_TRUE(collection->hasVariationSelector(0x2626, 0xFE0E)); + EXPECT_FALSE(collection->hasVariationSelector(0x2626, 0xFE0F)); + + // The color font has cmap format 14 subtable entry for VS16 but the text font doesn't have for + // VS15. + EXPECT_TRUE(collection->hasVariationSelector(0x262A, 0xFE0E)); + EXPECT_TRUE(collection->hasVariationSelector(0x262A, 0xFE0F)); + + // Neither text/color font have cmap format 14 subtable entry for VS15/VS16. + EXPECT_TRUE(collection->hasVariationSelector(0x262E, 0xFE0E)); + EXPECT_FALSE(collection->hasVariationSelector(0x262E, 0xFE0F)); + + // Text font doesn't have U+262F U+FE0E or even its base code point U+262F. + EXPECT_FALSE(collection->hasVariationSelector(0x262F, 0xFE0E)); + + // VS15/VS16 is only for emoji, should return false for not an emoji code point. + EXPECT_FALSE(collection->hasVariationSelector(0x2229, 0xFE0E)); + EXPECT_FALSE(collection->hasVariationSelector(0x2229, 0xFE0F)); +} + } // namespace android diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index 194063f5f81..1b2457695c4 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -339,10 +339,10 @@ void expectVSGlyphs(FontFamily* family, uint32_t codepoint, const std::sethasVariationSelector(codepoint, i)) + EXPECT_FALSE(family->hasGlyph(codepoint, i)) << "Glyph for U+" << std::hex << codepoint << " U+" << i; } else { - EXPECT_TRUE(family->hasVariationSelector(codepoint, i)) + EXPECT_TRUE(family->hasGlyph(codepoint, i)) << "Glyph for U+" << std::hex << codepoint << " U+" << i; } diff --git a/engine/src/flutter/tests/FontTestUtils.cpp b/engine/src/flutter/tests/FontTestUtils.cpp index 98dab5121b0..fdc3ed6ee91 100644 --- a/engine/src/flutter/tests/FontTestUtils.cpp +++ b/engine/src/flutter/tests/FontTestUtils.cpp @@ -24,8 +24,7 @@ #include "FontLanguage.h" #include "MinikinFontForTest.h" -std::unique_ptr getFontCollection( - const char* fontDir, const char* fontXml) { +android::FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { xmlDoc* doc = xmlReadFile(fontXml, NULL, 0); xmlNode* familySet = xmlDocGetRootElement(doc); @@ -73,9 +72,10 @@ std::unique_ptr getFontCollection( } xmlFreeDoc(doc); - std::unique_ptr r(new android::FontCollection(families)); + android::FontCollection* collection = new android::FontCollection(families); + collection->Ref(); for (size_t i = 0; i < families.size(); ++i) { families[i]->Unref(); } - return r; + return collection; } diff --git a/engine/src/flutter/tests/FontTestUtils.h b/engine/src/flutter/tests/FontTestUtils.h index 7c62c464074..5258a766ae5 100644 --- a/engine/src/flutter/tests/FontTestUtils.h +++ b/engine/src/flutter/tests/FontTestUtils.h @@ -24,8 +24,9 @@ * * This function reads /system/etc/fonts.xml and make font families and * collections of them. MinikinFontForTest is used for FontFamily creation. + * + * Caller must unref the returned pointer. */ -std::unique_ptr getFontCollection( - const char* fontDir, const char* fontXml); +android::FontCollection* getFontCollection(const char* fontDir, const char* fontXml); #endif // MINIKIN_FONT_TEST_UTILS_H From 47932fa53b75744a30034467cfae6333468f54bb Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 19 Apr 2016 17:14:27 +0900 Subject: [PATCH 180/364] Do not break before and after ZWJ. The emoji list is generated from external/unicode/emoji-data.txt Bug: 28248662 Change-Id: Ie49b3782505665d62c24371ca23d317ae5e9c5f7 --- engine/src/flutter/libs/minikin/Android.mk | 16 ++- .../flutter/libs/minikin/GraphemeBreak.cpp | 17 +-- .../flutter/libs/minikin/MinikinInternal.cpp | 6 + .../flutter/libs/minikin/MinikinInternal.h | 3 + .../src/flutter/libs/minikin/WordBreaker.cpp | 15 +-- .../libs/minikin/unicode_emoji_h_gen.py | 105 ++++++++++++++++++ engine/src/flutter/tests/Android.mk | 1 + .../src/flutter/tests/GraphemeBreakTests.cpp | 4 + .../src/flutter/tests/MinikinInternalTest.cpp | 34 ++++++ engine/src/flutter/tests/WordBreakerTests.cpp | 7 +- 10 files changed, 179 insertions(+), 29 deletions(-) create mode 100644 engine/src/flutter/libs/minikin/unicode_emoji_h_gen.py create mode 100644 engine/src/flutter/tests/MinikinInternalTest.cpp diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 2b5ff0667f6..9d8257944f1 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -15,7 +15,20 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) +# Generate unicode emoji data from UCD. +UNICODE_EMOJI_H_GEN_PY := $(LOCAL_PATH)/unicode_emoji_h_gen.py +UNICODE_EMOJI_DATA := $(TOP)/external/unicode/emoji-data.txt +UNICODE_EMOJI_H := $(intermediates)/generated/UnicodeData.h +$(UNICODE_EMOJI_H): $(UNICODE_EMOJI_H_GEN_PY) $(UNICODE_EMOJI_DATA) +$(LOCAL_PATH)/MinikinInternal.cpp: $(UNICODE_EMOJI_H) +$(UNICODE_EMOJI_H): PRIVATE_CUSTOM_TOOL := python $(UNICODE_EMOJI_H_GEN_PY) \ + -i $(UNICODE_EMOJI_DATA) \ + -o $(UNICODE_EMOJI_H) +$(UNICODE_EMOJI_H): + $(transform-generated-source) + +include $(CLEAR_VARS) minikin_src_files := \ AnalyzeStyle.cpp \ CmapCoverage.cpp \ @@ -40,7 +53,8 @@ minikin_src_files := \ minikin_c_includes := \ external/harfbuzz_ng/src \ external/freetype/include \ - frameworks/minikin/include + frameworks/minikin/include \ + $(intermediates) minikin_shared_libraries := \ libharfbuzz_ng \ diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index 1f361ba1a75..45dd0fff697 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -66,19 +66,6 @@ bool isPureKiller(uint32_t c) { || c == 0xA953 || c == 0xABED || c == 0x11134 || c == 0x112EA || c == 0x1172B); } -// Returns true if the character appears before or after zwj in a zwj emoji sequence. See -// http://www.unicode.org/emoji/charts/emoji-zwj-sequences.html -bool isZwjEmoji(uint32_t c) { - return (c == 0x2764 // HEAVY BLACK HEART - || c == 0x1F468 // MAN - || c == 0x1F469 // WOMAN - || c == 0x1F48B // KISS MARK - || c == 0x1F466 // BOY - || c == 0x1F467 // GIRL - || c == 0x1F441 // EYE - || c == 0x1F5E8); // LEFT SPEECH BUBBLE -} - bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t count, size_t offset) { // This implementation closely follows Unicode Standard Annex #29 on @@ -163,7 +150,7 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co return false; } // Tailoring: make emoji sequences with ZWJ a single grapheme cluster - if (c1 == 0x200D && isZwjEmoji(c2) && offset_back > start) { + if (c1 == 0x200D && isEmoji(c2) && offset_back > start) { // look at character before ZWJ to see that both can participate in an emoji zwj sequence uint32_t c0 = 0; U16_PREV(buf, start, offset_back, c0); @@ -171,7 +158,7 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co // skip over emoji variation selector U16_PREV(buf, start, offset_back, c0); } - if (isZwjEmoji(c0)) { + if (isEmoji(c0)) { return false; } } diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index e00f63951bf..7fcc7b7f8b6 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -18,6 +18,7 @@ #include "MinikinInternal.h" #include "HbFontCache.h" +#include "generated/UnicodeData.h" #include @@ -31,6 +32,11 @@ void assertMinikinLocked() { #endif } +bool isEmoji(uint32_t c) { + const size_t length = sizeof(generated::EMOJI_LIST) / sizeof(generated::EMOJI_LIST[0]); + return std::binary_search(generated::EMOJI_LIST, generated::EMOJI_LIST + length, c); +} + // Based on Modifiers from http://www.unicode.org/L2/L2016/16011-data-file.txt bool isEmojiModifier(uint32_t c) { return (0x1F3FB <= c && c <= 0x1F3FF); diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.h b/engine/src/flutter/libs/minikin/MinikinInternal.h index 709fb9f691a..88cc9475c8c 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.h +++ b/engine/src/flutter/libs/minikin/MinikinInternal.h @@ -36,6 +36,9 @@ extern Mutex gMinikinLock; // Aborts if gMinikinLock is not acquired. Do nothing on the release build. void assertMinikinLocked(); +// Returns true if c is emoji. +bool isEmoji(uint32_t c); + // Returns true if c is emoji modifier base. bool isEmojiBase(uint32_t c); diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index d420a6a0a87..34e7a932c95 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -90,18 +90,9 @@ static bool isBreakValid(const uint16_t* buf, size_t bufEnd, size_t i) { } } - // Known emoji ZWJ sequences - if (codePoint == CHAR_ZWJ) { - // Possible emoji ZWJ sequence - if (next_codepoint == 0x2764 || // HEAVY BLACK HEART - next_codepoint == 0x1F466 || // BOY - next_codepoint == 0x1F467 || // GIRL - next_codepoint == 0x1F468 || // MAN - next_codepoint == 0x1F469 || // WOMAN - next_codepoint == 0x1F48B || // KISS MARK - next_codepoint == 0x1F5E8) { // LEFT SPEECH BUBBLE - return false; - } + // Emoji ZWJ sequences. + if (codePoint == CHAR_ZWJ && isEmoji(next_codepoint)) { + return false; } // Proposed Rule LB30b from http://www.unicode.org/L2/L2016/16011r3-break-prop-emoji.pdf diff --git a/engine/src/flutter/libs/minikin/unicode_emoji_h_gen.py b/engine/src/flutter/libs/minikin/unicode_emoji_h_gen.py new file mode 100644 index 00000000000..7233ef621e3 --- /dev/null +++ b/engine/src/flutter/libs/minikin/unicode_emoji_h_gen.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python +# +# Copyright (C) 2016 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. +# +"""Generate header file for unicode data.""" + +import optparse +import sys + + +UNICODE_EMOJI_TEMPLATE=""" +/* file generated by frameworks/minikin/lib/minikin/Android.mk */ +#ifndef MINIKIN_UNICODE_EMOJI_H +#define MINIKIN_UNICODE_EMOJI_H + +#include + +namespace android { +namespace generated { + +int32_t EMOJI_LIST[] = { +@@@EMOJI_DATA@@@ +}; + +} // namespace generated +} // namespace android + +#endif // MINIKIN_UNICODE_EMOJI_H +""" + + +def _create_opt_parser(): + parser = optparse.OptionParser() + parser.add_option('-i', '--input', type='str', action='store', + help='path to input emoji-data.txt') + parser.add_option('-o', '--output', type='str', action='store', + help='path to output UnicodeEmoji.h') + return parser + + +def _read_emoji_data(emoji_data_file_path): + result = [] + with open(emoji_data_file_path) as emoji_data_file: + for line in emoji_data_file: + if '#' in line: + line = line[:line.index('#')] # Drop comments. + if not line.strip(): + continue # Skip empty line. + + code_points, prop = line.split(';') + code_points = code_points.strip() + prop = prop.strip() + if prop != 'Emoji': + break # Only collect Emoji property code points + + if '..' in code_points: # code point range + cp_start, cp_end = code_points.split('..') + result.extend(xrange(int(cp_start, 16), int(cp_end, 16) + 1)) + else: + code_point = int(code_points, 16) + result.append(code_point) + return result + + +def _generate_header_contents(emoji_list): + INDENT = ' ' * 4 + JOINER = ', ' + + hex_list = ['0x%04X' % x for x in emoji_list] + lines = [] + tmp_line = '%s%s' % (INDENT, hex_list[0]) + for hex_str in hex_list[1:]: + if len(tmp_line) + len(JOINER) + len(hex_str) >= 100: + lines.append(tmp_line + ',') + tmp_line = '%s%s' % (INDENT, hex_str) + else: + tmp_line = '%s%s%s' % (tmp_line, JOINER, hex_str) + lines.append(tmp_line) + + template = UNICODE_EMOJI_TEMPLATE + template = template.replace('@@@EMOJI_DATA@@@', '\n'.join(lines)) + return template + + +if __name__ == '__main__': + opt_parser = _create_opt_parser() + opts, _ = opt_parser.parse_args() + + emoji_list = _read_emoji_data(opts.input) + header = _generate_header_contents(emoji_list) + with open(opts.output, 'w') as header_file: + header_file.write(header) + diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index e6586d7178c..b33631eb28e 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -77,6 +77,7 @@ LOCAL_SRC_FILES += \ FontTestUtils.cpp \ HbFontCacheTest.cpp \ MinikinFontForTest.cpp \ + MinikinInternalTest.cpp \ GraphemeBreakTests.cpp \ LayoutUtilsTest.cpp \ UnicodeUtils.cpp \ diff --git a/engine/src/flutter/tests/GraphemeBreakTests.cpp b/engine/src/flutter/tests/GraphemeBreakTests.cpp index 3bfa5ecd8be..cec53088774 100644 --- a/engine/src/flutter/tests/GraphemeBreakTests.cpp +++ b/engine/src/flutter/tests/GraphemeBreakTests.cpp @@ -148,6 +148,10 @@ TEST(GraphemeBreak, tailoring) { EXPECT_FALSE(IsBreak("U+1F469 U+200D U+1F469 U+200D U+1F467 U+200D | U+1F466")); EXPECT_FALSE(IsBreak("U+1F441 U+200D | U+1F5E8")); + // Do not break before and after zwj with all kind of emoji characters. + EXPECT_FALSE(IsBreak("U+1F431 | U+200D U+1F464")); + EXPECT_FALSE(IsBreak("U+1F431 U+200D | U+1F464")); + // ARABIC LETTER BEH + ZWJ + heart, not a zwj emoji sequence, so we preserve the break EXPECT_TRUE(IsBreak("U+0628 U+200D | U+2764")); } diff --git a/engine/src/flutter/tests/MinikinInternalTest.cpp b/engine/src/flutter/tests/MinikinInternalTest.cpp new file mode 100644 index 00000000000..9c1a1e54a4b --- /dev/null +++ b/engine/src/flutter/tests/MinikinInternalTest.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2016 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 + +#include "MinikinInternal.h" + +namespace android { + +TEST(MinikinInternalTest, isEmojiTest) { + EXPECT_TRUE(isEmoji(0x0023)); // NUMBER SIGN + EXPECT_TRUE(isEmoji(0x0035)); // DIGIT FIVE + EXPECT_TRUE(isEmoji(0x1F0CF)); // PLAYING CARD BLACK JOKER + EXPECT_TRUE(isEmoji(0x1F1E9)); // REGIONAL INDICATOR SYMBOL LETTER D + + EXPECT_FALSE(isEmoji(0x0000)); // + EXPECT_FALSE(isEmoji(0x0061)); // LATIN SMALL LETTER A + EXPECT_FALSE(isEmoji(0x29E3D)); // A han character. +} + +} // namespace android diff --git a/engine/src/flutter/tests/WordBreakerTests.cpp b/engine/src/flutter/tests/WordBreakerTests.cpp index 480c57da965..9fa9da3af71 100644 --- a/engine/src/flutter/tests/WordBreakerTests.cpp +++ b/engine/src/flutter/tests/WordBreakerTests.cpp @@ -93,6 +93,8 @@ TEST_F(WordBreakerTest, zwjEmojiSequences) { UTF16(0x1F469), 0x200D, 0x2764, 0x200D, UTF16(0x1F48B), 0x200D, UTF16(0x1F469), // eye + zwj + left speech bubble UTF16(0x1F441), 0x200D, UTF16(0x1F5E8), + // CAT FACE + zwj + BUST IN SILHOUETTE + UTF16(0x1F431), 0x200D, UTF16(0x1F464), }; WordBreaker breaker; breaker.setLocale(icu::Locale::getEnglish()); @@ -104,9 +106,12 @@ TEST_F(WordBreakerTest, zwjEmojiSequences) { EXPECT_EQ(17, breaker.next()); // after woman + zwj + heart + zwj + woman EXPECT_EQ(7, breaker.wordStart()); EXPECT_EQ(17, breaker.wordEnd()); - EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_EQ(22, breaker.next()); // after eye + zwj + left speech bubble EXPECT_EQ(17, breaker.wordStart()); EXPECT_EQ(22, breaker.wordEnd()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end + EXPECT_EQ(22, breaker.wordStart()); + EXPECT_EQ(27, breaker.wordEnd()); } TEST_F(WordBreakerTest, emojiWithModifier) { From 1cec37d918795065ba409fe67a379b7ec12ed057 Mon Sep 17 00:00:00 2001 From: Adam Buchbinder Date: Mon, 23 May 2016 13:16:13 -0700 Subject: [PATCH 181/364] Fix a leaked file in HyphTool.cpp. This addresses the following cppcheck reports: [frameworks/minikin/app/HyphTool.cpp:30]: (error) Resource leak: f [frameworks/minikin/app/HyphTool.cpp:32]: (error) Resource leak: f Change-Id: I5113e0a7268bd3a45bf1498fd023042d9dfe2b87 --- engine/src/flutter/app/HyphTool.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/engine/src/flutter/app/HyphTool.cpp b/engine/src/flutter/app/HyphTool.cpp index 730abadcbaf..b535d9da8f2 100644 --- a/engine/src/flutter/app/HyphTool.cpp +++ b/engine/src/flutter/app/HyphTool.cpp @@ -24,6 +24,7 @@ Hyphenator* loadHybFile(const char* fn) { } uint8_t* buf = new uint8_t[size]; size_t read_size = fread(buf, 1, size, f); + fclose(f); if (read_size < size) { fprintf(stderr, "error reading %s\n", fn); delete[] buf; From acaf5cc08defe3dfaa1e0caa945be494532cbaa0 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 25 May 2016 16:46:56 -0700 Subject: [PATCH 182/364] Do not break after Myanmar viramas This is to work around a bug in ICU's line breaker, which thinks there is a valid line break between a Myanmar kinzi and a consonant. See http://bugs.icu-project.org/trac/ticket/12561 for the ICU bug. Bug: 28964845 Change-Id: I076ac15077e5627cbccf6732900bcc60d8596dda --- engine/src/flutter/libs/minikin/WordBreaker.cpp | 10 +++++++++- engine/src/flutter/tests/WordBreakerTests.cpp | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index 34e7a932c95..38f03caf6a0 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -76,12 +76,20 @@ static bool isBreakValid(const uint16_t* buf, size_t bufEnd, size_t i) { if (codePoint == CHAR_SOFT_HYPHEN) { return false; } + // For Myanmar kinzi sequences, created by . This is to go + // around a bug in ICU line breaking: http://bugs.icu-project.org/trac/ticket/12561. To avoid + // too much looking around in the strings, we simply avoid breaking after any Myanmar virama, + // where no line break could be imagined, since the Myanmar virama is a pure stacker. + if (codePoint == 0x1039) { // MYANMAR SIGN VIRAMA + return false; + } + uint32_t next_codepoint; size_t next_offset = i; U16_NEXT(buf, next_offset, bufEnd, next_codepoint); // Proposed change to LB24 from http://www.unicode.org/L2/L2016/16043r-line-break-pr-po.txt - //(AL | HL) × (PR | PO) + // (AL | HL) × (PR | PO) int32_t lineBreak = u_getIntPropertyValue(codePoint, UCHAR_LINE_BREAK); if (lineBreak == U_LB_ALPHABETIC || lineBreak == U_LB_HEBREW_LETTER) { lineBreak = u_getIntPropertyValue(next_codepoint, UCHAR_LINE_BREAK); diff --git a/engine/src/flutter/tests/WordBreakerTests.cpp b/engine/src/flutter/tests/WordBreakerTests.cpp index 9fa9da3af71..8ed87cc5069 100644 --- a/engine/src/flutter/tests/WordBreakerTests.cpp +++ b/engine/src/flutter/tests/WordBreakerTests.cpp @@ -85,6 +85,19 @@ TEST_F(WordBreakerTest, postfixAndPrefix) { EXPECT_EQ((ssize_t)NELEM(buf), breaker.wordEnd()); } +TEST_F(WordBreakerTest, MyanmarKinzi) { + uint16_t buf[] = {0x1004, 0x103A, 0x1039, 0x1000, 0x102C}; // NGA, ASAT, VIRAMA, KA, UU + WordBreaker breaker; + icu::Locale burmese("my"); + breaker.setLocale(burmese); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end of string + EXPECT_EQ(0, breaker.wordStart()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.wordEnd()); +} + TEST_F(WordBreakerTest, zwjEmojiSequences) { uint16_t buf[] = { // man + zwj + heart + zwj + man From 96c4e3971652301b0b412f292e46d8c9a643b233 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 31 May 2016 15:25:21 +0900 Subject: [PATCH 183/364] Introduce initial minikin perftest Bug: 28992567 Change-Id: Id14cc86761d6c5b408262fe8684e2b293a420a4f --- engine/src/flutter/tests/perftests/Android.mk | 31 +++++++++++++++++ .../flutter/tests/perftests/FontLanguage.cpp | 34 +++++++++++++++++++ .../flutter/tests/perftests/how_to_run.txt | 4 +++ engine/src/flutter/tests/perftests/main.cpp | 18 ++++++++++ 4 files changed, 87 insertions(+) create mode 100644 engine/src/flutter/tests/perftests/Android.mk create mode 100644 engine/src/flutter/tests/perftests/FontLanguage.cpp create mode 100644 engine/src/flutter/tests/perftests/how_to_run.txt create mode 100644 engine/src/flutter/tests/perftests/main.cpp diff --git a/engine/src/flutter/tests/perftests/Android.mk b/engine/src/flutter/tests/perftests/Android.mk new file mode 100644 index 00000000000..3b49036cee1 --- /dev/null +++ b/engine/src/flutter/tests/perftests/Android.mk @@ -0,0 +1,31 @@ +# +# Copyright (C) 2016 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. +# + +LOCAL_PATH := $(call my-dir) + +perftest_src_files := \ + FontLanguage.cpp \ + main.cpp + +include $(CLEAR_VARS) +LOCAL_MODULE := minikin_perftests +LOCAL_CPPFLAGS := -Werror -Wall -Wextra +LOCAL_SRC_FILES := $(perftest_src_files) +LOCAL_STATIC_LIBRARIES := libminikin +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/../../libs/minikin \ + external/harfbuzz_ng/src +include $(BUILD_NATIVE_BENCHMARK) diff --git a/engine/src/flutter/tests/perftests/FontLanguage.cpp b/engine/src/flutter/tests/perftests/FontLanguage.cpp new file mode 100644 index 00000000000..ac7af6f909d --- /dev/null +++ b/engine/src/flutter/tests/perftests/FontLanguage.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2016 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 + +#include "FontLanguage.h" + +using android::FontLanguage; + +static void BM_FontLanguage_en_US(benchmark::State& state) { + while (state.KeepRunning()) { + FontLanguage language("en-US", 5); + } +} +BENCHMARK(BM_FontLanguage_en_US); + +static void BM_FontLanguage_en_Latn_US(benchmark::State& state) { + while (state.KeepRunning()) { + FontLanguage language("en-Latn-US", 10); + } +} +BENCHMARK(BM_FontLanguage_en_Latn_US); diff --git a/engine/src/flutter/tests/perftests/how_to_run.txt b/engine/src/flutter/tests/perftests/how_to_run.txt new file mode 100644 index 00000000000..3390522c2fd --- /dev/null +++ b/engine/src/flutter/tests/perftests/how_to_run.txt @@ -0,0 +1,4 @@ +mmm -j8 frameworks/minikin/tests/perftests && +adb push $OUT/data/benchmarktest/minikin_perftests/minikin_perftests \ + /data/benchmarktest/minikin_perftests/minikin_perftests && +adb shell /data/benchmarktest/minikin_perftests/minikin_perftests diff --git a/engine/src/flutter/tests/perftests/main.cpp b/engine/src/flutter/tests/perftests/main.cpp new file mode 100644 index 00000000000..e39c7f88387 --- /dev/null +++ b/engine/src/flutter/tests/perftests/main.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2016 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 + +BENCHMARK_MAIN(); From 2eef839c8e61512d0a031100db9da477fe2a54c6 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Fri, 3 Jun 2016 16:10:02 +0900 Subject: [PATCH 184/364] Reconstruct the directory structure of minikin tests. To add perftests and reuse some utility classes, reconstruct test directory structure. - Move unit tests from minikin/tests to minikin/tests/unittests - Extract utilitiy classes to minikin/tests/utils which will be used by perftests eventually. Change-Id: I5026b177934e72ae67d362ee888302037da2f808 --- engine/src/flutter/tests/{ => unittest}/Android.mk | 13 +++++++------ .../{ => unittest}/FontCollectionItemizeTest.cpp | 0 .../tests/{ => unittest}/FontCollectionTest.cpp | 0 .../flutter/tests/{ => unittest}/FontFamilyTest.cpp | 0 .../{ => unittest}/FontLanguageListCacheTest.cpp | 0 .../tests/{ => unittest}/GraphemeBreakTests.cpp | 0 .../tests/{ => unittest}/HbFontCacheTest.cpp | 0 .../src/flutter/tests/{ => unittest}/ICUTestBase.h | 0 .../tests/{ => unittest}/LayoutUtilsTest.cpp | 0 .../tests/{ => unittest}/MinikinInternalTest.cpp | 0 .../tests/{ => unittest}/WordBreakerTests.cpp | 0 .../src/flutter/tests/{ => unittest}/how_to_run.txt | 2 +- .../src/flutter/tests/{ => util}/FontTestUtils.cpp | 0 engine/src/flutter/tests/{ => util}/FontTestUtils.h | 0 .../flutter/tests/{ => util}/MinikinFontForTest.cpp | 0 .../flutter/tests/{ => util}/MinikinFontForTest.h | 0 .../src/flutter/tests/{ => util}/UnicodeUtils.cpp | 0 engine/src/flutter/tests/{ => util}/UnicodeUtils.h | 0 18 files changed, 8 insertions(+), 7 deletions(-) rename engine/src/flutter/tests/{ => unittest}/Android.mk (92%) rename engine/src/flutter/tests/{ => unittest}/FontCollectionItemizeTest.cpp (100%) rename engine/src/flutter/tests/{ => unittest}/FontCollectionTest.cpp (100%) rename engine/src/flutter/tests/{ => unittest}/FontFamilyTest.cpp (100%) rename engine/src/flutter/tests/{ => unittest}/FontLanguageListCacheTest.cpp (100%) rename engine/src/flutter/tests/{ => unittest}/GraphemeBreakTests.cpp (100%) rename engine/src/flutter/tests/{ => unittest}/HbFontCacheTest.cpp (100%) rename engine/src/flutter/tests/{ => unittest}/ICUTestBase.h (100%) rename engine/src/flutter/tests/{ => unittest}/LayoutUtilsTest.cpp (100%) rename engine/src/flutter/tests/{ => unittest}/MinikinInternalTest.cpp (100%) rename engine/src/flutter/tests/{ => unittest}/WordBreakerTests.cpp (100%) rename engine/src/flutter/tests/{ => unittest}/how_to_run.txt (83%) rename engine/src/flutter/tests/{ => util}/FontTestUtils.cpp (100%) rename engine/src/flutter/tests/{ => util}/FontTestUtils.h (100%) rename engine/src/flutter/tests/{ => util}/MinikinFontForTest.cpp (100%) rename engine/src/flutter/tests/{ => util}/MinikinFontForTest.h (100%) rename engine/src/flutter/tests/{ => util}/UnicodeUtils.cpp (100%) rename engine/src/flutter/tests/{ => util}/UnicodeUtils.h (100%) diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/unittest/Android.mk similarity index 92% rename from engine/src/flutter/tests/Android.mk rename to engine/src/flutter/tests/unittest/Android.mk index b33631eb28e..885127199dc 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -45,9 +45,9 @@ LOCAL_MODULE := minikin_tests LOCAL_MODULE_TAGS := tests GEN := $(addprefix $(minikin_tests_root_for_test_zip)/, $(font_src_files)) -$(GEN): PRIVATE_PATH := $(LOCAL_PATH) +$(GEN): PRIVATE_PATH := $(LOCAL_PATH)/../ $(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@ -$(GEN): $(minikin_tests_root_for_test_zip)/data/% : $(LOCAL_PATH)/data/% +$(GEN): $(minikin_tests_root_for_test_zip)/data/% : $(LOCAL_PATH)/../data/% $(transform-generated-source) LOCAL_GENERATED_SOURCES += $(GEN) @@ -70,21 +70,22 @@ LOCAL_STATIC_LIBRARIES += \ libxml2 LOCAL_SRC_FILES += \ + ../util/FontTestUtils.cpp \ + ../util/MinikinFontForTest.cpp \ + ../util/UnicodeUtils.cpp \ FontCollectionTest.cpp \ FontCollectionItemizeTest.cpp \ FontFamilyTest.cpp \ FontLanguageListCacheTest.cpp \ - FontTestUtils.cpp \ HbFontCacheTest.cpp \ - MinikinFontForTest.cpp \ MinikinInternalTest.cpp \ GraphemeBreakTests.cpp \ LayoutUtilsTest.cpp \ - UnicodeUtils.cpp \ WordBreakerTests.cpp LOCAL_C_INCLUDES := \ - $(LOCAL_PATH)/../libs/minikin/ \ + $(LOCAL_PATH)/../../libs/minikin/ \ + $(LOCAL_PATH)/../util \ external/harfbuzz_ng/src \ external/libxml2/include \ external/skia/src/core diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp similarity index 100% rename from engine/src/flutter/tests/FontCollectionItemizeTest.cpp rename to engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp diff --git a/engine/src/flutter/tests/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp similarity index 100% rename from engine/src/flutter/tests/FontCollectionTest.cpp rename to engine/src/flutter/tests/unittest/FontCollectionTest.cpp diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp similarity index 100% rename from engine/src/flutter/tests/FontFamilyTest.cpp rename to engine/src/flutter/tests/unittest/FontFamilyTest.cpp diff --git a/engine/src/flutter/tests/FontLanguageListCacheTest.cpp b/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp similarity index 100% rename from engine/src/flutter/tests/FontLanguageListCacheTest.cpp rename to engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp diff --git a/engine/src/flutter/tests/GraphemeBreakTests.cpp b/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp similarity index 100% rename from engine/src/flutter/tests/GraphemeBreakTests.cpp rename to engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp diff --git a/engine/src/flutter/tests/HbFontCacheTest.cpp b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp similarity index 100% rename from engine/src/flutter/tests/HbFontCacheTest.cpp rename to engine/src/flutter/tests/unittest/HbFontCacheTest.cpp diff --git a/engine/src/flutter/tests/ICUTestBase.h b/engine/src/flutter/tests/unittest/ICUTestBase.h similarity index 100% rename from engine/src/flutter/tests/ICUTestBase.h rename to engine/src/flutter/tests/unittest/ICUTestBase.h diff --git a/engine/src/flutter/tests/LayoutUtilsTest.cpp b/engine/src/flutter/tests/unittest/LayoutUtilsTest.cpp similarity index 100% rename from engine/src/flutter/tests/LayoutUtilsTest.cpp rename to engine/src/flutter/tests/unittest/LayoutUtilsTest.cpp diff --git a/engine/src/flutter/tests/MinikinInternalTest.cpp b/engine/src/flutter/tests/unittest/MinikinInternalTest.cpp similarity index 100% rename from engine/src/flutter/tests/MinikinInternalTest.cpp rename to engine/src/flutter/tests/unittest/MinikinInternalTest.cpp diff --git a/engine/src/flutter/tests/WordBreakerTests.cpp b/engine/src/flutter/tests/unittest/WordBreakerTests.cpp similarity index 100% rename from engine/src/flutter/tests/WordBreakerTests.cpp rename to engine/src/flutter/tests/unittest/WordBreakerTests.cpp diff --git a/engine/src/flutter/tests/how_to_run.txt b/engine/src/flutter/tests/unittest/how_to_run.txt similarity index 83% rename from engine/src/flutter/tests/how_to_run.txt rename to engine/src/flutter/tests/unittest/how_to_run.txt index bee367bd179..c90c6640bdf 100644 --- a/engine/src/flutter/tests/how_to_run.txt +++ b/engine/src/flutter/tests/unittest/how_to_run.txt @@ -1,4 +1,4 @@ -mmm -j8 frameworks/minikin/tests && +mmm -j8 frameworks/minikin/tests/unittests && adb push $OUT/data/nativetest/minikin_tests/minikin_tests \ /data/nativetest/minikin_tests/minikin_tests && adb push frameworks/minikin/tests/data /data/nativetest/minikin_tests/ && diff --git a/engine/src/flutter/tests/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp similarity index 100% rename from engine/src/flutter/tests/FontTestUtils.cpp rename to engine/src/flutter/tests/util/FontTestUtils.cpp diff --git a/engine/src/flutter/tests/FontTestUtils.h b/engine/src/flutter/tests/util/FontTestUtils.h similarity index 100% rename from engine/src/flutter/tests/FontTestUtils.h rename to engine/src/flutter/tests/util/FontTestUtils.h diff --git a/engine/src/flutter/tests/MinikinFontForTest.cpp b/engine/src/flutter/tests/util/MinikinFontForTest.cpp similarity index 100% rename from engine/src/flutter/tests/MinikinFontForTest.cpp rename to engine/src/flutter/tests/util/MinikinFontForTest.cpp diff --git a/engine/src/flutter/tests/MinikinFontForTest.h b/engine/src/flutter/tests/util/MinikinFontForTest.h similarity index 100% rename from engine/src/flutter/tests/MinikinFontForTest.h rename to engine/src/flutter/tests/util/MinikinFontForTest.h diff --git a/engine/src/flutter/tests/UnicodeUtils.cpp b/engine/src/flutter/tests/util/UnicodeUtils.cpp similarity index 100% rename from engine/src/flutter/tests/UnicodeUtils.cpp rename to engine/src/flutter/tests/util/UnicodeUtils.cpp diff --git a/engine/src/flutter/tests/UnicodeUtils.h b/engine/src/flutter/tests/util/UnicodeUtils.h similarity index 100% rename from engine/src/flutter/tests/UnicodeUtils.h rename to engine/src/flutter/tests/util/UnicodeUtils.h From 2fdcf62495d27f95b130013ae0b45f9c0dc03593 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 9 Jun 2016 19:40:58 +0900 Subject: [PATCH 185/364] Always use minikin namespace. Here is a new policy of the namespace of minikin. - All components should be in minikin namespace. - All tests are also in minikin namespace and no anonymous namespace. Bug: 29233740 Change-Id: I71a8a35049bb8d624f7a78797231e90fed1e2b8c --- engine/src/flutter/app/HyphTool.cpp | 2 +- .../flutter/include/minikin/AnalyzeStyle.h | 6 +- .../flutter/include/minikin/CmapCoverage.h | 4 +- .../flutter/include/minikin/FontCollection.h | 4 +- .../src/flutter/include/minikin/FontFamily.h | 8 +-- .../flutter/include/minikin/GraphemeBreak.h | 6 +- .../src/flutter/include/minikin/Hyphenator.h | 4 +- engine/src/flutter/include/minikin/Layout.h | 8 +-- .../src/flutter/include/minikin/LineBreaker.h | 4 +- .../src/flutter/include/minikin/Measurement.h | 4 +- .../src/flutter/include/minikin/MinikinFont.h | 4 +- .../include/minikin/MinikinFontFreeType.h | 4 +- .../include/minikin/MinikinRefCounted.h | 6 +- .../flutter/include/minikin/SparseBitSet.h | 4 +- .../src/flutter/include/minikin/WordBreaker.h | 4 +- .../src/flutter/libs/minikin/AnalyzeStyle.cpp | 4 +- .../src/flutter/libs/minikin/CmapCoverage.cpp | 4 +- .../flutter/libs/minikin/FontCollection.cpp | 8 +-- .../src/flutter/libs/minikin/FontFamily.cpp | 18 +++--- .../src/flutter/libs/minikin/FontLanguage.cpp | 4 +- .../src/flutter/libs/minikin/FontLanguage.h | 4 +- .../libs/minikin/FontLanguageListCache.cpp | 4 +- .../libs/minikin/FontLanguageListCache.h | 4 +- .../flutter/libs/minikin/GraphemeBreak.cpp | 4 +- .../src/flutter/libs/minikin/HbFontCache.cpp | 8 +-- engine/src/flutter/libs/minikin/HbFontCache.h | 4 +- .../src/flutter/libs/minikin/Hyphenator.cpp | 4 +- engine/src/flutter/libs/minikin/Layout.cpp | 63 ++++++++++--------- .../src/flutter/libs/minikin/LayoutUtils.cpp | 4 ++ engine/src/flutter/libs/minikin/LayoutUtils.h | 3 + .../src/flutter/libs/minikin/LineBreaker.cpp | 4 +- .../src/flutter/libs/minikin/Measurement.cpp | 4 +- .../src/flutter/libs/minikin/MinikinFont.cpp | 4 +- .../libs/minikin/MinikinFontFreeType.cpp | 4 +- .../flutter/libs/minikin/MinikinInternal.cpp | 6 +- .../flutter/libs/minikin/MinikinInternal.h | 6 +- .../libs/minikin/MinikinRefCounted.cpp | 8 +-- .../src/flutter/libs/minikin/SparseBitSet.cpp | 4 +- .../src/flutter/libs/minikin/WordBreaker.cpp | 4 +- .../libs/minikin/unicode_emoji_h_gen.py | 4 +- engine/src/flutter/sample/MinikinSkia.cpp | 4 +- engine/src/flutter/sample/MinikinSkia.h | 19 +++++- engine/src/flutter/sample/example.cpp | 1 - engine/src/flutter/sample/example_skia.cpp | 6 +- .../flutter/tests/perftests/FontLanguage.cpp | 4 +- .../unittest/FontCollectionItemizeTest.cpp | 23 +++---- .../tests/unittest/FontCollectionTest.cpp | 4 +- .../flutter/tests/unittest/FontFamilyTest.cpp | 12 ++-- .../unittest/FontLanguageListCacheTest.cpp | 8 +-- .../tests/unittest/GraphemeBreakTests.cpp | 4 +- .../tests/unittest/HbFontCacheTest.cpp | 12 ++-- .../src/flutter/tests/unittest/ICUTestBase.h | 4 +- .../tests/unittest/LayoutUtilsTest.cpp | 4 +- .../tests/unittest/MinikinInternalTest.cpp | 4 +- .../tests/unittest/WordBreakerTests.cpp | 4 +- .../src/flutter/tests/util/FontTestUtils.cpp | 22 ++++--- engine/src/flutter/tests/util/FontTestUtils.h | 5 +- .../flutter/tests/util/MinikinFontForTest.cpp | 12 ++-- .../flutter/tests/util/MinikinFontForTest.h | 14 +++-- .../src/flutter/tests/util/UnicodeUtils.cpp | 4 ++ engine/src/flutter/tests/util/UnicodeUtils.h | 6 +- 61 files changed, 238 insertions(+), 198 deletions(-) diff --git a/engine/src/flutter/app/HyphTool.cpp b/engine/src/flutter/app/HyphTool.cpp index 730abadcbaf..e421cf9671e 100644 --- a/engine/src/flutter/app/HyphTool.cpp +++ b/engine/src/flutter/app/HyphTool.cpp @@ -7,7 +7,7 @@ #include #include -using android::Hyphenator; +using minikin::Hyphenator; Hyphenator* loadHybFile(const char* fn) { struct stat statbuf; diff --git a/engine/src/flutter/include/minikin/AnalyzeStyle.h b/engine/src/flutter/include/minikin/AnalyzeStyle.h index 298947742ae..b4cd915108c 100644 --- a/engine/src/flutter/include/minikin/AnalyzeStyle.h +++ b/engine/src/flutter/include/minikin/AnalyzeStyle.h @@ -17,10 +17,10 @@ #ifndef MINIKIN_ANALYZE_STYLE_H #define MINIKIN_ANALYZE_STYLE_H -namespace android { +namespace minikin { bool analyzeStyle(const uint8_t* os2_data, size_t os2_size, int* weight, bool* italic); -} // namespace android +} // namespace minikin -#endif // MINIKIN_ANALYZE_STYLE_H \ No newline at end of file +#endif // MINIKIN_ANALYZE_STYLE_H diff --git a/engine/src/flutter/include/minikin/CmapCoverage.h b/engine/src/flutter/include/minikin/CmapCoverage.h index 56abac7bec3..19b43f38de7 100644 --- a/engine/src/flutter/include/minikin/CmapCoverage.h +++ b/engine/src/flutter/include/minikin/CmapCoverage.h @@ -19,7 +19,7 @@ #include -namespace android { +namespace minikin { class CmapCoverage { public: @@ -27,6 +27,6 @@ public: bool* has_cmap_format14_subtable); }; -} // namespace android +} // namespace minikin #endif // MINIKIN_CMAP_COVERAGE_H diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index c3c183db3b0..c9c8520be6b 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -23,7 +23,7 @@ #include #include -namespace android { +namespace minikin { class FontCollection : public MinikinRefCounted { public: @@ -98,6 +98,6 @@ private: std::vector mRanges; }; -} // namespace android +} // namespace minikin #endif // MINIKIN_FONT_COLLECTION_H diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 81033d23fda..f4b1f468d7d 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -26,7 +26,7 @@ #include #include -namespace android { +namespace minikin { class MinikinFont; @@ -52,7 +52,7 @@ public: return bits == other.bits && mLanguageListId == other.mLanguageListId; } - hash_t hash() const; + android::hash_t hash() const; // Looks up a language list from an internal cache and returns its ID. // If the passed language list is not in the cache, registers it and returns newly assigned ID. @@ -75,7 +75,7 @@ enum FontVariant { VARIANT_ELEGANT = 2, }; -inline hash_t hash_type(const FontStyle &style) { +inline android::hash_t hash_type(const FontStyle &style) { return style.hash(); } @@ -158,6 +158,6 @@ private: bool mCoverageValid; }; -} // namespace android +} // namespace minikin #endif // MINIKIN_FONT_FAMILY_H diff --git a/engine/src/flutter/include/minikin/GraphemeBreak.h b/engine/src/flutter/include/minikin/GraphemeBreak.h index 31201015855..b501f6784fa 100644 --- a/engine/src/flutter/include/minikin/GraphemeBreak.h +++ b/engine/src/flutter/include/minikin/GraphemeBreak.h @@ -17,7 +17,7 @@ #ifndef MINIKIN_GRAPHEME_BREAK_H #define MINIKIN_GRAPHEME_BREAK_H -namespace android { +namespace minikin { class GraphemeBreak { public: @@ -42,6 +42,6 @@ public: size_t offset, MoveOpt opt); }; -} // namespace android +} // namespace minikin -#endif // MINIKIN_GRAPHEME_BREAK_H \ No newline at end of file +#endif // MINIKIN_GRAPHEME_BREAK_H diff --git a/engine/src/flutter/include/minikin/Hyphenator.h b/engine/src/flutter/include/minikin/Hyphenator.h index 9605205a294..f922dcbfb79 100644 --- a/engine/src/flutter/include/minikin/Hyphenator.h +++ b/engine/src/flutter/include/minikin/Hyphenator.h @@ -24,7 +24,7 @@ #ifndef MINIKIN_HYPHENATOR_H #define MINIKIN_HYPHENATOR_H -namespace android { +namespace minikin { // hyb file header; implementation details are in the .cpp file struct Header; @@ -78,6 +78,6 @@ private: }; -} // namespace android +} // namespace minikin #endif // MINIKIN_HYPHENATOR_H diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index d9bb01f1a7c..87d5e0534ba 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -34,17 +34,13 @@ public: Bitmap(int width, int height); ~Bitmap(); void writePnm(std::ofstream& o) const; - void drawGlyph(const android::GlyphBitmap& bitmap, int x, int y); + void drawGlyph(const GlyphBitmap& bitmap, int x, int y); private: int width; int height; uint8_t* buf; }; -} // namespace minikin - -namespace android { - struct LayoutGlyph { // index into mFaces and mHbFonts vectors. We could imagine // moving this into a run length representation, because it's @@ -160,6 +156,6 @@ private: MinikinRect mBounds; }; -} // namespace android +} // namespace minikin #endif // MINIKIN_LAYOUT_H diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index 1d814040455..feaffe74e32 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -29,7 +29,7 @@ #include "minikin/Hyphenator.h" #include "minikin/WordBreaker.h" -namespace android { +namespace minikin { enum BreakStrategy { kBreakStrategy_Greedy = 0, @@ -243,6 +243,6 @@ class LineBreaker { int mFirstTabIndex; }; -} // namespace android +} // namespace minikin #endif // MINIKIN_LINE_BREAKER_H diff --git a/engine/src/flutter/include/minikin/Measurement.h b/engine/src/flutter/include/minikin/Measurement.h index 7bcab669dea..b00c2120a73 100644 --- a/engine/src/flutter/include/minikin/Measurement.h +++ b/engine/src/flutter/include/minikin/Measurement.h @@ -19,7 +19,7 @@ #include -namespace android { +namespace minikin { float getRunAdvance(const float* advances, const uint16_t* buf, size_t start, size_t count, size_t offset); @@ -27,6 +27,6 @@ float getRunAdvance(const float* advances, const uint16_t* buf, size_t start, si size_t getOffsetForAdvance(const float* advances, const uint16_t* buf, size_t start, size_t count, float advance); -} +} // namespace minikin #endif // MINIKIN_MEASUREMENT_H diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 4951514518f..9d4f9370898 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -25,7 +25,7 @@ // An abstraction for platform fonts, allowing Minikin to be used with // multiple actual implementations of fonts. -namespace android { +namespace minikin { // The hyphen edit represents an edit to the string when a word is // hyphenated. The most common hyphen edit is adding a "-" at the end @@ -137,6 +137,6 @@ private: const int32_t mUniqueId; }; -} // namespace android +} // namespace minikin #endif // MINIKIN_FONT_H diff --git a/engine/src/flutter/include/minikin/MinikinFontFreeType.h b/engine/src/flutter/include/minikin/MinikinFontFreeType.h index baa08df3b71..34c3fd92d4c 100644 --- a/engine/src/flutter/include/minikin/MinikinFontFreeType.h +++ b/engine/src/flutter/include/minikin/MinikinFontFreeType.h @@ -26,7 +26,7 @@ // An abstraction for platform fonts, allowing Minikin to be used with // multiple actual implementations of fonts. -namespace android { +namespace minikin { struct GlyphBitmap { uint8_t *buffer; @@ -65,6 +65,6 @@ private: static int32_t sIdCounter; }; -} // namespace android +} // namespace minikin #endif // MINIKIN_FONT_FREETYPE_H diff --git a/engine/src/flutter/include/minikin/MinikinRefCounted.h b/engine/src/flutter/include/minikin/MinikinRefCounted.h index 603aff0cce9..0ee44747c1b 100644 --- a/engine/src/flutter/include/minikin/MinikinRefCounted.h +++ b/engine/src/flutter/include/minikin/MinikinRefCounted.h @@ -19,7 +19,7 @@ #ifndef MINIKIN_REF_COUNTED_H #define MINIKIN_REF_COUNTED_H -namespace android { +namespace minikin { class MinikinRefCounted { public: @@ -54,6 +54,6 @@ private: T* mObj; }; -} +} // namespace minikin -#endif // MINIKIN_REF_COUNTED_H \ No newline at end of file +#endif // MINIKIN_REF_COUNTED_H diff --git a/engine/src/flutter/include/minikin/SparseBitSet.h b/engine/src/flutter/include/minikin/SparseBitSet.h index 72b83057c6c..00babbbf2f5 100644 --- a/engine/src/flutter/include/minikin/SparseBitSet.h +++ b/engine/src/flutter/include/minikin/SparseBitSet.h @@ -23,7 +23,7 @@ // --------------------------------------------------------------------------- -namespace android { +namespace minikin { // This is an implementation of a set of integers. It is optimized for // values that are somewhat sparse, in the ballpark of a maximum value @@ -87,6 +87,6 @@ private: // Note: this thing cannot be used in vectors yet. If that were important, we'd need to // make the copy constructor work, and probably set up move traits as well. -}; // namespace android +} // namespace minikin #endif // MINIKIN_SPARSE_BIT_SET_H diff --git a/engine/src/flutter/include/minikin/WordBreaker.h b/engine/src/flutter/include/minikin/WordBreaker.h index 4eff9d1755b..0f95bb208a5 100644 --- a/engine/src/flutter/include/minikin/WordBreaker.h +++ b/engine/src/flutter/include/minikin/WordBreaker.h @@ -26,7 +26,7 @@ #include "unicode/brkiter.h" #include -namespace android { +namespace minikin { class WordBreaker { public: @@ -68,6 +68,6 @@ private: bool mInEmailOrUrl; }; -} // namespace +} // namespace minikin #endif // MINIKIN_WORD_BREAKER_H diff --git a/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp b/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp index 09616452907..333f008f7fd 100644 --- a/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp +++ b/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp @@ -19,7 +19,7 @@ #include -namespace android { +namespace minikin { // should we have a single FontAnalyzer class this stuff lives in, to avoid dup? static int32_t readU16(const uint8_t* data, size_t offset) { @@ -40,4 +40,4 @@ bool analyzeStyle(const uint8_t* os2_data, size_t os2_size, int* weight, bool* i return true; } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/CmapCoverage.cpp b/engine/src/flutter/libs/minikin/CmapCoverage.cpp index 2961d2ffa8d..3dc2cd30744 100644 --- a/engine/src/flutter/libs/minikin/CmapCoverage.cpp +++ b/engine/src/flutter/libs/minikin/CmapCoverage.cpp @@ -25,7 +25,7 @@ using std::vector; #include #include -namespace android { +namespace minikin { // These could perhaps be optimized to use __builtin_bswap16 and friends. static uint32_t readU16(const uint8_t* data, size_t offset) { @@ -203,4 +203,4 @@ bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, return success; } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index b1b0aaf95f7..90b67d25501 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -30,7 +30,7 @@ using std::vector; -namespace android { +namespace minikin { template static inline T max(T a, T b) { @@ -77,7 +77,7 @@ uint32_t FontCollection::sNextId = 0; FontCollection::FontCollection(const vector& typefaces) : mMaxChar(0) { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); mId = sNextId++; vector lastChar; size_t nTypefaces = typefaces.size(); @@ -362,7 +362,7 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, return false; } - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); // Currently mRanges can not be used here since it isn't aware of the variation sequence. for (size_t i = 0; i < mVSFamilyVec.size(); i++) { @@ -471,4 +471,4 @@ uint32_t FontCollection::getId() const { return mId; } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index e2d86f0bbb0..99edb874731 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -38,7 +38,7 @@ using std::vector; -namespace android { +namespace minikin { FontStyle::FontStyle(int variant, int weight, bool italic) : FontStyle(FontLanguageListCache::kEmptyListId, variant, weight, italic) { @@ -48,15 +48,15 @@ FontStyle::FontStyle(uint32_t languageListId, int variant, int weight, bool ital : bits(pack(variant, weight, italic)), mLanguageListId(languageListId) { } -hash_t FontStyle::hash() const { - uint32_t hash = JenkinsHashMix(0, bits); - hash = JenkinsHashMix(hash, mLanguageListId); - return JenkinsHashWhiten(hash); +android::hash_t FontStyle::hash() const { + uint32_t hash = android::JenkinsHashMix(0, bits); + hash = android::JenkinsHashMix(hash, mLanguageListId); + return android::JenkinsHashWhiten(hash); } // static uint32_t FontStyle::registerLanguageList(const std::string& languages) { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); return FontLanguageListCache::getId(languages); } @@ -78,7 +78,7 @@ FontFamily::~FontFamily() { } bool FontFamily::addFont(MinikinFont* typeface) { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2'); HbBlob os2Table(getFontTable(typeface, os2Tag)); if (os2Table.get() == nullptr) return false; @@ -96,7 +96,7 @@ bool FontFamily::addFont(MinikinFont* typeface) { } void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); addFontLocked(typeface, style); } @@ -214,4 +214,4 @@ bool FontFamily::hasVSTable() const { return mHasVSTable; } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/FontLanguage.cpp b/engine/src/flutter/libs/minikin/FontLanguage.cpp index bccb4bf9e8f..9cfa0aa664a 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguage.cpp @@ -21,7 +21,7 @@ #include #include -namespace android { +namespace minikin { #define SCRIPT_TAG(c1, c2, c3, c4) \ (((uint32_t)(c1)) << 24 | ((uint32_t)(c2)) << 16 | ((uint32_t)(c3)) << 8 | \ @@ -183,4 +183,4 @@ FontLanguages::FontLanguages(std::vector&& languages) } #undef SCRIPT_TAG -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/FontLanguage.h b/engine/src/flutter/libs/minikin/FontLanguage.h index f944174a865..f28a4a8e720 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.h +++ b/engine/src/flutter/libs/minikin/FontLanguage.h @@ -22,7 +22,7 @@ #include -namespace android { +namespace minikin { // Due to the limits in font fallback score calculation, we can't use anything more than 17 // languages. @@ -121,6 +121,6 @@ private: void operator=(const FontLanguages&) = delete; }; -} // namespace android +} // namespace minikin #endif // MINIKIN_FONT_LANGUAGE_H diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp index 6b661f03846..bf46d4f6eaf 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp @@ -25,7 +25,7 @@ #include "MinikinInternal.h" #include "FontLanguage.h" -namespace android { +namespace minikin { const uint32_t FontLanguageListCache::kEmptyListId; @@ -152,4 +152,4 @@ FontLanguageListCache* FontLanguageListCache::getInstance() { return instance; } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.h b/engine/src/flutter/libs/minikin/FontLanguageListCache.h index c961882f0a8..9bf156f9de7 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.h +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.h @@ -22,7 +22,7 @@ #include #include "FontLanguage.h" -namespace android { +namespace minikin { class FontLanguageListCache { public: @@ -51,6 +51,6 @@ private: std::unordered_map mLanguageListLookupTable; }; -} // namespace android +} // namespace minikin #endif // MINIKIN_FONT_LANGUAGE_LIST_CACHE_H diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index 45dd0fff697..dc5a7619370 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -22,7 +22,7 @@ #include #include "MinikinInternal.h" -namespace android { +namespace minikin { int32_t tailoredGraphemeClusterBreak(uint32_t c) { // Characters defined as Control that we want to treat them as Extend. @@ -209,4 +209,4 @@ size_t GraphemeBreak::getTextRunCursor(const uint16_t* buf, size_t start, size_t return offset; } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index 3be942d7b9e..45c3f5807ba 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -26,7 +26,7 @@ #include #include "MinikinInternal.h" -namespace android { +namespace minikin { static hb_blob_t* referenceTable(hb_face_t* /* face */, hb_tag_t tag, void* userData) { MinikinFont* font = reinterpret_cast(userData); @@ -44,7 +44,7 @@ static hb_blob_t* referenceTable(hb_face_t* /* face */, hb_tag_t tag, void* user HB_MEMORY_MODE_READONLY, const_cast(buffer), destroy); } -class HbFontCache : private OnEntryRemoved { +class HbFontCache : private android::OnEntryRemoved { public: HbFontCache() : mCache(kMaxEntries) { mCache.setOnEntryRemovedListener(this); @@ -74,7 +74,7 @@ public: private: static const size_t kMaxEntries = 100; - LruCache mCache; + android::LruCache mCache; }; HbFontCache* getFontCacheLocked() { @@ -141,4 +141,4 @@ hb_font_t* getHbFontLocked(MinikinFont* minikinFont) { return hb_font_reference(font); } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/HbFontCache.h b/engine/src/flutter/libs/minikin/HbFontCache.h index 449b354c2db..fba685aeb27 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.h +++ b/engine/src/flutter/libs/minikin/HbFontCache.h @@ -19,12 +19,12 @@ struct hb_font_t; -namespace android { +namespace minikin { class MinikinFont; void purgeHbFontCacheLocked(); void purgeHbFontLocked(const MinikinFont* minikinFont); hb_font_t* getHbFontLocked(MinikinFont* minikinFont); -} // namespace android +} // namespace minikin #endif // MINIKIN_HBFONT_CACHE_H diff --git a/engine/src/flutter/libs/minikin/Hyphenator.cpp b/engine/src/flutter/libs/minikin/Hyphenator.cpp index c5eb60b8e50..c170c6bd483 100644 --- a/engine/src/flutter/libs/minikin/Hyphenator.cpp +++ b/engine/src/flutter/libs/minikin/Hyphenator.cpp @@ -30,7 +30,7 @@ using std::vector; -namespace android { +namespace minikin { static const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; @@ -232,4 +232,4 @@ void Hyphenator::hyphenateFromCodes(uint8_t* result, const uint16_t* codes, size } } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 9c1d6a873a5..713ac84f0a2 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -63,7 +63,7 @@ void Bitmap::writePnm(std::ofstream &o) const { o.close(); } -void Bitmap::drawGlyph(const android::GlyphBitmap& bitmap, int x, int y) { +void Bitmap::drawGlyph(const GlyphBitmap& bitmap, int x, int y) { int bmw = bitmap.width; int bmh = bitmap.height; x += bitmap.left; @@ -85,10 +85,6 @@ void Bitmap::drawGlyph(const android::GlyphBitmap& bitmap, int x, int y) { } } -} // namespace minikin - -namespace android { - const int kDirection_Mask = 0x1; struct LayoutContext { @@ -120,7 +116,7 @@ public: } bool operator==(const LayoutCacheKey &other) const; - hash_t hash() const { + android::hash_t hash() const { return mHash; } @@ -157,12 +153,12 @@ private: bool mIsRtl; // Note: any fields added to MinikinPaint must also be reflected here. // TODO: language matching (possibly integrate into style) - hash_t mHash; + android::hash_t mHash; - hash_t computeHash() const; + android::hash_t computeHash() const; }; -class LayoutCache : private OnEntryRemoved { +class LayoutCache : private android::OnEntryRemoved { public: LayoutCache() : mCache(kMaxEntries) { mCache.setOnEntryRemovedListener(this); @@ -190,7 +186,7 @@ private: delete value; } - LruCache mCache; + android::LruCache mCache; //static const size_t kMaxEntries = LruCache::kUnlimitedCapacity; @@ -204,7 +200,7 @@ static unsigned int disabledDecomposeCompatibility(hb_unicode_funcs_t*, hb_codep return 0; } -class LayoutEngine : public Singleton { +class LayoutEngine : public ::android::Singleton { public: LayoutEngine() { unicodeFunctions = hb_unicode_funcs_create(hb_icu_get_unicode_funcs()); @@ -220,8 +216,6 @@ public: LayoutCache layoutCache; }; -ANDROID_SINGLETON_STATIC_INSTANCE(LayoutEngine); - bool LayoutCacheKey::operator==(const LayoutCacheKey& other) const { return mId == other.mId && mStart == other.mStart @@ -238,23 +232,23 @@ bool LayoutCacheKey::operator==(const LayoutCacheKey& other) const { && !memcmp(mChars, other.mChars, mNchars * sizeof(uint16_t)); } -hash_t LayoutCacheKey::computeHash() const { - uint32_t hash = JenkinsHashMix(0, mId); - hash = JenkinsHashMix(hash, mStart); - hash = JenkinsHashMix(hash, mCount); - hash = JenkinsHashMix(hash, hash_type(mStyle)); - hash = JenkinsHashMix(hash, hash_type(mSize)); - hash = JenkinsHashMix(hash, hash_type(mScaleX)); - hash = JenkinsHashMix(hash, hash_type(mSkewX)); - hash = JenkinsHashMix(hash, hash_type(mLetterSpacing)); - hash = JenkinsHashMix(hash, hash_type(mPaintFlags)); - hash = JenkinsHashMix(hash, hash_type(mHyphenEdit.hasHyphen())); - hash = JenkinsHashMix(hash, hash_type(mIsRtl)); - hash = JenkinsHashMixShorts(hash, mChars, mNchars); - return JenkinsHashWhiten(hash); +android::hash_t LayoutCacheKey::computeHash() const { + uint32_t hash = android::JenkinsHashMix(0, mId); + hash = android::JenkinsHashMix(hash, mStart); + hash = android::JenkinsHashMix(hash, mCount); + hash = android::JenkinsHashMix(hash, hash_type(mStyle)); + hash = android::JenkinsHashMix(hash, hash_type(mSize)); + hash = android::JenkinsHashMix(hash, hash_type(mScaleX)); + hash = android::JenkinsHashMix(hash, hash_type(mSkewX)); + hash = android::JenkinsHashMix(hash, hash_type(mLetterSpacing)); + hash = android::JenkinsHashMix(hash, hash_type(mPaintFlags)); + hash = android::JenkinsHashMix(hash, hash_type(mHyphenEdit.hasHyphen())); + hash = android::JenkinsHashMix(hash, hash_type(mIsRtl)); + hash = android::JenkinsHashMixShorts(hash, mChars, mNchars); + return android::JenkinsHashWhiten(hash); } -hash_t hash_type(const LayoutCacheKey& key) { +android::hash_t hash_type(const LayoutCacheKey& key) { return key.hash(); } @@ -578,7 +572,7 @@ BidiText::BidiText(const uint16_t* buf, size_t start, size_t count, size_t bufSi void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint) { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); LayoutContext ctx; ctx.style = style; @@ -597,7 +591,7 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu float Layout::measureText(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint, const FontCollection* collection, float* advances) { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); LayoutContext ctx; ctx.style = style; @@ -965,10 +959,17 @@ void Layout::getBounds(MinikinRect* bounds) { } void Layout::purgeCaches() { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); LayoutCache& layoutCache = LayoutEngine::getInstance().layoutCache; layoutCache.clear(); purgeHbFontCacheLocked(); } +} // namespace minikin + +// Unable to define the static data member outside of android. +// TODO: introduce our own Singleton to drop android namespace. +namespace android { +ANDROID_SINGLETON_STATIC_INSTANCE(minikin::LayoutEngine); } // namespace android + diff --git a/engine/src/flutter/libs/minikin/LayoutUtils.cpp b/engine/src/flutter/libs/minikin/LayoutUtils.cpp index 418268286c6..4e59afd6b20 100644 --- a/engine/src/flutter/libs/minikin/LayoutUtils.cpp +++ b/engine/src/flutter/libs/minikin/LayoutUtils.cpp @@ -18,6 +18,8 @@ #include "LayoutUtils.h" +namespace minikin { + /** * For the purpose of layout, a word break is a boundary with no * kerning or complex script processing. This is necessarily a @@ -74,3 +76,5 @@ size_t getNextWordBreakForCache( } return len; } + +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/LayoutUtils.h b/engine/src/flutter/libs/minikin/LayoutUtils.h index 83ddd0a255d..f35e843cfa5 100644 --- a/engine/src/flutter/libs/minikin/LayoutUtils.h +++ b/engine/src/flutter/libs/minikin/LayoutUtils.h @@ -19,6 +19,8 @@ #include +namespace minikin { + /** * Return offset of previous word break. It is either < offset or == 0. * @@ -39,4 +41,5 @@ size_t getPrevWordBreakForCache( size_t getNextWordBreakForCache( const uint16_t* chars, size_t offset, size_t len); +} // namespace minikin #endif // MINIKIN_LAYOUT_UTILS_H diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 2a71f044d23..1940062eafa 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -26,7 +26,7 @@ using std::vector; -namespace android { +namespace minikin { const int CHAR_TAB = 0x0009; @@ -441,4 +441,4 @@ void LineBreaker::finish() { mLinePenalty = 0.0f; } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/Measurement.cpp b/engine/src/flutter/libs/minikin/Measurement.cpp index 1ba6678373b..a9655e4eaf5 100644 --- a/engine/src/flutter/libs/minikin/Measurement.cpp +++ b/engine/src/flutter/libs/minikin/Measurement.cpp @@ -23,7 +23,7 @@ #include #include -namespace android { +namespace minikin { // These could be considered helper methods of layout, but need only be loosely coupled, so // are separate. @@ -119,4 +119,4 @@ size_t getOffsetForAdvance(const float* advances, const uint16_t* buf, size_t st return best; } -} +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/MinikinFont.cpp b/engine/src/flutter/libs/minikin/MinikinFont.cpp index ef42e9b12f6..8aee01de7ed 100644 --- a/engine/src/flutter/libs/minikin/MinikinFont.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFont.cpp @@ -17,10 +17,10 @@ #include #include "HbFontCache.h" -namespace android { +namespace minikin { MinikinFont::~MinikinFont() { purgeHbFontLocked(this); } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp index 4a1b1150828..6f56a8dd55a 100644 --- a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp @@ -25,7 +25,7 @@ #include -namespace android { +namespace minikin { int32_t MinikinFontFreeType::sIdCounter = 0; @@ -97,4 +97,4 @@ MinikinFontFreeType* MinikinFontFreeType::GetFreeType() { return this; } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index 7fcc7b7f8b6..b1ca2df6690 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -22,9 +22,9 @@ #include -namespace android { +namespace minikin { -Mutex gMinikinLock; +android::Mutex gMinikinLock; void assertMinikinLocked() { #ifdef ENABLE_RACE_DETECTION @@ -88,4 +88,4 @@ hb_blob_t* getFontTable(MinikinFont* minikinFont, uint32_t tag) { return blob; } -} +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.h b/engine/src/flutter/libs/minikin/MinikinInternal.h index 88cc9475c8c..88c0d5f510a 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.h +++ b/engine/src/flutter/libs/minikin/MinikinInternal.h @@ -25,13 +25,13 @@ #include -namespace android { +namespace minikin { // All external Minikin interfaces are designed to be thread-safe. // Presently, that's implemented by through a global lock, and having // all external interfaces take that lock. -extern Mutex gMinikinLock; +extern android::Mutex gMinikinLock; // Aborts if gMinikinLock is not acquired. Do nothing on the release build. void assertMinikinLocked(); @@ -74,6 +74,6 @@ private: hb_blob_t* mBlob; }; -} +} // namespace minikin #endif // MINIKIN_INTERNAL_H diff --git a/engine/src/flutter/libs/minikin/MinikinRefCounted.cpp b/engine/src/flutter/libs/minikin/MinikinRefCounted.cpp index 9fa3ae46317..6914a012f84 100644 --- a/engine/src/flutter/libs/minikin/MinikinRefCounted.cpp +++ b/engine/src/flutter/libs/minikin/MinikinRefCounted.cpp @@ -20,16 +20,16 @@ #include -namespace android { +namespace minikin { void MinikinRefCounted::Ref() { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); this->RefLocked(); } void MinikinRefCounted::Unref() { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); this->UnrefLocked(); } -} +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/SparseBitSet.cpp b/engine/src/flutter/libs/minikin/SparseBitSet.cpp index de0791445cd..d78dd246ed2 100644 --- a/engine/src/flutter/libs/minikin/SparseBitSet.cpp +++ b/engine/src/flutter/libs/minikin/SparseBitSet.cpp @@ -19,7 +19,7 @@ #include #include -namespace android { +namespace minikin { const uint32_t SparseBitSet::kNotFound; @@ -146,4 +146,4 @@ uint32_t SparseBitSet::nextSetBit(uint32_t fromIndex) const { return kNotFound; } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index 38f03caf6a0..a852eddddfb 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -23,7 +23,7 @@ #include #include -namespace android { +namespace minikin { const uint32_t CHAR_SOFT_HYPHEN = 0x00AD; const uint32_t CHAR_ZWJ = 0x200D; @@ -258,4 +258,4 @@ void WordBreaker::finish() { utext_close(&mUText); } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/unicode_emoji_h_gen.py b/engine/src/flutter/libs/minikin/unicode_emoji_h_gen.py index 7233ef621e3..51864551884 100644 --- a/engine/src/flutter/libs/minikin/unicode_emoji_h_gen.py +++ b/engine/src/flutter/libs/minikin/unicode_emoji_h_gen.py @@ -27,7 +27,7 @@ UNICODE_EMOJI_TEMPLATE=""" #include -namespace android { +namespace minikin { namespace generated { int32_t EMOJI_LIST[] = { @@ -35,7 +35,7 @@ int32_t EMOJI_LIST[] = { }; } // namespace generated -} // namespace android +} // namespace minikin #endif // MINIKIN_UNICODE_EMOJI_H """ diff --git a/engine/src/flutter/sample/MinikinSkia.cpp b/engine/src/flutter/sample/MinikinSkia.cpp index e2ecde02d18..c920ca63e56 100644 --- a/engine/src/flutter/sample/MinikinSkia.cpp +++ b/engine/src/flutter/sample/MinikinSkia.cpp @@ -4,7 +4,7 @@ #include #include "MinikinSkia.h" -namespace android { +namespace minikin { MinikinFontSkia::MinikinFontSkia(SkTypeface *typeface) : MinikinFont(typeface->uniqueID()), @@ -68,4 +68,4 @@ SkTypeface *MinikinFontSkia::GetSkTypeface() { return mTypeface; } -} +} // namespace minikin diff --git a/engine/src/flutter/sample/MinikinSkia.h b/engine/src/flutter/sample/MinikinSkia.h index 6eb9065cc2c..92f5ed2f524 100644 --- a/engine/src/flutter/sample/MinikinSkia.h +++ b/engine/src/flutter/sample/MinikinSkia.h @@ -1,4 +1,19 @@ -namespace android { +/* + * Copyright (C) 2016 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. + */ +namespace minikin { class MinikinFontSkia : public MinikinFont { public: @@ -21,4 +36,4 @@ private: }; -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/sample/example.cpp b/engine/src/flutter/sample/example.cpp index f4c6a07a4a6..a27918ea758 100644 --- a/engine/src/flutter/sample/example.cpp +++ b/engine/src/flutter/sample/example.cpp @@ -28,7 +28,6 @@ #include using std::vector; -using namespace android; using namespace minikin; FT_Library library; // TODO: this should not be a global diff --git a/engine/src/flutter/sample/example_skia.cpp b/engine/src/flutter/sample/example_skia.cpp index f892b8c987a..bd2d779b9e9 100644 --- a/engine/src/flutter/sample/example_skia.cpp +++ b/engine/src/flutter/sample/example_skia.cpp @@ -37,7 +37,7 @@ using std::vector; -namespace android { +namespace minikin { FT_Library library; // TODO: this should not be a global @@ -145,8 +145,8 @@ int runMinikinTest() { return 0; } -} +} // namespace minikin int main(int argc, const char** argv) { - return android::runMinikinTest(); + return minikin::runMinikinTest(); } diff --git a/engine/src/flutter/tests/perftests/FontLanguage.cpp b/engine/src/flutter/tests/perftests/FontLanguage.cpp index ac7af6f909d..8f77e12b75d 100644 --- a/engine/src/flutter/tests/perftests/FontLanguage.cpp +++ b/engine/src/flutter/tests/perftests/FontLanguage.cpp @@ -17,7 +17,7 @@ #include "FontLanguage.h" -using android::FontLanguage; +namespace minikin { static void BM_FontLanguage_en_US(benchmark::State& state) { while (state.KeepRunning()) { @@ -32,3 +32,5 @@ static void BM_FontLanguage_en_Latn_US(benchmark::State& state) { } } BENCHMARK(BM_FontLanguage_en_Latn_US); + +} // namespace minikin diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 8ad9472490a..8ae703ea126 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -25,16 +25,7 @@ #include "UnicodeUtils.h" #include "minikin/FontFamily.h" -using android::AutoMutex; -using android::FontCollection; -using android::FontFamily; -using android::FontLanguage; -using android::FontLanguages; -using android::FontLanguageListCache; -using android::FontStyle; -using android::MinikinAutoUnref; -using android::MinikinFont; -using android::gMinikinLock; +namespace minikin { const char kItemizeFontXml[] = kTestFontDir "itemize.xml"; const char kEmojiFont[] = kTestFontDir "Emoji.ttf"; @@ -64,7 +55,7 @@ void itemize(FontCollection* collection, const char* str, FontStyle style, result->clear(); ParseUnicode(buf, BUF_SIZE, str, &len, NULL); - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); collection->itemize(buf, len, style, result); } @@ -76,7 +67,7 @@ const std::string& getFontPath(const FontCollection::Run& run) { // Utility function to obtain FontLanguages from string. const FontLanguages& registerAndGetFontLanguages(const std::string& lang_string) { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); return FontLanguageListCache::getById(FontLanguageListCache::getId(lang_string)); } @@ -673,12 +664,12 @@ TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { // point. const std::string kVSTestFont = kTestFontDir "VarioationSelectorTest-Regular.ttf"; - std::vector families; - FontFamily* family1 = new FontFamily(android::VARIANT_DEFAULT); + std::vector families; + FontFamily* family1 = new FontFamily(VARIANT_DEFAULT); family1->addFont(new MinikinFontForTest(kLatinFont)); families.push_back(family1); - FontFamily* family2 = new FontFamily(android::VARIANT_DEFAULT); + FontFamily* family2 = new FontFamily(VARIANT_DEFAULT); family2->addFont(new MinikinFontForTest(kVSTestFont)); families.push_back(family2); @@ -1372,3 +1363,5 @@ TEST_F(FontCollectionItemizeTest, itemize_PrivateUseArea) { EXPECT_EQ(4, runs[0].end); EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); } + +} // namespace minikin diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index 5a03f60d26f..a22067a5b09 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -21,7 +21,7 @@ #include "MinikinFontForTest.h" #include "MinikinInternal.h" -namespace android { +namespace minikin { // The test font has following glyphs. // U+82A6 @@ -107,4 +107,4 @@ TEST(FontCollectionTest, hasVariationSelectorTest_emoji) { EXPECT_FALSE(collection->hasVariationSelector(0x2229, 0xFE0F)); } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 1b2457695c4..384703f8c48 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -25,19 +25,19 @@ #include "MinikinFontForTest.h" #include "MinikinInternal.h" -namespace android { +namespace minikin { typedef ICUTestBase FontLanguagesTest; typedef ICUTestBase FontLanguageTest; static const FontLanguages& createFontLanguages(const std::string& input) { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); uint32_t langId = FontLanguageListCache::getId(input); return FontLanguageListCache::getById(langId); } static FontLanguage createFontLanguage(const std::string& input) { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); uint32_t langId = FontLanguageListCache::getId(input); return FontLanguageListCache::getById(langId)[0]; } @@ -354,7 +354,7 @@ TEST_F(FontFamilyTest, hasVariationSelectorTest) { MinikinAutoUnref family(new FontFamily); family->addFont(minikinFont.get()); - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); const uint32_t kVS1 = 0xFE00; const uint32_t kVS2 = 0xFE01; @@ -406,11 +406,11 @@ TEST_F(FontFamilyTest, hasVSTableTest) { MinikinAutoUnref minikinFont(new MinikinFontForTest(testCase.fontPath)); MinikinAutoUnref family(new FontFamily); family->addFont(minikinFont.get()); - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); family->getCoverage(); EXPECT_EQ(testCase.hasVSTable, family->hasVSTable()); } } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp b/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp index 2a046713c9c..81d84a8a288 100644 --- a/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp @@ -22,7 +22,7 @@ #include "ICUTestBase.h" #include "MinikinInternal.h" -namespace android { +namespace minikin { typedef ICUTestBase FontLanguageListCacheTest; @@ -31,7 +31,7 @@ TEST_F(FontLanguageListCacheTest, getId) { EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en,zh-Hans")); - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); EXPECT_EQ(0UL, FontLanguageListCache::getId("")); EXPECT_EQ(FontLanguageListCache::getId("en"), FontLanguageListCache::getId("en")); @@ -50,7 +50,7 @@ TEST_F(FontLanguageListCacheTest, getId) { } TEST_F(FontLanguageListCacheTest, getById) { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); uint32_t enLangId = FontLanguageListCache::getId("en"); uint32_t jpLangId = FontLanguageListCache::getId("jp"); FontLanguage english = FontLanguageListCache::getById(enLangId)[0]; @@ -70,4 +70,4 @@ TEST_F(FontLanguageListCacheTest, getById) { EXPECT_EQ(japanese, langs2[1]); } -} // android +} // namespace minikin diff --git a/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp b/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp index cec53088774..07ddf82ce68 100644 --- a/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp +++ b/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp @@ -18,7 +18,7 @@ #include #include -using namespace android; +namespace minikin { bool IsBreak(const char* src) { const size_t BUF_SIZE = 256; @@ -188,3 +188,5 @@ TEST(GraphemeBreak, offsets) { EXPECT_TRUE(GraphemeBreak::isGraphemeBreak(string, 2, 3, 4)); EXPECT_TRUE(GraphemeBreak::isGraphemeBreak(string, 2, 3, 5)); } + +} // namespace minikin diff --git a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp index 2dee61aff06..82adc4f7681 100644 --- a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp @@ -26,19 +26,18 @@ #include "MinikinFontForTest.h" #include -namespace android { -namespace { +namespace minikin { class HbFontCacheTest : public testing::Test { public: virtual void TearDown() { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); purgeHbFontCacheLocked(); } }; TEST_F(HbFontCacheTest, getHbFontLockedTest) { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); MinikinFontForTest fontA(kTestFontDir "Regular.ttf"); MinikinFontForTest fontB(kTestFontDir "Bold.ttf"); @@ -62,7 +61,7 @@ TEST_F(HbFontCacheTest, getHbFontLockedTest) { } TEST_F(HbFontCacheTest, purgeCacheTest) { - AutoMutex _l(gMinikinLock); + android::AutoMutex _l(gMinikinLock); MinikinFontForTest minikinFont(kTestFontDir "Regular.ttf"); hb_font_t* font = getHbFontLocked(&minikinFont); @@ -83,5 +82,4 @@ TEST_F(HbFontCacheTest, purgeCacheTest) { EXPECT_EQ(nullptr, hb_font_get_user_data(font, &key)); } -} // namespace -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/tests/unittest/ICUTestBase.h b/engine/src/flutter/tests/unittest/ICUTestBase.h index 3bcfaf36945..f915cf80cec 100644 --- a/engine/src/flutter/tests/unittest/ICUTestBase.h +++ b/engine/src/flutter/tests/unittest/ICUTestBase.h @@ -26,6 +26,8 @@ #include #include +namespace minikin { + class ICUTestBase : public testing::Test { protected: virtual void SetUp() override { @@ -48,5 +50,5 @@ protected: } }; - +} // namespace minikin #endif // MINIKIN_TEST_ICU_TEST_BASE_H diff --git a/engine/src/flutter/tests/unittest/LayoutUtilsTest.cpp b/engine/src/flutter/tests/unittest/LayoutUtilsTest.cpp index f4fbb181076..e7e6c273d63 100644 --- a/engine/src/flutter/tests/unittest/LayoutUtilsTest.cpp +++ b/engine/src/flutter/tests/unittest/LayoutUtilsTest.cpp @@ -19,7 +19,7 @@ #include "LayoutUtils.h" -namespace { +namespace minikin { void ExpectNextWordBreakForCache(size_t offset_in, const char* query_str) { const size_t BUF_SIZE = 256U; @@ -507,4 +507,4 @@ TEST(WordBreakTest, goPrevWordBreakTest) { ExpectPrevWordBreakForCache(1000, "U+4444 U+302D U+302D | U+4444"); } -} // namespace +} // namespace minikin diff --git a/engine/src/flutter/tests/unittest/MinikinInternalTest.cpp b/engine/src/flutter/tests/unittest/MinikinInternalTest.cpp index 9c1a1e54a4b..e314dd1be5c 100644 --- a/engine/src/flutter/tests/unittest/MinikinInternalTest.cpp +++ b/engine/src/flutter/tests/unittest/MinikinInternalTest.cpp @@ -18,7 +18,7 @@ #include "MinikinInternal.h" -namespace android { +namespace minikin { TEST(MinikinInternalTest, isEmojiTest) { EXPECT_TRUE(isEmoji(0x0023)); // NUMBER SIGN @@ -31,4 +31,4 @@ TEST(MinikinInternalTest, isEmojiTest) { EXPECT_FALSE(isEmoji(0x29E3D)); // A han character. } -} // namespace android +} // namespace minikin diff --git a/engine/src/flutter/tests/unittest/WordBreakerTests.cpp b/engine/src/flutter/tests/unittest/WordBreakerTests.cpp index 8ed87cc5069..bacf3178a1a 100644 --- a/engine/src/flutter/tests/unittest/WordBreakerTests.cpp +++ b/engine/src/flutter/tests/unittest/WordBreakerTests.cpp @@ -31,7 +31,7 @@ #define UTF16(codepoint) U16_LEAD(codepoint), U16_TRAIL(codepoint) -using namespace android; +namespace minikin { typedef ICUTestBase WordBreakerTest; @@ -388,3 +388,5 @@ TEST_F(WordBreakerTest, emailStartsWithSlash) { EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end EXPECT_TRUE(breaker.wordStart() >= breaker.wordEnd()); } + +} // namespace minikin diff --git a/engine/src/flutter/tests/util/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp index fdc3ed6ee91..76d3ea20a24 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.cpp +++ b/engine/src/flutter/tests/util/FontTestUtils.cpp @@ -24,31 +24,33 @@ #include "FontLanguage.h" #include "MinikinFontForTest.h" -android::FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { +namespace minikin { + +FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { xmlDoc* doc = xmlReadFile(fontXml, NULL, 0); xmlNode* familySet = xmlDocGetRootElement(doc); - std::vector families; + std::vector families; for (xmlNode* familyNode = familySet->children; familyNode; familyNode = familyNode->next) { if (xmlStrcmp(familyNode->name, (const xmlChar*)"family") != 0) { continue; } xmlChar* variantXmlch = xmlGetProp(familyNode, (const xmlChar*)"variant"); - int variant = android::VARIANT_DEFAULT; + int variant = VARIANT_DEFAULT; if (variantXmlch) { if (xmlStrcmp(variantXmlch, (const xmlChar*)"elegant") == 0) { - variant = android::VARIANT_ELEGANT; + variant = VARIANT_ELEGANT; } else if (xmlStrcmp(variantXmlch, (const xmlChar*)"compact") == 0) { - variant = android::VARIANT_COMPACT; + variant = VARIANT_COMPACT; } } xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); - uint32_t langId = android::FontStyle::registerLanguageList( + uint32_t langId = FontStyle::registerLanguageList( std::string((const char*)lang, xmlStrlen(lang))); - android::FontFamily* family = new android::FontFamily(langId, variant); + FontFamily* family = new FontFamily(langId, variant); for (xmlNode* fontNode = familyNode->children; fontNode; fontNode = fontNode->next) { if (xmlStrcmp(fontNode->name, (const xmlChar*)"font") != 0) { @@ -66,16 +68,18 @@ android::FontCollection* getFontCollection(const char* fontDir, const char* font LOG_ALWAYS_FATAL_IF(access(fontPath.c_str(), R_OK) != 0, "%s is not found", fontPath.c_str()); - family->addFont(new MinikinFontForTest(fontPath), android::FontStyle(weight, italic)); + family->addFont(new MinikinFontForTest(fontPath), FontStyle(weight, italic)); } families.push_back(family); } xmlFreeDoc(doc); - android::FontCollection* collection = new android::FontCollection(families); + FontCollection* collection = new FontCollection(families); collection->Ref(); for (size_t i = 0; i < families.size(); ++i) { families[i]->Unref(); } return collection; } + +} // namespace minikin diff --git a/engine/src/flutter/tests/util/FontTestUtils.h b/engine/src/flutter/tests/util/FontTestUtils.h index 5258a766ae5..69ba841b438 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.h +++ b/engine/src/flutter/tests/util/FontTestUtils.h @@ -19,6 +19,8 @@ #include +namespace minikin { + /** * Returns FontCollection from installed fonts. * @@ -27,6 +29,7 @@ * * Caller must unref the returned pointer. */ -android::FontCollection* getFontCollection(const char* fontDir, const char* fontXml); +FontCollection* getFontCollection(const char* fontDir, const char* fontXml); +} // namespace minikin #endif // MINIKIN_FONT_TEST_UTILS_H diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.cpp b/engine/src/flutter/tests/util/MinikinFontForTest.cpp index 66dd4ea4734..ae8ef72bcfa 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/util/MinikinFontForTest.cpp @@ -22,6 +22,8 @@ #include +namespace minikin { + MinikinFontForTest::MinikinFontForTest(const std::string& font_path) : MinikinFontForTest(font_path, SkTypeface::CreateFromFile(font_path.c_str())) { } @@ -36,18 +38,18 @@ MinikinFontForTest::~MinikinFontForTest() { } float MinikinFontForTest::GetHorizontalAdvance(uint32_t /* glyph_id */, - const android::MinikinPaint& /* paint */) const { + const MinikinPaint& /* paint */) const { LOG_ALWAYS_FATAL("MinikinFontForTest::GetHorizontalAdvance is not yet implemented"); return 0.0f; } -void MinikinFontForTest::GetBounds(android::MinikinRect* /* bounds */, uint32_t /* glyph_id */, - const android::MinikinPaint& /* paint */) const { +void MinikinFontForTest::GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph_id */, + const MinikinPaint& /* paint */) const { LOG_ALWAYS_FATAL("MinikinFontForTest::GetBounds is not yet implemented"); } const void* MinikinFontForTest::GetTable(uint32_t tag, size_t* size, - android::MinikinDestroyFunc* destroy) { + MinikinDestroyFunc* destroy) { const size_t tableSize = mTypeface->getTableSize(tag); *size = tableSize; if (tableSize == 0) { @@ -61,3 +63,5 @@ const void* MinikinFontForTest::GetTable(uint32_t tag, size_t* size, *destroy = free; return buf; } + +} // namespace minikin diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.h b/engine/src/flutter/tests/util/MinikinFontForTest.h index e527d21e34d..56f63adaff8 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.h +++ b/engine/src/flutter/tests/util/MinikinFontForTest.h @@ -21,17 +21,19 @@ class SkTypeface; -class MinikinFontForTest : public android::MinikinFont { +namespace minikin { + +class MinikinFontForTest : public MinikinFont { public: explicit MinikinFontForTest(const std::string& font_path); MinikinFontForTest(const std::string& font_path, SkTypeface* typeface); ~MinikinFontForTest(); // MinikinFont overrides. - float GetHorizontalAdvance(uint32_t glyph_id, const android::MinikinPaint &paint) const; - void GetBounds(android::MinikinRect* bounds, uint32_t glyph_id, - const android::MinikinPaint& paint) const; - const void* GetTable(uint32_t tag, size_t* size, android::MinikinDestroyFunc* destroy); + float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const; + void GetBounds(MinikinRect* bounds, uint32_t glyph_id, + const MinikinPaint& paint) const; + const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); const std::string& fontPath() const { return mFontPath; } private: @@ -39,4 +41,6 @@ private: const std::string mFontPath; }; +} // namespace minikin + #endif // MINIKIN_TEST_MINIKIN_FONT_FOR_TEST_H diff --git a/engine/src/flutter/tests/util/UnicodeUtils.cpp b/engine/src/flutter/tests/util/UnicodeUtils.cpp index 501fc9f4808..bb652ff63dc 100644 --- a/engine/src/flutter/tests/util/UnicodeUtils.cpp +++ b/engine/src/flutter/tests/util/UnicodeUtils.cpp @@ -18,6 +18,8 @@ #include #include +namespace minikin { + // src is of the form "U+1F431 | 'h' 'i'". Position of "|" gets saved to offset if non-null. // Size is returned in an out parameter because gtest needs a void return for ASSERT to work. void ParseUnicode(uint16_t* buf, size_t buf_size, const char* src, size_t* result_size, @@ -94,3 +96,5 @@ TEST(UnicodeUtils, parse) { EXPECT_EQ(buf[2], 0xDC31); EXPECT_EQ(buf[3], 'a'); } + +} // namespace minikin diff --git a/engine/src/flutter/tests/util/UnicodeUtils.h b/engine/src/flutter/tests/util/UnicodeUtils.h index 4f1b06a2fc1..64b90c91b19 100644 --- a/engine/src/flutter/tests/util/UnicodeUtils.h +++ b/engine/src/flutter/tests/util/UnicodeUtils.h @@ -14,5 +14,9 @@ * limitations under the License. */ - void ParseUnicode(uint16_t* buf, size_t buf_size, const char* src, size_t* result_size, +namespace minikin { + +void ParseUnicode(uint16_t* buf, size_t buf_size, const char* src, size_t* result_size, size_t* offset); + +} // namespace minikin From c3b9f7dadde2701885950c0d6aa0f6f739b5cecb Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 16 Jun 2016 16:59:30 +0900 Subject: [PATCH 186/364] Fix test utilities This fixes following three memory leaks in test utilities. There is no problem in production code and this CL doesn't affect any production behaviors. - SkTypeface leaks due to forget calling SkSafeUnref in dtor. - MinikinFontForTest leaks during constructing FontCollection. - FontCollection leaks due to unnecessary AddRef. Change-Id: I22e1e0307f1b2499296acb1aacc3ef66076a36e9 --- .../unittest/FontCollectionItemizeTest.cpp | 23 ++++++----- .../tests/unittest/FontCollectionTest.cpp | 32 +++++++-------- .../flutter/tests/unittest/FontFamilyTest.cpp | 6 ++- .../tests/unittest/HbFontCacheTest.cpp | 39 +++++++++++-------- .../src/flutter/tests/util/FontTestUtils.cpp | 6 ++- .../flutter/tests/util/MinikinFontForTest.cpp | 16 +++++--- .../flutter/tests/util/MinikinFontForTest.h | 9 ++++- 7 files changed, 78 insertions(+), 53 deletions(-) diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 8ae703ea126..b28820b1f84 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -666,11 +666,13 @@ TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { std::vector families; FontFamily* family1 = new FontFamily(VARIANT_DEFAULT); - family1->addFont(new MinikinFontForTest(kLatinFont)); + MinikinAutoUnref font(MinikinFontForTest::createFromFile(kLatinFont)); + family1->addFont(font.get()); families.push_back(family1); FontFamily* family2 = new FontFamily(VARIANT_DEFAULT); - family2->addFont(new MinikinFontForTest(kVSTestFont)); + MinikinAutoUnref font2(MinikinFontForTest::createFromFile(kVSTestFont)); + family2->addFont(font2.get()); families.push_back(family2); FontCollection collection(families); @@ -794,8 +796,9 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { // Prepare first font which doesn't supports U+9AA8 FontFamily* firstFamily = new FontFamily( FontStyle::registerLanguageList("und"), 0 /* variant */); - MinikinFont* firstFamilyMinikinFont = new MinikinFontForTest(kNoGlyphFont); - firstFamily->addFont(firstFamilyMinikinFont); + MinikinAutoUnref firstFamilyMinikinFont( + MinikinFontForTest::createFromFile(kNoGlyphFont)); + firstFamily->addFont(firstFamilyMinikinFont.get()); families.push_back(firstFamily); // Prepare font families @@ -806,12 +809,12 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { for (size_t i = 0; i < testCase.fontLanguages.size(); ++i) { FontFamily* family = new FontFamily( FontStyle::registerLanguageList(testCase.fontLanguages[i]), 0 /* variant */); - MinikinFont* minikin_font = new MinikinFontForTest(kJAFont); - family->addFont(minikin_font); + MinikinAutoUnref minikin_font(MinikinFontForTest::createFromFile(kJAFont)); + family->addFont(minikin_font.get()); families.push_back(family); - fontLangIdxMap.insert(std::make_pair(minikin_font, i)); + fontLangIdxMap.insert(std::make_pair(minikin_font.get(), i)); } - FontCollection collection(families); + MinikinAutoUnref collection(new FontCollection(families)); for (auto family : families) { family->Unref(); } @@ -820,13 +823,13 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { const FontStyle style = FontStyle( FontStyle::registerLanguageList(testCase.userPreferredLanguages)); std::vector runs; - itemize(&collection, "U+9AA8", style, &runs); + itemize(collection.get(), "U+9AA8", style, &runs); ASSERT_EQ(1U, runs.size()); ASSERT_NE(nullptr, runs[0].fakedFont.font); // First family doesn't support U+9AA8 and others support it, so the first font should not // be selected. - EXPECT_NE(firstFamilyMinikinFont, runs[0].fakedFont.font); + EXPECT_NE(firstFamilyMinikinFont.get(), runs[0].fakedFont.font); // Lookup used font family by MinikinFont*. const int usedLangIndex = fontLangIdxMap[runs[0].fakedFont.font]; diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index a22067a5b09..3f365be083a 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -40,40 +40,40 @@ namespace minikin { // U+717D U+E0103 (VS20) const char kVsTestFont[] = kTestFontDir "/VarioationSelectorTest-Regular.ttf"; -void expectVSGlyphs(const FontCollection& fc, uint32_t codepoint, const std::set& vsSet) { +void expectVSGlyphs(const FontCollection* fc, uint32_t codepoint, const std::set& vsSet) { for (uint32_t vs = 0xFE00; vs <= 0xE01EF; ++vs) { // Move to variation selectors supplements after variation selectors. if (vs == 0xFF00) { vs = 0xE0100; } if (vsSet.find(vs) == vsSet.end()) { - EXPECT_FALSE(fc.hasVariationSelector(codepoint, vs)) + EXPECT_FALSE(fc->hasVariationSelector(codepoint, vs)) << "Glyph for U+" << std::hex << codepoint << " U+" << vs; } else { - EXPECT_TRUE(fc.hasVariationSelector(codepoint, vs)) + EXPECT_TRUE(fc->hasVariationSelector(codepoint, vs)) << "Glyph for U+" << std::hex << codepoint << " U+" << vs; } } } TEST(FontCollectionTest, hasVariationSelectorTest) { - FontFamily* family = new FontFamily(); - family->addFont(new MinikinFontForTest(kVsTestFont)); - std::vector families({family}); - FontCollection fc(families); - family->Unref(); + MinikinAutoUnref family(new FontFamily()); + MinikinAutoUnref font(MinikinFontForTest::createFromFile(kVsTestFont)); + family->addFont(font.get()); + std::vector families({family.get()}); + MinikinAutoUnref fc(new FontCollection(families)); - EXPECT_FALSE(fc.hasVariationSelector(0x82A6, 0)); - expectVSGlyphs(fc, 0x82A6, std::set({0xFE00, 0xE0100, 0xE0101, 0xE0102})); + EXPECT_FALSE(fc->hasVariationSelector(0x82A6, 0)); + expectVSGlyphs(fc.get(), 0x82A6, std::set({0xFE00, 0xE0100, 0xE0101, 0xE0102})); - EXPECT_FALSE(fc.hasVariationSelector(0x845B, 0)); - expectVSGlyphs(fc, 0x845B, std::set({0xFE01, 0xE0101, 0xE0102, 0xE0103})); + EXPECT_FALSE(fc->hasVariationSelector(0x845B, 0)); + expectVSGlyphs(fc.get(), 0x845B, std::set({0xFE01, 0xE0101, 0xE0102, 0xE0103})); - EXPECT_FALSE(fc.hasVariationSelector(0x537F, 0)); - expectVSGlyphs(fc, 0x537F, std::set({})); + EXPECT_FALSE(fc->hasVariationSelector(0x537F, 0)); + expectVSGlyphs(fc.get(), 0x537F, std::set({})); - EXPECT_FALSE(fc.hasVariationSelector(0x717D, 0)); - expectVSGlyphs(fc, 0x717D, std::set({0xFE02, 0xE0102, 0xE0103})); + EXPECT_FALSE(fc->hasVariationSelector(0x717D, 0)); + expectVSGlyphs(fc.get(), 0x717D, std::set({0xFE02, 0xE0102, 0xE0103})); } const char kEmojiXmlFile[] = kTestFontDir "emoji.xml"; diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 384703f8c48..69fef23da82 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -350,7 +350,8 @@ void expectVSGlyphs(FontFamily* family, uint32_t codepoint, const std::set minikinFont(new MinikinFontForTest(kVsTestFont)); + MinikinAutoUnref + minikinFont(MinikinFontForTest::createFromFile(kVsTestFont)); MinikinAutoUnref family(new FontFamily); family->addFont(minikinFont.get()); @@ -403,7 +404,8 @@ TEST_F(FontFamilyTest, hasVSTableTest) { "Font " + testCase.fontPath + " should have a variation sequence table." : "Font " + testCase.fontPath + " shouldn't have a variation sequence table."); - MinikinAutoUnref minikinFont(new MinikinFontForTest(testCase.fontPath)); + MinikinAutoUnref minikinFont( + MinikinFontForTest::createFromFile(testCase.fontPath)); MinikinAutoUnref family(new FontFamily); family->addFont(minikinFont.get()); android::AutoMutex _l(gMinikinLock); diff --git a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp index 82adc4f7681..aa4cb34c053 100644 --- a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp @@ -37,34 +37,39 @@ public: }; TEST_F(HbFontCacheTest, getHbFontLockedTest) { + MinikinAutoUnref fontA( + MinikinFontForTest::createFromFile(kTestFontDir "Regular.ttf")); + + MinikinAutoUnref fontB( + MinikinFontForTest::createFromFile(kTestFontDir "Bold.ttf")); + + MinikinAutoUnref fontC( + MinikinFontForTest::createFromFile(kTestFontDir "BoldItalic.ttf")); + android::AutoMutex _l(gMinikinLock); - - MinikinFontForTest fontA(kTestFontDir "Regular.ttf"); - MinikinFontForTest fontB(kTestFontDir "Bold.ttf"); - MinikinFontForTest fontC(kTestFontDir "BoldItalic.ttf"); - // Never return NULL. - EXPECT_NE(nullptr, getHbFontLocked(&fontA)); - EXPECT_NE(nullptr, getHbFontLocked(&fontB)); - EXPECT_NE(nullptr, getHbFontLocked(&fontC)); + EXPECT_NE(nullptr, getHbFontLocked(fontA.get())); + EXPECT_NE(nullptr, getHbFontLocked(fontB.get())); + EXPECT_NE(nullptr, getHbFontLocked(fontC.get())); EXPECT_NE(nullptr, getHbFontLocked(nullptr)); // Must return same object if same font object is passed. - EXPECT_EQ(getHbFontLocked(&fontA), getHbFontLocked(&fontA)); - EXPECT_EQ(getHbFontLocked(&fontB), getHbFontLocked(&fontB)); - EXPECT_EQ(getHbFontLocked(&fontC), getHbFontLocked(&fontC)); + EXPECT_EQ(getHbFontLocked(fontA.get()), getHbFontLocked(fontA.get())); + EXPECT_EQ(getHbFontLocked(fontB.get()), getHbFontLocked(fontB.get())); + EXPECT_EQ(getHbFontLocked(fontC.get()), getHbFontLocked(fontC.get())); // Different object must be returned if the passed minikinFont has different ID. - EXPECT_NE(getHbFontLocked(&fontA), getHbFontLocked(&fontB)); - EXPECT_NE(getHbFontLocked(&fontA), getHbFontLocked(&fontC)); + EXPECT_NE(getHbFontLocked(fontA.get()), getHbFontLocked(fontB.get())); + EXPECT_NE(getHbFontLocked(fontA.get()), getHbFontLocked(fontC.get())); } TEST_F(HbFontCacheTest, purgeCacheTest) { - android::AutoMutex _l(gMinikinLock); - MinikinFontForTest minikinFont(kTestFontDir "Regular.ttf"); + MinikinAutoUnref minikinFont( + MinikinFontForTest::createFromFile(kTestFontDir "Regular.ttf")); - hb_font_t* font = getHbFontLocked(&minikinFont); + android::AutoMutex _l(gMinikinLock); + hb_font_t* font = getHbFontLocked(minikinFont.get()); ASSERT_NE(nullptr, font); // Set user data to identify the font object. @@ -78,7 +83,7 @@ TEST_F(HbFontCacheTest, purgeCacheTest) { // By checking user data, confirm that the object after purge is different from previously // created one. Do not compare the returned pointer here since memory allocator may assign // same region for new object. - font = getHbFontLocked(&minikinFont); + font = getHbFontLocked(minikinFont.get()); EXPECT_EQ(nullptr, hb_font_get_user_data(font, &key)); } diff --git a/engine/src/flutter/tests/util/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp index 76d3ea20a24..eaf3610df26 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.cpp +++ b/engine/src/flutter/tests/util/FontTestUtils.cpp @@ -68,14 +68,16 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { LOG_ALWAYS_FATAL_IF(access(fontPath.c_str(), R_OK) != 0, "%s is not found", fontPath.c_str()); - family->addFont(new MinikinFontForTest(fontPath), FontStyle(weight, italic)); + MinikinAutoUnref + minikinFont(MinikinFontForTest::createFromFile(fontPath)); + + family->addFont(minikinFont.get(), FontStyle(weight, italic)); } families.push_back(family); } xmlFreeDoc(doc); FontCollection* collection = new FontCollection(families); - collection->Ref(); for (size_t i = 0; i < families.size(); ++i) { families[i]->Unref(); } diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.cpp b/engine/src/flutter/tests/util/MinikinFontForTest.cpp index ae8ef72bcfa..93e3e66d2df 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/util/MinikinFontForTest.cpp @@ -24,17 +24,23 @@ namespace minikin { -MinikinFontForTest::MinikinFontForTest(const std::string& font_path) : - MinikinFontForTest(font_path, SkTypeface::CreateFromFile(font_path.c_str())) { +// static +MinikinFontForTest* MinikinFontForTest::createFromFile(const std::string& font_path) { + SkTypeface* typeface = SkTypeface::CreateFromFile(font_path.c_str()); + MinikinFontForTest* font = new MinikinFontForTest(font_path, typeface); + SkSafeUnref(typeface); + return font; } MinikinFontForTest::MinikinFontForTest(const std::string& font_path, SkTypeface* typeface) : - MinikinFont(typeface->uniqueID()), - mTypeface(typeface), - mFontPath(font_path) { + MinikinFont(typeface->uniqueID()), + mTypeface(typeface), + mFontPath(font_path) { + SkSafeRef(mTypeface); } MinikinFontForTest::~MinikinFontForTest() { + SkSafeUnref(mTypeface); } float MinikinFontForTest::GetHorizontalAdvance(uint32_t /* glyph_id */, diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.h b/engine/src/flutter/tests/util/MinikinFontForTest.h index 56f63adaff8..bfd8421525b 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.h +++ b/engine/src/flutter/tests/util/MinikinFontForTest.h @@ -25,10 +25,13 @@ namespace minikin { class MinikinFontForTest : public MinikinFont { public: - explicit MinikinFontForTest(const std::string& font_path); MinikinFontForTest(const std::string& font_path, SkTypeface* typeface); ~MinikinFontForTest(); + // Helper function for creating MinikinFontForTest instance from font file. + // Calller need to unref returned object. + static MinikinFontForTest* createFromFile(const std::string& font_path); + // MinikinFont overrides. float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const; void GetBounds(MinikinRect* bounds, uint32_t glyph_id, @@ -37,6 +40,10 @@ public: const std::string& fontPath() const { return mFontPath; } private: + MinikinFontForTest() = delete; + MinikinFontForTest(const MinikinFontForTest&) = delete; + MinikinFontForTest& operator=(MinikinFontForTest&) = delete; + SkTypeface *mTypeface; const std::string mFontPath; }; From df66baa6fa6461e7acd1e3521c6a0a66a0f6d6a1 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 14 Jun 2016 15:43:57 +0900 Subject: [PATCH 187/364] Add more native perf tests to minikin. This CL introduces performance tests for following three modules: - Hyphenator - WordBreaker - GraphemeBreak During using UnicodeUtils, need to decouple it from gtest since perftest doesn't have gtest dependencies. Bug:29142734 Change-Id: I700c662fa7d0a52f19d8e93150ad1a85dc28769f --- engine/src/flutter/tests/perftests/Android.mk | 9 +++ .../flutter/tests/perftests/GraphemeBreak.cpp | 79 +++++++++++++++++++ .../flutter/tests/perftests/Hyphenator.cpp | 55 +++++++++++++ .../flutter/tests/perftests/WordBreaker.cpp | 39 +++++++++ engine/src/flutter/tests/perftests/main.cpp | 30 ++++++- engine/src/flutter/tests/unittest/Android.mk | 1 + .../tests/unittest/UnicodeUtilsTest.cpp | 37 +++++++++ engine/src/flutter/tests/util/FileUtils.cpp | 35 ++++++++ engine/src/flutter/tests/util/FileUtils.h | 18 +++++ .../src/flutter/tests/util/UnicodeUtils.cpp | 64 ++++++++------- engine/src/flutter/tests/util/UnicodeUtils.h | 3 + 11 files changed, 341 insertions(+), 29 deletions(-) create mode 100644 engine/src/flutter/tests/perftests/GraphemeBreak.cpp create mode 100644 engine/src/flutter/tests/perftests/Hyphenator.cpp create mode 100644 engine/src/flutter/tests/perftests/WordBreaker.cpp create mode 100644 engine/src/flutter/tests/unittest/UnicodeUtilsTest.cpp create mode 100644 engine/src/flutter/tests/util/FileUtils.cpp create mode 100644 engine/src/flutter/tests/util/FileUtils.h diff --git a/engine/src/flutter/tests/perftests/Android.mk b/engine/src/flutter/tests/perftests/Android.mk index 3b49036cee1..d3ed600b6ee 100644 --- a/engine/src/flutter/tests/perftests/Android.mk +++ b/engine/src/flutter/tests/perftests/Android.mk @@ -17,7 +17,12 @@ LOCAL_PATH := $(call my-dir) perftest_src_files := \ + ../util/FileUtils.cpp \ + ../util/UnicodeUtils.cpp \ FontLanguage.cpp \ + GraphemeBreak.cpp \ + Hyphenator.cpp \ + WordBreaker.cpp \ main.cpp include $(CLEAR_VARS) @@ -25,7 +30,11 @@ LOCAL_MODULE := minikin_perftests LOCAL_CPPFLAGS := -Werror -Wall -Wextra LOCAL_SRC_FILES := $(perftest_src_files) LOCAL_STATIC_LIBRARIES := libminikin +LOCAL_SHARED_LIBRARIES := \ + libicuuc \ + liblog LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/../ \ $(LOCAL_PATH)/../../libs/minikin \ external/harfbuzz_ng/src include $(BUILD_NATIVE_BENCHMARK) diff --git a/engine/src/flutter/tests/perftests/GraphemeBreak.cpp b/engine/src/flutter/tests/perftests/GraphemeBreak.cpp new file mode 100644 index 00000000000..4db8f75d3da --- /dev/null +++ b/engine/src/flutter/tests/perftests/GraphemeBreak.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2016 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 + +#include + +#include "minikin/GraphemeBreak.h" +#include "util/UnicodeUtils.h" + +namespace minikin { + +const char* ASCII_TEST_STR = "'L' 'o' 'r' 'e' 'm' ' ' 'i' 'p' 's' 'u' 'm' '.'"; +// U+261D: WHITE UP POINTING INDEX +// U+1F3FD: EMOJI MODIFIER FITZPATRICK TYPE-4 +const char* EMOJI_TEST_STR = "U+261D U+1F3FD U+261D U+1F3FD U+261D U+1F3FD U+261D U+1F3FD"; +// U+1F1FA: REGIONAL INDICATOR SYMBOL LETTER U +// U+1F1F8: REGIONAL INDICATOR SYMBOL LETTER S +const char* FLAGS_TEST_STR = "U+1F1FA U+1F1F8 U+1F1FA U+1F1F8 U+1F1FA U+1F1F8"; + +// TODO: Migrate BENCHMARK_CAPTURE for parameterizing. +static void BM_GraphemeBreak_Ascii(benchmark::State& state) { + size_t result_size; + uint16_t buffer[12]; + ParseUnicode(buffer, 12, ASCII_TEST_STR, &result_size, nullptr); + LOG_ALWAYS_FATAL_IF(result_size != 12); + const size_t testIndex = state.range_x(); + while (state.KeepRunning()) { + GraphemeBreak::isGraphemeBreak(buffer, 0, result_size, testIndex); + } +} +BENCHMARK(BM_GraphemeBreak_Ascii) + ->Arg(0) // Begining of the text. + ->Arg(1) // Middle of the text. + ->Arg(12); // End of the text. + +static void BM_GraphemeBreak_Emoji(benchmark::State& state) { + size_t result_size; + uint16_t buffer[12]; + ParseUnicode(buffer, 12, EMOJI_TEST_STR, &result_size, nullptr); + LOG_ALWAYS_FATAL_IF(result_size != 12); + const size_t testIndex = state.range_x(); + while (state.KeepRunning()) { + GraphemeBreak::isGraphemeBreak(buffer, 0, result_size, testIndex); + } +} +BENCHMARK(BM_GraphemeBreak_Emoji) + ->Arg(1) // Middle of emoji modifier sequence. + ->Arg(2) // Middle of the surrogate pairs. + ->Arg(3); // After emoji modifier sequence. Here is boundary of grapheme cluster. + +static void BM_GraphemeBreak_Emoji_Flags(benchmark::State& state) { + size_t result_size; + uint16_t buffer[12]; + ParseUnicode(buffer, 12, FLAGS_TEST_STR, &result_size, nullptr); + LOG_ALWAYS_FATAL_IF(result_size != 12); + const size_t testIndex = state.range_x(); + while (state.KeepRunning()) { + GraphemeBreak::isGraphemeBreak(buffer, 0, result_size, testIndex); + } +} +BENCHMARK(BM_GraphemeBreak_Emoji_Flags) + ->Arg(2) // Middle of flag sequence. + ->Arg(4) // After flag sequence. Here is boundary of grapheme cluster. + ->Arg(10); // Middle of 3rd flag sequence. + +} // namespace minikin diff --git a/engine/src/flutter/tests/perftests/Hyphenator.cpp b/engine/src/flutter/tests/perftests/Hyphenator.cpp new file mode 100644 index 00000000000..692e06d2bf0 --- /dev/null +++ b/engine/src/flutter/tests/perftests/Hyphenator.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2016 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 + +#include +#include +#include + +namespace minikin { + +const char* enUsHyph = "/system/usr/hyphen-data/hyph-en-us.hyb"; + +static void BM_Hyphenator_short_word(benchmark::State& state) { + Hyphenator* hyphenator = Hyphenator::loadBinary(readWholeFile(enUsHyph).data()); + std::vector word = utf8ToUtf16("hyphen"); + std::vector result; + while (state.KeepRunning()) { + hyphenator->hyphenate(&result, word.data(), word.size()); + } + Hyphenator::loadBinary(nullptr); +} + +// TODO: Use BENCHMARK_CAPTURE for parametrise. +BENCHMARK(BM_Hyphenator_short_word); + +static void BM_Hyphenator_long_word(benchmark::State& state) { + Hyphenator* hyphenator = Hyphenator::loadBinary(readWholeFile(enUsHyph).data()); + std::vector word = utf8ToUtf16( + "Pneumonoultramicroscopicsilicovolcanoconiosis"); + std::vector result; + while (state.KeepRunning()) { + hyphenator->hyphenate(&result, word.data(), word.size()); + } + Hyphenator::loadBinary(nullptr); +} + +// TODO: Use BENCHMARK_CAPTURE for parametrise. +BENCHMARK(BM_Hyphenator_long_word); + +// TODO: Add more tests for other languages. + +} // namespace minikin diff --git a/engine/src/flutter/tests/perftests/WordBreaker.cpp b/engine/src/flutter/tests/perftests/WordBreaker.cpp new file mode 100644 index 00000000000..6758cf97e58 --- /dev/null +++ b/engine/src/flutter/tests/perftests/WordBreaker.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2016 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 + +#include "minikin/WordBreaker.h" +#include "util/UnicodeUtils.h" + +namespace minikin { + +static void BM_WordBreaker_English(benchmark::State& state) { + const char* kLoremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do " + "eiusmod tempor incididunt ut labore et dolore magna aliqua."; + + WordBreaker wb; + wb.setLocale(icu::Locale::getEnglish()); + std::vector text = utf8ToUtf16(kLoremIpsum); + while (state.KeepRunning()) { + wb.setText(text.data(), text.size()); + while (wb.next() != -1) {} + } +} +BENCHMARK(BM_WordBreaker_English); + +// TODO: Add more tests for other languages. + +} // namespace minikin diff --git a/engine/src/flutter/tests/perftests/main.cpp b/engine/src/flutter/tests/perftests/main.cpp index e39c7f88387..e6f9d14cda5 100644 --- a/engine/src/flutter/tests/perftests/main.cpp +++ b/engine/src/flutter/tests/perftests/main.cpp @@ -15,4 +15,32 @@ */ #include -BENCHMARK_MAIN(); +#include + +#include +#include + +#include +#include +#include + +int main(int argc, char** argv) { + const char* fn = "/system/usr/icu/" U_ICUDATA_NAME ".dat"; + int fd = open(fn, O_RDONLY); + LOG_ALWAYS_FATAL_IF(fd == -1); + struct stat st; + LOG_ALWAYS_FATAL_IF(fstat(fd, &st) != 0); + void* data = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0); + + UErrorCode errorCode = U_ZERO_ERROR; + udata_setCommonData(data, &errorCode); + LOG_ALWAYS_FATAL_IF(U_FAILURE(errorCode)); + u_init(&errorCode); + LOG_ALWAYS_FATAL_IF(U_FAILURE(errorCode)); + + benchmark::Initialize(&argc, argv); + benchmark::RunSpecifiedBenchmarks(); + + u_cleanup(); + return 0; +} diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index 885127199dc..b43e3c85703 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -81,6 +81,7 @@ LOCAL_SRC_FILES += \ MinikinInternalTest.cpp \ GraphemeBreakTests.cpp \ LayoutUtilsTest.cpp \ + UnicodeUtilsTest.cpp \ WordBreakerTests.cpp LOCAL_C_INCLUDES := \ diff --git a/engine/src/flutter/tests/unittest/UnicodeUtilsTest.cpp b/engine/src/flutter/tests/unittest/UnicodeUtilsTest.cpp new file mode 100644 index 00000000000..99327235c59 --- /dev/null +++ b/engine/src/flutter/tests/unittest/UnicodeUtilsTest.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2016 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 + +#include "UnicodeUtils.h" + +namespace minikin { + +TEST(UnicodeUtils, parse) { + const size_t BUF_SIZE = 256; + uint16_t buf[BUF_SIZE]; + size_t offset; + size_t size; + ParseUnicode(buf, BUF_SIZE, "U+000D U+1F431 | 'a'", &size, &offset); + EXPECT_EQ(size, 4u); + EXPECT_EQ(offset, 3u); + EXPECT_EQ(buf[0], 0x000D); + EXPECT_EQ(buf[1], 0xD83D); + EXPECT_EQ(buf[2], 0xDC31); + EXPECT_EQ(buf[3], 'a'); +} + +} // namespace minikin diff --git a/engine/src/flutter/tests/util/FileUtils.cpp b/engine/src/flutter/tests/util/FileUtils.cpp new file mode 100644 index 00000000000..dfe15225dd8 --- /dev/null +++ b/engine/src/flutter/tests/util/FileUtils.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 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 + +#include +#include + +#include +#include + +std::vector readWholeFile(const std::string& filePath) { + FILE* fp = fopen(filePath.c_str(), "r"); + LOG_ALWAYS_FATAL_IF(fp == nullptr); + struct stat st; + LOG_ALWAYS_FATAL_IF(fstat(fileno(fp), &st) != 0); + + std::vector result(st.st_size); + LOG_ALWAYS_FATAL_IF(fread(result.data(), 1, st.st_size, fp) != st.st_size); + fclose(fp); + return result; +} diff --git a/engine/src/flutter/tests/util/FileUtils.h b/engine/src/flutter/tests/util/FileUtils.h new file mode 100644 index 00000000000..1e66d1b701a --- /dev/null +++ b/engine/src/flutter/tests/util/FileUtils.h @@ -0,0 +1,18 @@ +/* + * Copyright (C) 2015 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. + */ + +std::vector readWholeFile(const std::string& filePath); + diff --git a/engine/src/flutter/tests/util/UnicodeUtils.cpp b/engine/src/flutter/tests/util/UnicodeUtils.cpp index bb652ff63dc..2f811daec25 100644 --- a/engine/src/flutter/tests/util/UnicodeUtils.cpp +++ b/engine/src/flutter/tests/util/UnicodeUtils.cpp @@ -14,9 +14,12 @@ * limitations under the License. */ -#include #include +#include #include +#include +#include +#include namespace minikin { @@ -32,33 +35,35 @@ void ParseUnicode(uint16_t* buf, size_t buf_size, const char* src, size_t* resul switch (src[input_ix]) { case '\'': // single ASCII char - ASSERT_LT(src[input_ix], 0x80); + LOG_ALWAYS_FATAL_IF(static_cast(src[input_ix]) >= 0x80); input_ix++; - ASSERT_NE(src[input_ix], 0); - ASSERT_LT(output_ix, buf_size); + LOG_ALWAYS_FATAL_IF(src[input_ix] == 0); + LOG_ALWAYS_FATAL_IF(output_ix >= buf_size); buf[output_ix++] = (uint16_t)src[input_ix++]; - ASSERT_EQ(src[input_ix], '\''); + LOG_ALWAYS_FATAL_IF(src[input_ix] != '\''); input_ix++; break; case 'u': case 'U': { // Unicode codepoint in hex syntax input_ix++; - ASSERT_EQ(src[input_ix], '+'); + LOG_ALWAYS_FATAL_IF(src[input_ix] != '+'); input_ix++; char* endptr = (char*)src + input_ix; unsigned long int codepoint = strtoul(src + input_ix, &endptr, 16); size_t num_hex_digits = endptr - (src + input_ix); - ASSERT_GE(num_hex_digits, 4u); // also triggers on invalid number syntax, digits = 0 - ASSERT_LE(num_hex_digits, 6u); - ASSERT_LE(codepoint, 0x10FFFFu); + + // also triggers on invalid number syntax, digits = 0 + LOG_ALWAYS_FATAL_IF(num_hex_digits < 4u); + LOG_ALWAYS_FATAL_IF(num_hex_digits > 6u); + LOG_ALWAYS_FATAL_IF(codepoint > 0x10FFFFu); input_ix += num_hex_digits; if (U16_LENGTH(codepoint) == 1) { - ASSERT_LE(output_ix + 1, buf_size); + LOG_ALWAYS_FATAL_IF(output_ix + 1 > buf_size); buf[output_ix++] = codepoint; } else { // UTF-16 encoding - ASSERT_LE(output_ix + 2, buf_size); + LOG_ALWAYS_FATAL_IF(output_ix + 2 > buf_size); buf[output_ix++] = U16_LEAD(codepoint); buf[output_ix++] = U16_TRAIL(codepoint); } @@ -68,33 +73,36 @@ void ParseUnicode(uint16_t* buf, size_t buf_size, const char* src, size_t* resul input_ix++; break; case '|': - ASSERT_FALSE(seen_offset); - ASSERT_NE(offset, nullptr); + LOG_ALWAYS_FATAL_IF(seen_offset); + LOG_ALWAYS_FATAL_IF(offset == nullptr); *offset = output_ix; seen_offset = true; input_ix++; break; default: - FAIL(); // unexpected character + LOG_ALWAYS_FATAL("Unexpected Character"); } } - ASSERT_NE(result_size, nullptr); + LOG_ALWAYS_FATAL_IF(result_size == nullptr); *result_size = output_ix; - ASSERT_TRUE(seen_offset || offset == nullptr); + LOG_ALWAYS_FATAL_IF(!seen_offset && offset != nullptr); } -TEST(UnicodeUtils, parse) { - const size_t BUF_SIZE = 256; - uint16_t buf[BUF_SIZE]; - size_t offset; - size_t size; - ParseUnicode(buf, BUF_SIZE, "U+000D U+1F431 | 'a'", &size, &offset); - EXPECT_EQ(size, 4u); - EXPECT_EQ(offset, 3u); - EXPECT_EQ(buf[0], 0x000D); - EXPECT_EQ(buf[1], 0xD83D); - EXPECT_EQ(buf[2], 0xDC31); - EXPECT_EQ(buf[3], 'a'); +std::vector utf8ToUtf16(const std::string& text) { + std::vector result; + int32_t i = 0; + const int32_t textLength = static_cast(text.size()); + uint32_t c = 0; + while (i < textLength) { + U8_NEXT(text.c_str(), i, textLength, c); + if (U16_LENGTH(c) == 1) { + result.push_back(c); + } else { + result.push_back(U16_LEAD(c)); + result.push_back(U16_TRAIL(c)); + } + } + return result; } } // namespace minikin diff --git a/engine/src/flutter/tests/util/UnicodeUtils.h b/engine/src/flutter/tests/util/UnicodeUtils.h index 64b90c91b19..571be7a31ef 100644 --- a/engine/src/flutter/tests/util/UnicodeUtils.h +++ b/engine/src/flutter/tests/util/UnicodeUtils.h @@ -19,4 +19,7 @@ namespace minikin { void ParseUnicode(uint16_t* buf, size_t buf_size, const char* src, size_t* result_size, size_t* offset); +// Converts UTF-8 to UTF-16. +std::vector utf8ToUtf16(const std::string& text); + } // namespace minikin From a89c08ae496e402b46a71e2f86941c1f3968b2a5 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 16 Jun 2016 16:58:14 +0900 Subject: [PATCH 188/364] Introduce FontCollection perftest This CL introduces performance tests for FontCollection. To support TTC file in /system/fonts, this CL also extends FontTestUtils Bug:29142734 Change-Id: I9d8ad24ca55f61031b85623ab7c26234239e4f41 --- engine/src/flutter/tests/perftests/Android.mk | 17 +++- .../tests/perftests/FontCollection.cpp | 90 +++++++++++++++++++ .../src/flutter/tests/util/FontTestUtils.cpp | 33 ++++--- .../flutter/tests/util/MinikinFontForTest.cpp | 9 ++ .../flutter/tests/util/MinikinFontForTest.h | 1 + 5 files changed, 137 insertions(+), 13 deletions(-) create mode 100644 engine/src/flutter/tests/perftests/FontCollection.cpp diff --git a/engine/src/flutter/tests/perftests/Android.mk b/engine/src/flutter/tests/perftests/Android.mk index d3ed600b6ee..de5769c7436 100644 --- a/engine/src/flutter/tests/perftests/Android.mk +++ b/engine/src/flutter/tests/perftests/Android.mk @@ -18,7 +18,10 @@ LOCAL_PATH := $(call my-dir) perftest_src_files := \ ../util/FileUtils.cpp \ + ../util/FontTestUtils.cpp \ + ../util/MinikinFontForTest.cpp \ ../util/UnicodeUtils.cpp \ + FontCollection.cpp \ FontLanguage.cpp \ GraphemeBreak.cpp \ Hyphenator.cpp \ @@ -29,12 +32,20 @@ include $(CLEAR_VARS) LOCAL_MODULE := minikin_perftests LOCAL_CPPFLAGS := -Werror -Wall -Wextra LOCAL_SRC_FILES := $(perftest_src_files) -LOCAL_STATIC_LIBRARIES := libminikin +LOCAL_STATIC_LIBRARIES := \ + libminikin \ + libxml2 + LOCAL_SHARED_LIBRARIES := \ + libharfbuzz_ng \ libicuuc \ - liblog + liblog \ + libskia + LOCAL_C_INCLUDES := \ $(LOCAL_PATH)/../ \ $(LOCAL_PATH)/../../libs/minikin \ - external/harfbuzz_ng/src + external/harfbuzz_ng/src \ + external/libxml2/include + include $(BUILD_NATIVE_BENCHMARK) diff --git a/engine/src/flutter/tests/perftests/FontCollection.cpp b/engine/src/flutter/tests/perftests/FontCollection.cpp new file mode 100644 index 00000000000..490f5d85fea --- /dev/null +++ b/engine/src/flutter/tests/perftests/FontCollection.cpp @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2016 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 + +#include +#include +#include +#include +#include + +namespace minikin { + +const char* SYSTEM_FONT_PATH = "/system/fonts/"; +const char* SYSTEM_FONT_XML = "/system/etc/fonts.xml"; + +static void BM_FontCollection_hasVariationSelector(benchmark::State& state) { + MinikinAutoUnref collection( + getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); + + uint32_t baseCp = state.range_x(); + uint32_t vsCp = state.range_y(); + + char titleBuffer[64]; + snprintf(titleBuffer, 64, "hasVariationSelector U+%04X,U+%04X", baseCp, vsCp); + state.SetLabel(titleBuffer); + + while (state.KeepRunning()) { + collection->hasVariationSelector(baseCp, vsCp); + } +} + +// TODO: Rewrite with BENCHMARK_CAPTURE for better test name. +BENCHMARK(BM_FontCollection_hasVariationSelector) + ->ArgPair(0x2708, 0xFE0F) + ->ArgPair(0x2708, 0xFE0E) + ->ArgPair(0x3402, 0xE0100); + +struct ItemizeTestCases { + std::string itemizeText; + std::string languageTag; + std::string labelText; +} ITEMIZE_TEST_CASES[] = { + { "'A' 'n' 'd' 'r' 'o' 'i' 'd'", "en", "English" }, + { "U+4E16", "zh-Hans", "CJK Ideograph" }, + { "U+4E16", "zh-Hans,zh-Hant,ja,en,es,pt,fr,de", "CJK Ideograph with many language fallback" }, + { "U+3402 U+E0100", "ja", "CJK Ideograph with variation selector" }, + { "'A' 'n' U+0E1A U+0E31 U+0645 U+062D U+0648", "en", "Mixture of English, Thai and Arabic" }, + { "U+2708 U+FE0E", "en", "Emoji with variation selector" }, + { "U+0031 U+FE0F U+20E3", "en", "KEYCAP" }, +}; + +static void BM_FontCollection_itemize(benchmark::State& state) { + MinikinAutoUnref collection( + getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); + + size_t testIndex = state.range_x(); + state.SetLabel("Itemize: " + ITEMIZE_TEST_CASES[testIndex].labelText); + + uint16_t buffer[64]; + size_t utf16_length = 0; + ParseUnicode( + buffer, 64, ITEMIZE_TEST_CASES[testIndex].itemizeText.c_str(), &utf16_length, nullptr); + std::vector result; + FontStyle style(FontStyle::registerLanguageList(ITEMIZE_TEST_CASES[testIndex].languageTag)); + + android::AutoMutex _l(gMinikinLock); + while (state.KeepRunning()) { + result.clear(); + collection->itemize(buffer, utf16_length, style, &result); + } +} + +// TODO: Rewrite with BENCHMARK_CAPTURE once it is available in Android. +BENCHMARK(BM_FontCollection_itemize) + ->Arg(0)->Arg(1)->Arg(2)->Arg(3)->Arg(4)->Arg(5)->Arg(6); + +} // namespace minikin diff --git a/engine/src/flutter/tests/util/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp index eaf3610df26..246c87231af 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.cpp +++ b/engine/src/flutter/tests/util/FontTestUtils.cpp @@ -47,10 +47,14 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { } xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); - uint32_t langId = FontStyle::registerLanguageList( - std::string((const char*)lang, xmlStrlen(lang))); - - FontFamily* family = new FontFamily(langId, variant); + FontFamily* family; + if (lang == nullptr) { + family = new FontFamily(variant); + } else { + uint32_t langId = FontStyle::registerLanguageList( + std::string((const char*)lang, xmlStrlen(lang))); + family = new FontFamily(langId, variant); + } for (xmlNode* fontNode = familyNode->children; fontNode; fontNode = fontNode->next) { if (xmlStrcmp(fontNode->name, (const xmlChar*)"font") != 0) { @@ -60,18 +64,27 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { int weight = atoi((const char*)(xmlGetProp(fontNode, (const xmlChar*)"weight"))) / 100; bool italic = xmlStrcmp( xmlGetProp(fontNode, (const xmlChar*)"style"), (const xmlChar*)"italic") == 0; + xmlChar* index = xmlGetProp(familyNode, (const xmlChar*)"index"); xmlChar* fontFileName = xmlNodeListGetString(doc, fontNode->xmlChildrenNode, 1); std::string fontPath = fontDir + std::string((const char*)fontFileName); xmlFree(fontFileName); - LOG_ALWAYS_FATAL_IF(access(fontPath.c_str(), R_OK) != 0, - "%s is not found", fontPath.c_str()); + if (access(fontPath.c_str(), R_OK) != 0) { + ALOGW("%s is not found.", fontPath.c_str()); + continue; + } - MinikinAutoUnref - minikinFont(MinikinFontForTest::createFromFile(fontPath)); - - family->addFont(minikinFont.get(), FontStyle(weight, italic)); + if (index == nullptr) { + MinikinAutoUnref + minikinFont(MinikinFontForTest::createFromFile(fontPath)); + family->addFont(minikinFont.get(), FontStyle(weight, italic)); + } else { + MinikinAutoUnref + minikinFont(MinikinFontForTest::createFromFileWithIndex(fontPath, + atoi((const char*)index))); + family->addFont(minikinFont.get(), FontStyle(weight, italic)); + } } families.push_back(family); } diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.cpp b/engine/src/flutter/tests/util/MinikinFontForTest.cpp index 93e3e66d2df..392d5b2ea54 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/util/MinikinFontForTest.cpp @@ -32,6 +32,15 @@ MinikinFontForTest* MinikinFontForTest::createFromFile(const std::string& font_p return font; } +// static +MinikinFontForTest* MinikinFontForTest::createFromFileWithIndex(const std::string& font_path, + int index) { + SkTypeface* typeface = SkTypeface::CreateFromFile(font_path.c_str(), index); + MinikinFontForTest* font = new MinikinFontForTest(font_path, typeface); + SkSafeUnref(typeface); + return font; +} + MinikinFontForTest::MinikinFontForTest(const std::string& font_path, SkTypeface* typeface) : MinikinFont(typeface->uniqueID()), mTypeface(typeface), diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.h b/engine/src/flutter/tests/util/MinikinFontForTest.h index bfd8421525b..7b5322ca0b1 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.h +++ b/engine/src/flutter/tests/util/MinikinFontForTest.h @@ -31,6 +31,7 @@ public: // Helper function for creating MinikinFontForTest instance from font file. // Calller need to unref returned object. static MinikinFontForTest* createFromFile(const std::string& font_path); + static MinikinFontForTest* createFromFileWithIndex(const std::string& font_path, int index); // MinikinFont overrides. float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const; From cd8eea620534db54e34e2755c270b37c2248564b Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 28 Jun 2016 18:35:48 +0900 Subject: [PATCH 189/364] Fix build failure of minikin_perftest stat.st_size is off_t not size_t, so need to cast to size_t before compare it. Change-Id: I6b742746fbb9f254701fc91e515c293f93f912c5 --- engine/src/flutter/tests/util/FileUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/flutter/tests/util/FileUtils.cpp b/engine/src/flutter/tests/util/FileUtils.cpp index dfe15225dd8..68cc45cf4dc 100644 --- a/engine/src/flutter/tests/util/FileUtils.cpp +++ b/engine/src/flutter/tests/util/FileUtils.cpp @@ -29,7 +29,7 @@ std::vector readWholeFile(const std::string& filePath) { LOG_ALWAYS_FATAL_IF(fstat(fileno(fp), &st) != 0); std::vector result(st.st_size); - LOG_ALWAYS_FATAL_IF(fread(result.data(), 1, st.st_size, fp) != st.st_size); + LOG_ALWAYS_FATAL_IF(fread(result.data(), 1, st.st_size, fp) != static_cast(st.st_size)); fclose(fp); return result; } From dc6138ffeb80368d532f3b8f55b42f287e966170 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Fri, 8 Jul 2016 15:19:22 +0900 Subject: [PATCH 190/364] Add some gender balanced components in to the sticky whitelist. FEMALE SIGN(U+2640), MALE SIGN(U+2642), StAFF OF AESCULAPIUS(U+2695) will be used as the ZWJ sequenced in gender balanced emoji sequence. To be in the same run with ZWJ, mark these emoji as sticky chracters. With this fix, Female police officer sequence will be shown correctly regardless of VS16. Bug: 30026374 Change-Id: I503fc061eaa943d45208bb69e885151610c430ce --- .../flutter/libs/minikin/FontCollection.cpp | 5 +++- .../unittest/FontCollectionItemizeTest.cpp | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 90b67d25501..d1a1924ae01 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -336,11 +336,14 @@ const uint32_t ZWJ = 0x200c; const uint32_t ZWNJ = 0x200d; const uint32_t HYPHEN = 0x2010; const uint32_t NB_HYPHEN = 0x2011; +const uint32_t FEMALE_SIGN = 0x2640; +const uint32_t MALE_SIGN = 0x2642; +const uint32_t STAFF_OF_AESCULAPIUS = 0x2695; // Characters where we want to continue using existing font run instead of // recomputing the best match in the fallback list. static const uint32_t stickyWhitelist[] = { '!', ',', '-', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ, - HYPHEN, NB_HYPHEN }; + HYPHEN, NB_HYPHEN, FEMALE_SIGN, MALE_SIGN, STAFF_OF_AESCULAPIUS }; static bool isStickyWhitelisted(uint32_t c) { for (size_t i = 0; i < sizeof(stickyWhitelist) / sizeof(stickyWhitelist[0]); i++) { diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index b28820b1f84..367739683d1 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -1367,4 +1367,29 @@ TEST_F(FontCollectionItemizeTest, itemize_PrivateUseArea) { EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); } +TEST_F(FontCollectionItemizeTest, itemize_genderBalancedEmoji) { + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + std::vector runs; + + const FontStyle kDefaultFontStyle; + + itemize(collection.get(), "U+1F469 U+200D U+1F373", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+1F469 U+200D U+2695 U+FE0F", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+1F469 U+200D U+2695", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(4, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); +} + } // namespace minikin From 9c9fda459efec0be097b122c6c2f39fd3edbc7a5 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 30 Jun 2016 16:48:45 +0900 Subject: [PATCH 191/364] Treat U+2695, U+2640, U+2642 as emoji characters. Bug: 29885295 Change-Id: I1bf191a46d05e7099265d863bae0523c50817d0b --- .../flutter/libs/minikin/FontCollection.cpp | 41 ++++++++++--------- .../flutter/libs/minikin/MinikinInternal.cpp | 5 +++ .../tests/unittest/FontCollectionTest.cpp | 14 +++++++ .../tests/unittest/GraphemeBreakTests.cpp | 11 +++++ 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index d1a1924ae01..97c206881f1 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -40,7 +40,9 @@ static inline T max(T a, T b) { const uint32_t EMOJI_STYLE_VS = 0xFE0F; const uint32_t TEXT_STYLE_VS = 0xFE0E; -// See http://www.unicode.org/Public/9.0.0/ucd/StandardizedVariants-9.0.0d1.txt +// See http://www.unicode.org/Public/9.0.0/ucd/StandardizedVariants.txt +// U+2640, U+2642, U+2695 are now in emoji category but not listed in above file, so added them by +// manual. // Must be sorted. const uint32_t EMOJI_STYLE_VS_BASES[] = { 0x0023, 0x002A, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, @@ -48,24 +50,25 @@ const uint32_t EMOJI_STYLE_VS_BASES[] = { 0x21A9, 0x21AA, 0x231A, 0x231B, 0x2328, 0x23CF, 0x23ED, 0x23EE, 0x23EF, 0x23F1, 0x23F2, 0x23F8, 0x23F9, 0x23FA, 0x24C2, 0x25AA, 0x25AB, 0x25B6, 0x25C0, 0x25FB, 0x25FC, 0x25FD, 0x25FE, 0x2600, 0x2601, 0x2602, 0x2603, 0x2604, 0x260E, 0x2611, 0x2614, 0x2615, 0x2618, 0x261D, 0x2620, 0x2622, - 0x2623, 0x2626, 0x262A, 0x262E, 0x262F, 0x2638, 0x2639, 0x263A, 0x2648, 0x2649, 0x264A, 0x264B, - 0x264C, 0x264D, 0x264E, 0x264F, 0x2650, 0x2651, 0x2652, 0x2653, 0x2660, 0x2663, 0x2665, 0x2666, - 0x2668, 0x267B, 0x267F, 0x2692, 0x2693, 0x2694, 0x2696, 0x2697, 0x2699, 0x269B, 0x269C, 0x26A0, - 0x26A1, 0x26AA, 0x26AB, 0x26B0, 0x26B1, 0x26BD, 0x26BE, 0x26C4, 0x26C5, 0x26C8, 0x26CF, 0x26D1, - 0x26D3, 0x26D4, 0x26E9, 0x26EA, 0x26F0, 0x26F1, 0x26F2, 0x26F3, 0x26F4, 0x26F5, 0x26F7, 0x26F8, - 0x26F9, 0x26FA, 0x26FD, 0x2702, 0x2708, 0x2709, 0x270C, 0x270D, 0x270F, 0x2712, 0x2714, 0x2716, - 0x271D, 0x2721, 0x2733, 0x2734, 0x2744, 0x2747, 0x2757, 0x2763, 0x2764, 0x27A1, 0x2934, 0x2935, - 0x2B05, 0x2B06, 0x2B07, 0x2B1B, 0x2B1C, 0x2B50, 0x2B55, 0x3030, 0x303D, 0x3297, 0x3299, - 0x1F004, 0x1F170, 0x1F171, 0x1F17E, 0x1F17F, 0x1F202, 0x1F21A, 0x1F22F, 0x1F237, 0x1F321, - 0x1F324, 0x1F325, 0x1F326, 0x1F327, 0x1F328, 0x1F329, 0x1F32A, 0x1F32B, 0x1F32C, 0x1F336, - 0x1F37D, 0x1F396, 0x1F397, 0x1F399, 0x1F39A, 0x1F39B, 0x1F39E, 0x1F39F, 0x1F3CB, 0x1F3CC, - 0x1F3CD, 0x1F3CE, 0x1F3D4, 0x1F3D5, 0x1F3D6, 0x1F3D7, 0x1F3D8, 0x1F3D9, 0x1F3DA, 0x1F3DB, - 0x1F3DC, 0x1F3DD, 0x1F3DE, 0x1F3DF, 0x1F3F3, 0x1F3F5, 0x1F3F7, 0x1F43F, 0x1F441, 0x1F4FD, - 0x1F549, 0x1F54A, 0x1F56F, 0x1F570, 0x1F573, 0x1F574, 0x1F575, 0x1F576, 0x1F577, 0x1F578, - 0x1F579, 0x1F587, 0x1F58A, 0x1F58B, 0x1F58C, 0x1F58D, 0x1F590, 0x1F5A5, 0x1F5A8, 0x1F5B1, - 0x1F5B2, 0x1F5BC, 0x1F5C2, 0x1F5C3, 0x1F5C4, 0x1F5D1, 0x1F5D2, 0x1F5D3, 0x1F5DC, 0x1F5DD, - 0x1F5DE, 0x1F5E1, 0x1F5E3, 0x1F5E8, 0x1F5EF, 0x1F5F3, 0x1F5FA, 0x1F6CB, 0x1F6CD, 0x1F6CE, - 0x1F6CF, 0x1F6E0, 0x1F6E1, 0x1F6E2, 0x1F6E3, 0x1F6E4, 0x1F6E5, 0x1F6E9, 0x1F6F0, 0x1F6F3, + 0x2623, 0x2626, 0x262A, 0x262E, 0x262F, 0x2638, 0x2639, 0x263A, 0x2640, 0x2642, 0x2648, 0x2649, + 0x264A, 0x264B, 0x264C, 0x264D, 0x264E, 0x264F, 0x2650, 0x2651, 0x2652, 0x2653, 0x2660, 0x2663, + 0x2665, 0x2666, 0x2668, 0x267B, 0x267F, 0x2692, 0x2693, 0x2694, 0x2695, 0x2696, 0x2697, 0x2699, + 0x269B, 0x269C, 0x26A0, 0x26A1, 0x26AA, 0x26AB, 0x26B0, 0x26B1, 0x26BD, 0x26BE, 0x26C4, 0x26C5, + 0x26C8, 0x26CF, 0x26D1, 0x26D3, 0x26D4, 0x26E9, 0x26EA, 0x26F0, 0x26F1, 0x26F2, 0x26F3, 0x26F4, + 0x26F5, 0x26F7, 0x26F8, 0x26F9, 0x26FA, 0x26FD, 0x2702, 0x2708, 0x2709, 0x270C, 0x270D, 0x270F, + 0x2712, 0x2714, 0x2716, 0x271D, 0x2721, 0x2733, 0x2734, 0x2744, 0x2747, 0x2757, 0x2763, 0x2764, + 0x27A1, 0x2934, 0x2935, 0x2B05, 0x2B06, 0x2B07, 0x2B1B, 0x2B1C, 0x2B50, 0x2B55, 0x3030, 0x303D, + 0x3297, 0x3299, 0x1F004, 0x1F170, 0x1F171, 0x1F17E, 0x1F17F, 0x1F202, 0x1F21A, 0x1F22F, 0x1F237, + 0x1F321, 0x1F324, 0x1F325, 0x1F326, 0x1F327, 0x1F328, 0x1F329, 0x1F32A, 0x1F32B, 0x1F32C, + 0x1F336, 0x1F37D, 0x1F396, 0x1F397, 0x1F399, 0x1F39A, 0x1F39B, 0x1F39E, 0x1F39F, 0x1F3CB, + 0x1F3CC, 0x1F3CD, 0x1F3CE, 0x1F3D4, 0x1F3D5, 0x1F3D6, 0x1F3D7, 0x1F3D8, 0x1F3D9, 0x1F3DA, + 0x1F3DB, 0x1F3DC, 0x1F3DD, 0x1F3DE, 0x1F3DF, 0x1F3F3, 0x1F3F5, 0x1F3F7, 0x1F43F, 0x1F441, + 0x1F4FD, 0x1F549, 0x1F54A, 0x1F56F, 0x1F570, 0x1F573, 0x1F574, 0x1F575, 0x1F576, 0x1F577, + 0x1F578, 0x1F579, 0x1F587, 0x1F58A, 0x1F58B, 0x1F58C, 0x1F58D, 0x1F590, 0x1F5A5, 0x1F5A8, + 0x1F5B1, 0x1F5B2, 0x1F5BC, 0x1F5C2, 0x1F5C3, 0x1F5C4, 0x1F5D1, 0x1F5D2, 0x1F5D3, 0x1F5DC, + 0x1F5DD, 0x1F5DE, 0x1F5E1, 0x1F5E3, 0x1F5E8, 0x1F5EF, 0x1F5F3, 0x1F5FA, 0x1F6CB, 0x1F6CD, + 0x1F6CE, 0x1F6CF, 0x1F6E0, 0x1F6E1, 0x1F6E2, 0x1F6E3, 0x1F6E4, 0x1F6E5, 0x1F6E9, 0x1F6F0, + 0x1F6F3, }; static bool isEmojiStyleVSBase(uint32_t cp) { diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index b1ca2df6690..dc15549b120 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -33,6 +33,11 @@ void assertMinikinLocked() { } bool isEmoji(uint32_t c) { + // U+2695 U+2640 U+2642 are not in emoji category in Unicode 9 but they are now emoji category. + // TODO: remove once emoji database is updated. + if (c == 0x2695 || c == 0x2640 || c == 0x2642) { + return true; + } const size_t length = sizeof(generated::EMOJI_LIST) / sizeof(generated::EMOJI_LIST[0]); return std::binary_search(generated::EMOJI_LIST, generated::EMOJI_LIST + length, c); } diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index 3f365be083a..ef2da66b2b3 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -105,6 +105,20 @@ TEST(FontCollectionTest, hasVariationSelectorTest_emoji) { // VS15/VS16 is only for emoji, should return false for not an emoji code point. EXPECT_FALSE(collection->hasVariationSelector(0x2229, 0xFE0E)); EXPECT_FALSE(collection->hasVariationSelector(0x2229, 0xFE0F)); + +} + +TEST(FontCollectionTest, newEmojiTest) { + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + + // U+2695, U+2640, U+2642 are not in emoji catrgory in Unicode 9 but they are now in emoji + // category. Should return true even if U+FE0E was appended. + // These three emojis are only avalilable in TextEmoji.ttf but U+2695 is excluded here since it + // is used in other tests. + EXPECT_TRUE(collection->hasVariationSelector(0x2640, 0xFE0E)); + EXPECT_FALSE(collection->hasVariationSelector(0x2640, 0xFE0F)); + EXPECT_TRUE(collection->hasVariationSelector(0x2642, 0xFE0E)); + EXPECT_FALSE(collection->hasVariationSelector(0x2642, 0xFE0F)); } } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp b/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp index 07ddf82ce68..d95fa31b1dc 100644 --- a/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp +++ b/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp @@ -179,6 +179,17 @@ TEST(GraphemeBreak, emojiModifiers) { // rat is not an emoji modifer EXPECT_TRUE(IsBreak("U+1F466 | U+1F400")); // boy + rat + +} + +TEST(GraphemeBreak, genderBalancedEmoji) { + // U+1F469 is WOMAN, U+200D is ZWJ, U+1F4BC is BRIEFCASE. + EXPECT_FALSE(IsBreak("U+1F469 | U+200D U+1F4BC")); + EXPECT_FALSE(IsBreak("U+1F469 U+200D | U+1F4BC")); + + // U+2695 has now emoji property, so should be part of ZWJ sequence. + EXPECT_FALSE(IsBreak("U+1F469 | U+200D U+2695")); + EXPECT_FALSE(IsBreak("U+1F469 U+200D | U+2695")); } TEST(GraphemeBreak, offsets) { From 3d665c82d4b39e9ae44db22ca6569b3505ad3934 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Mon, 11 Jul 2016 17:28:44 +0900 Subject: [PATCH 192/364] Lookup glyph from color emoji font before and after ZWJ. Unicode recommends that the zwj sequences should be emoji presentation even if they don't have the proper U+FE0F. Thus always lookup the glyph for the code point before and after zwj as if they have a U+FE0F variation selector. Bug: 30056627 Change-Id: I03958a92337eaba4a8dd9c5be824b2665aa4a103 --- .../flutter/libs/minikin/FontCollection.cpp | 18 +++++++++++------- .../unittest/FontCollectionItemizeTest.cpp | 12 +++++++++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 97c206881f1..687c1302688 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -335,18 +335,15 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, } const uint32_t NBSP = 0xa0; -const uint32_t ZWJ = 0x200c; -const uint32_t ZWNJ = 0x200d; +const uint32_t ZWJ = 0x200d; +const uint32_t ZWNJ = 0x200c; const uint32_t HYPHEN = 0x2010; const uint32_t NB_HYPHEN = 0x2011; -const uint32_t FEMALE_SIGN = 0x2640; -const uint32_t MALE_SIGN = 0x2642; -const uint32_t STAFF_OF_AESCULAPIUS = 0x2695; // Characters where we want to continue using existing font run instead of // recomputing the best match in the fallback list. static const uint32_t stickyWhitelist[] = { '!', ',', '-', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ, - HYPHEN, NB_HYPHEN, FEMALE_SIGN, MALE_SIGN, STAFF_OF_AESCULAPIUS }; + HYPHEN, NB_HYPHEN }; static bool isStickyWhitelisted(uint32_t c) { for (size_t i = 0; i < sizeof(stickyWhitelist) / sizeof(stickyWhitelist[0]); i++) { @@ -432,8 +429,15 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } if (!shouldContinueRun) { - FontFamily* family = getFamilyForChar(ch, isVariationSelector(nextCh) ? nextCh : 0, + FontFamily* family; + if ((prevCh == ZWJ || nextCh == ZWJ) && isEmoji(ch)) { + // Treat emoji before and after ZWJ as emoji presentation. + family = getFamilyForChar(ch, EMOJI_STYLE_VS, langListId, variant); + } else { + family = getFamilyForChar(ch, isVariationSelector(nextCh) ? nextCh : 0, langListId, variant); + } + if (utf16Pos == 0 || family != lastFamily) { size_t start = utf16Pos; // Workaround for combining marks and emoji modifiers until we implement diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 367739683d1..84415d92e61 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -1217,7 +1217,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { EXPECT_EQ(2, runs[0].end); EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); - // U+26FA U+FE0E is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F + // U+26FA U+FE0E is specified but ColorTextMixedEmojiFont has a variation sequence U+26FA U+FE0F // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. itemize(collection.get(), "U+26FA U+FE0E", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); @@ -1299,9 +1299,9 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { EXPECT_EQ(2, runs[0].end); EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); - // U+26F9 U+FE0F is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F + // U+26F8 U+FE0F is specified but ColorTextMixedEmojiFont has a variation sequence U+26F8 U+FE0F // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. - itemize(collection.get(), "U+26F9 U+FE0F", kDefaultFontStyle, &runs); + itemize(collection.get(), "U+26F8 U+FE0F", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1390,6 +1390,12 @@ TEST_F(FontCollectionItemizeTest, itemize_genderBalancedEmoji) { EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+26F9 U+200D U+2695", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(3, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); } } // namespace minikin From 2fd057eb7048f3739f3135b2cf108ef5aca42a31 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Fri, 8 Jul 2016 15:19:22 +0900 Subject: [PATCH 193/364] Add some gender balanced components in to the sticky whitelist. FEMALE SIGN(U+2640), MALE SIGN(U+2642), StAFF OF AESCULAPIUS(U+2695) will be used as the ZWJ sequenced in gender balanced emoji sequence. To be in the same run with ZWJ, mark these emoji as sticky chracters. With this fix, Female police officer sequence will be shown correctly regardless of VS16. Bug: 30026374 Change-Id: I503fc061eaa943d45208bb69e885151610c430ce --- .../flutter/libs/minikin/FontCollection.cpp | 5 +++- .../tests/FontCollectionItemizeTest.cpp | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index b1b0aaf95f7..78f102e17cf 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -336,11 +336,14 @@ const uint32_t ZWJ = 0x200c; const uint32_t ZWNJ = 0x200d; const uint32_t HYPHEN = 0x2010; const uint32_t NB_HYPHEN = 0x2011; +const uint32_t FEMALE_SIGN = 0x2640; +const uint32_t MALE_SIGN = 0x2642; +const uint32_t STAFF_OF_AESCULAPIUS = 0x2695; // Characters where we want to continue using existing font run instead of // recomputing the best match in the fallback list. static const uint32_t stickyWhitelist[] = { '!', ',', '-', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ, - HYPHEN, NB_HYPHEN }; + HYPHEN, NB_HYPHEN, FEMALE_SIGN, MALE_SIGN, STAFF_OF_AESCULAPIUS }; static bool isStickyWhitelisted(uint32_t c) { for (size_t i = 0; i < sizeof(stickyWhitelist) / sizeof(stickyWhitelist[0]); i++) { diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index 8ad9472490a..468b4a28fac 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -1372,3 +1372,28 @@ TEST_F(FontCollectionItemizeTest, itemize_PrivateUseArea) { EXPECT_EQ(4, runs[0].end); EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); } + +TEST_F(FontCollectionItemizeTest, itemize_genderBalancedEmoji) { + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + std::vector runs; + + const FontStyle kDefaultFontStyle; + + itemize(collection.get(), "U+1F469 U+200D U+1F373", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+1F469 U+200D U+2695 U+FE0F", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(5, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+1F469 U+200D U+2695", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(4, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); +} From c5d673d42309ef91429ba5f6356b1fae22b2d680 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 30 Jun 2016 16:48:45 +0900 Subject: [PATCH 194/364] Treat U+2695, U+2640, U+2642 as emoji characters. Bug: 29885295 Change-Id: I1bf191a46d05e7099265d863bae0523c50817d0b --- .../flutter/libs/minikin/FontCollection.cpp | 41 ++++++++++--------- .../flutter/libs/minikin/MinikinInternal.cpp | 5 +++ .../src/flutter/tests/FontCollectionTest.cpp | 14 +++++++ .../src/flutter/tests/GraphemeBreakTests.cpp | 11 +++++ 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 78f102e17cf..33418ab1b5d 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -40,7 +40,9 @@ static inline T max(T a, T b) { const uint32_t EMOJI_STYLE_VS = 0xFE0F; const uint32_t TEXT_STYLE_VS = 0xFE0E; -// See http://www.unicode.org/Public/9.0.0/ucd/StandardizedVariants-9.0.0d1.txt +// See http://www.unicode.org/Public/9.0.0/ucd/StandardizedVariants.txt +// U+2640, U+2642, U+2695 are now in emoji category but not listed in above file, so added them by +// manual. // Must be sorted. const uint32_t EMOJI_STYLE_VS_BASES[] = { 0x0023, 0x002A, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, @@ -48,24 +50,25 @@ const uint32_t EMOJI_STYLE_VS_BASES[] = { 0x21A9, 0x21AA, 0x231A, 0x231B, 0x2328, 0x23CF, 0x23ED, 0x23EE, 0x23EF, 0x23F1, 0x23F2, 0x23F8, 0x23F9, 0x23FA, 0x24C2, 0x25AA, 0x25AB, 0x25B6, 0x25C0, 0x25FB, 0x25FC, 0x25FD, 0x25FE, 0x2600, 0x2601, 0x2602, 0x2603, 0x2604, 0x260E, 0x2611, 0x2614, 0x2615, 0x2618, 0x261D, 0x2620, 0x2622, - 0x2623, 0x2626, 0x262A, 0x262E, 0x262F, 0x2638, 0x2639, 0x263A, 0x2648, 0x2649, 0x264A, 0x264B, - 0x264C, 0x264D, 0x264E, 0x264F, 0x2650, 0x2651, 0x2652, 0x2653, 0x2660, 0x2663, 0x2665, 0x2666, - 0x2668, 0x267B, 0x267F, 0x2692, 0x2693, 0x2694, 0x2696, 0x2697, 0x2699, 0x269B, 0x269C, 0x26A0, - 0x26A1, 0x26AA, 0x26AB, 0x26B0, 0x26B1, 0x26BD, 0x26BE, 0x26C4, 0x26C5, 0x26C8, 0x26CF, 0x26D1, - 0x26D3, 0x26D4, 0x26E9, 0x26EA, 0x26F0, 0x26F1, 0x26F2, 0x26F3, 0x26F4, 0x26F5, 0x26F7, 0x26F8, - 0x26F9, 0x26FA, 0x26FD, 0x2702, 0x2708, 0x2709, 0x270C, 0x270D, 0x270F, 0x2712, 0x2714, 0x2716, - 0x271D, 0x2721, 0x2733, 0x2734, 0x2744, 0x2747, 0x2757, 0x2763, 0x2764, 0x27A1, 0x2934, 0x2935, - 0x2B05, 0x2B06, 0x2B07, 0x2B1B, 0x2B1C, 0x2B50, 0x2B55, 0x3030, 0x303D, 0x3297, 0x3299, - 0x1F004, 0x1F170, 0x1F171, 0x1F17E, 0x1F17F, 0x1F202, 0x1F21A, 0x1F22F, 0x1F237, 0x1F321, - 0x1F324, 0x1F325, 0x1F326, 0x1F327, 0x1F328, 0x1F329, 0x1F32A, 0x1F32B, 0x1F32C, 0x1F336, - 0x1F37D, 0x1F396, 0x1F397, 0x1F399, 0x1F39A, 0x1F39B, 0x1F39E, 0x1F39F, 0x1F3CB, 0x1F3CC, - 0x1F3CD, 0x1F3CE, 0x1F3D4, 0x1F3D5, 0x1F3D6, 0x1F3D7, 0x1F3D8, 0x1F3D9, 0x1F3DA, 0x1F3DB, - 0x1F3DC, 0x1F3DD, 0x1F3DE, 0x1F3DF, 0x1F3F3, 0x1F3F5, 0x1F3F7, 0x1F43F, 0x1F441, 0x1F4FD, - 0x1F549, 0x1F54A, 0x1F56F, 0x1F570, 0x1F573, 0x1F574, 0x1F575, 0x1F576, 0x1F577, 0x1F578, - 0x1F579, 0x1F587, 0x1F58A, 0x1F58B, 0x1F58C, 0x1F58D, 0x1F590, 0x1F5A5, 0x1F5A8, 0x1F5B1, - 0x1F5B2, 0x1F5BC, 0x1F5C2, 0x1F5C3, 0x1F5C4, 0x1F5D1, 0x1F5D2, 0x1F5D3, 0x1F5DC, 0x1F5DD, - 0x1F5DE, 0x1F5E1, 0x1F5E3, 0x1F5E8, 0x1F5EF, 0x1F5F3, 0x1F5FA, 0x1F6CB, 0x1F6CD, 0x1F6CE, - 0x1F6CF, 0x1F6E0, 0x1F6E1, 0x1F6E2, 0x1F6E3, 0x1F6E4, 0x1F6E5, 0x1F6E9, 0x1F6F0, 0x1F6F3, + 0x2623, 0x2626, 0x262A, 0x262E, 0x262F, 0x2638, 0x2639, 0x263A, 0x2640, 0x2642, 0x2648, 0x2649, + 0x264A, 0x264B, 0x264C, 0x264D, 0x264E, 0x264F, 0x2650, 0x2651, 0x2652, 0x2653, 0x2660, 0x2663, + 0x2665, 0x2666, 0x2668, 0x267B, 0x267F, 0x2692, 0x2693, 0x2694, 0x2695, 0x2696, 0x2697, 0x2699, + 0x269B, 0x269C, 0x26A0, 0x26A1, 0x26AA, 0x26AB, 0x26B0, 0x26B1, 0x26BD, 0x26BE, 0x26C4, 0x26C5, + 0x26C8, 0x26CF, 0x26D1, 0x26D3, 0x26D4, 0x26E9, 0x26EA, 0x26F0, 0x26F1, 0x26F2, 0x26F3, 0x26F4, + 0x26F5, 0x26F7, 0x26F8, 0x26F9, 0x26FA, 0x26FD, 0x2702, 0x2708, 0x2709, 0x270C, 0x270D, 0x270F, + 0x2712, 0x2714, 0x2716, 0x271D, 0x2721, 0x2733, 0x2734, 0x2744, 0x2747, 0x2757, 0x2763, 0x2764, + 0x27A1, 0x2934, 0x2935, 0x2B05, 0x2B06, 0x2B07, 0x2B1B, 0x2B1C, 0x2B50, 0x2B55, 0x3030, 0x303D, + 0x3297, 0x3299, 0x1F004, 0x1F170, 0x1F171, 0x1F17E, 0x1F17F, 0x1F202, 0x1F21A, 0x1F22F, 0x1F237, + 0x1F321, 0x1F324, 0x1F325, 0x1F326, 0x1F327, 0x1F328, 0x1F329, 0x1F32A, 0x1F32B, 0x1F32C, + 0x1F336, 0x1F37D, 0x1F396, 0x1F397, 0x1F399, 0x1F39A, 0x1F39B, 0x1F39E, 0x1F39F, 0x1F3CB, + 0x1F3CC, 0x1F3CD, 0x1F3CE, 0x1F3D4, 0x1F3D5, 0x1F3D6, 0x1F3D7, 0x1F3D8, 0x1F3D9, 0x1F3DA, + 0x1F3DB, 0x1F3DC, 0x1F3DD, 0x1F3DE, 0x1F3DF, 0x1F3F3, 0x1F3F5, 0x1F3F7, 0x1F43F, 0x1F441, + 0x1F4FD, 0x1F549, 0x1F54A, 0x1F56F, 0x1F570, 0x1F573, 0x1F574, 0x1F575, 0x1F576, 0x1F577, + 0x1F578, 0x1F579, 0x1F587, 0x1F58A, 0x1F58B, 0x1F58C, 0x1F58D, 0x1F590, 0x1F5A5, 0x1F5A8, + 0x1F5B1, 0x1F5B2, 0x1F5BC, 0x1F5C2, 0x1F5C3, 0x1F5C4, 0x1F5D1, 0x1F5D2, 0x1F5D3, 0x1F5DC, + 0x1F5DD, 0x1F5DE, 0x1F5E1, 0x1F5E3, 0x1F5E8, 0x1F5EF, 0x1F5F3, 0x1F5FA, 0x1F6CB, 0x1F6CD, + 0x1F6CE, 0x1F6CF, 0x1F6E0, 0x1F6E1, 0x1F6E2, 0x1F6E3, 0x1F6E4, 0x1F6E5, 0x1F6E9, 0x1F6F0, + 0x1F6F3, }; static bool isEmojiStyleVSBase(uint32_t cp) { diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index 7fcc7b7f8b6..5cb94914c9e 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -33,6 +33,11 @@ void assertMinikinLocked() { } bool isEmoji(uint32_t c) { + // U+2695 U+2640 U+2642 are not in emoji category in Unicode 9 but they are now emoji category. + // TODO: remove once emoji database is updated. + if (c == 0x2695 || c == 0x2640 || c == 0x2642) { + return true; + } const size_t length = sizeof(generated::EMOJI_LIST) / sizeof(generated::EMOJI_LIST[0]); return std::binary_search(generated::EMOJI_LIST, generated::EMOJI_LIST + length, c); } diff --git a/engine/src/flutter/tests/FontCollectionTest.cpp b/engine/src/flutter/tests/FontCollectionTest.cpp index 5a03f60d26f..fa952421002 100644 --- a/engine/src/flutter/tests/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/FontCollectionTest.cpp @@ -105,6 +105,20 @@ TEST(FontCollectionTest, hasVariationSelectorTest_emoji) { // VS15/VS16 is only for emoji, should return false for not an emoji code point. EXPECT_FALSE(collection->hasVariationSelector(0x2229, 0xFE0E)); EXPECT_FALSE(collection->hasVariationSelector(0x2229, 0xFE0F)); + +} + +TEST(FontCollectionTest, newEmojiTest) { + MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + + // U+2695, U+2640, U+2642 are not in emoji catrgory in Unicode 9 but they are now in emoji + // category. Should return true even if U+FE0E was appended. + // These three emojis are only avalilable in TextEmoji.ttf but U+2695 is excluded here since it + // is used in other tests. + EXPECT_TRUE(collection->hasVariationSelector(0x2640, 0xFE0E)); + EXPECT_FALSE(collection->hasVariationSelector(0x2640, 0xFE0F)); + EXPECT_TRUE(collection->hasVariationSelector(0x2642, 0xFE0E)); + EXPECT_FALSE(collection->hasVariationSelector(0x2642, 0xFE0F)); } } // namespace android diff --git a/engine/src/flutter/tests/GraphemeBreakTests.cpp b/engine/src/flutter/tests/GraphemeBreakTests.cpp index cec53088774..9dfd426bc4b 100644 --- a/engine/src/flutter/tests/GraphemeBreakTests.cpp +++ b/engine/src/flutter/tests/GraphemeBreakTests.cpp @@ -179,6 +179,17 @@ TEST(GraphemeBreak, emojiModifiers) { // rat is not an emoji modifer EXPECT_TRUE(IsBreak("U+1F466 | U+1F400")); // boy + rat + +} + +TEST(GraphemeBreak, genderBalancedEmoji) { + // U+1F469 is WOMAN, U+200D is ZWJ, U+1F4BC is BRIEFCASE. + EXPECT_FALSE(IsBreak("U+1F469 | U+200D U+1F4BC")); + EXPECT_FALSE(IsBreak("U+1F469 U+200D | U+1F4BC")); + + // U+2695 has now emoji property, so should be part of ZWJ sequence. + EXPECT_FALSE(IsBreak("U+1F469 | U+200D U+2695")); + EXPECT_FALSE(IsBreak("U+1F469 U+200D | U+2695")); } TEST(GraphemeBreak, offsets) { From 56bda7e82a59b3fcaa828960deeb2a766f8afdfe Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Mon, 11 Jul 2016 17:28:44 +0900 Subject: [PATCH 195/364] Lookup glyph from color emoji font before and after ZWJ. Unicode recommends that the zwj sequences should be emoji presentation even if they don't have the proper U+FE0F. Thus always lookup the glyph for the code point before and after zwj as if they have a U+FE0F variation selector. Bug: 30056627 Change-Id: I03958a92337eaba4a8dd9c5be824b2665aa4a103 --- .../flutter/libs/minikin/FontCollection.cpp | 18 +++++++++++------- .../tests/FontCollectionItemizeTest.cpp | 12 +++++++++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 33418ab1b5d..e665615d93b 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -335,18 +335,15 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, } const uint32_t NBSP = 0xa0; -const uint32_t ZWJ = 0x200c; -const uint32_t ZWNJ = 0x200d; +const uint32_t ZWJ = 0x200d; +const uint32_t ZWNJ = 0x200c; const uint32_t HYPHEN = 0x2010; const uint32_t NB_HYPHEN = 0x2011; -const uint32_t FEMALE_SIGN = 0x2640; -const uint32_t MALE_SIGN = 0x2642; -const uint32_t STAFF_OF_AESCULAPIUS = 0x2695; // Characters where we want to continue using existing font run instead of // recomputing the best match in the fallback list. static const uint32_t stickyWhitelist[] = { '!', ',', '-', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ, - HYPHEN, NB_HYPHEN, FEMALE_SIGN, MALE_SIGN, STAFF_OF_AESCULAPIUS }; + HYPHEN, NB_HYPHEN }; static bool isStickyWhitelisted(uint32_t c) { for (size_t i = 0; i < sizeof(stickyWhitelist) / sizeof(stickyWhitelist[0]); i++) { @@ -432,8 +429,15 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } if (!shouldContinueRun) { - FontFamily* family = getFamilyForChar(ch, isVariationSelector(nextCh) ? nextCh : 0, + FontFamily* family; + if ((prevCh == ZWJ || nextCh == ZWJ) && isEmoji(ch)) { + // Treat emoji before and after ZWJ as emoji presentation. + family = getFamilyForChar(ch, EMOJI_STYLE_VS, langListId, variant); + } else { + family = getFamilyForChar(ch, isVariationSelector(nextCh) ? nextCh : 0, langListId, variant); + } + if (utf16Pos == 0 || family != lastFamily) { size_t start = utf16Pos; // Workaround for combining marks and emoji modifiers until we implement diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index 468b4a28fac..85d223ceaf0 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -1223,7 +1223,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { EXPECT_EQ(2, runs[0].end); EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); - // U+26FA U+FE0E is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F + // U+26FA U+FE0E is specified but ColorTextMixedEmojiFont has a variation sequence U+26FA U+FE0F // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. itemize(collection.get(), "U+26FA U+FE0E", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); @@ -1305,9 +1305,9 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { EXPECT_EQ(2, runs[0].end); EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); - // U+26F9 U+FE0F is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F + // U+26F8 U+FE0F is specified but ColorTextMixedEmojiFont has a variation sequence U+26F8 U+FE0F // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. - itemize(collection.get(), "U+26F9 U+FE0F", kDefaultFontStyle, &runs); + itemize(collection.get(), "U+26F8 U+FE0F", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1396,4 +1396,10 @@ TEST_F(FontCollectionItemizeTest, itemize_genderBalancedEmoji) { EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); + + itemize(collection.get(), "U+26F9 U+200D U+2695", kDefaultFontStyle, &runs); + ASSERT_EQ(1U, runs.size()); + EXPECT_EQ(0, runs[0].start); + EXPECT_EQ(3, runs[0].end); + EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); } From 3ebdaaae864e157985eb9ab60af6d10734c292dd Mon Sep 17 00:00:00 2001 From: Ben Wagner Date: Fri, 5 Aug 2016 12:01:04 -0400 Subject: [PATCH 196/364] Move SkTypeface::CreateXXX to SkTypeface::MakeXXX. Skia is moving to returning smart pointers from its factory methods. This updates uses of SkTypeface::CreateXXX to SkTypeface::MakeXXX and generally updates use of SkTypeface to sk_sp. This will allow for the removal of the SK_SUPPORT_LEGACY_TYPEFACE_PTR define. Change-Id: If3e600c6cb86080576667bc77d427da4f6560afa --- engine/src/flutter/sample/MinikinSkia.cpp | 14 +++++--------- engine/src/flutter/sample/MinikinSkia.h | 6 ++---- engine/src/flutter/sample/example_skia.cpp | 12 ++++++------ .../flutter/tests/util/MinikinFontForTest.cpp | 19 ++++++------------- .../flutter/tests/util/MinikinFontForTest.h | 6 +++--- 5 files changed, 22 insertions(+), 35 deletions(-) diff --git a/engine/src/flutter/sample/MinikinSkia.cpp b/engine/src/flutter/sample/MinikinSkia.cpp index c920ca63e56..ec1e9da78c2 100644 --- a/engine/src/flutter/sample/MinikinSkia.cpp +++ b/engine/src/flutter/sample/MinikinSkia.cpp @@ -6,17 +6,13 @@ namespace minikin { -MinikinFontSkia::MinikinFontSkia(SkTypeface *typeface) : +MinikinFontSkia::MinikinFontSkia(sk_sp typeface) : MinikinFont(typeface->uniqueID()), - mTypeface(typeface) { + mTypeface(std::move(typeface)) { } -MinikinFontSkia::~MinikinFontSkia() { - SkSafeUnref(mTypeface); -} - -static void MinikinFontSkia_SetSkiaPaint(SkTypeface* typeface, SkPaint* skPaint, const MinikinPaint& paint) { - skPaint->setTypeface(typeface); +static void MinikinFontSkia_SetSkiaPaint(sk_sp typeface, SkPaint* skPaint, const MinikinPaint& paint) { + skPaint->setTypeface(std::move(typeface)); skPaint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); // TODO: set more paint parameters from Minikin skPaint->setTextSize(paint.size); @@ -65,7 +61,7 @@ const void* MinikinFontSkia::GetTable(uint32_t tag, size_t* size, MinikinDestroy } SkTypeface *MinikinFontSkia::GetSkTypeface() { - return mTypeface; + return mTypeface.get(); } } // namespace minikin diff --git a/engine/src/flutter/sample/MinikinSkia.h b/engine/src/flutter/sample/MinikinSkia.h index 92f5ed2f524..d995f7d2798 100644 --- a/engine/src/flutter/sample/MinikinSkia.h +++ b/engine/src/flutter/sample/MinikinSkia.h @@ -17,9 +17,7 @@ namespace minikin { class MinikinFontSkia : public MinikinFont { public: - explicit MinikinFontSkia(SkTypeface *typeface); - - ~MinikinFontSkia(); + explicit MinikinFontSkia(sk_sp typeface); float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const; @@ -32,7 +30,7 @@ public: SkTypeface *GetSkTypeface(); private: - SkTypeface *mTypeface; + sk_sp mTypeface; }; diff --git a/engine/src/flutter/sample/example_skia.cpp b/engine/src/flutter/sample/example_skia.cpp index bd2d779b9e9..5e15a107c27 100644 --- a/engine/src/flutter/sample/example_skia.cpp +++ b/engine/src/flutter/sample/example_skia.cpp @@ -57,8 +57,8 @@ FontCollection *makeFontCollection() { FontFamily *family = new FontFamily(); for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) { const char *fn = fns[i]; - SkTypeface *skFace = SkTypeface::CreateFromFile(fn); - MinikinFont *font = new MinikinFontSkia(skFace); + sk_sp skFace = SkTypeface::MakeFromFile(fn); + MinikinFont *font = new MinikinFontSkia(std::move(skFace)); family->addFont(font); } typefaces.push_back(family); @@ -66,8 +66,8 @@ FontCollection *makeFontCollection() { #if 1 family = new FontFamily(); const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf"; - SkTypeface *skFace = SkTypeface::CreateFromFile(fn); - MinikinFont *font = new MinikinFontSkia(skFace); + sk_sp skFace = SkTypeface::MakeFromFile(fn); + MinikinFont *font = new MinikinFontSkia(std::move(skFace)); family->addFont(font); typefaces.push_back(family); #endif @@ -93,13 +93,13 @@ void drawToSkia(SkCanvas *canvas, SkPaint *paint, Layout *layout, float x, float pos[i].fX = x + layout->getX(i); pos[i].fY = y + layout->getY(i); if (i > 0 && skFace != lastFace) { - paint->setTypeface(lastFace); + paint->setTypeface(sk_ref_sp(lastFace)); canvas->drawPosText(glyphs + start, (i - start) << 1, pos + start, *paint); start = i; } lastFace = skFace; } - paint->setTypeface(skFace); + paint->setTypeface(sk_ref_sp(skFace)); canvas->drawPosText(glyphs + start, (nGlyphs - start) << 1, pos + start, *paint); delete[] glyphs; delete[] pos; diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.cpp b/engine/src/flutter/tests/util/MinikinFontForTest.cpp index 392d5b2ea54..807b234296e 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/util/MinikinFontForTest.cpp @@ -26,30 +26,23 @@ namespace minikin { // static MinikinFontForTest* MinikinFontForTest::createFromFile(const std::string& font_path) { - SkTypeface* typeface = SkTypeface::CreateFromFile(font_path.c_str()); - MinikinFontForTest* font = new MinikinFontForTest(font_path, typeface); - SkSafeUnref(typeface); + sk_sp typeface = SkTypeface::MakeFromFile(font_path.c_str()); + MinikinFontForTest* font = new MinikinFontForTest(font_path, std::move(typeface)); return font; } // static MinikinFontForTest* MinikinFontForTest::createFromFileWithIndex(const std::string& font_path, int index) { - SkTypeface* typeface = SkTypeface::CreateFromFile(font_path.c_str(), index); - MinikinFontForTest* font = new MinikinFontForTest(font_path, typeface); - SkSafeUnref(typeface); + sk_sp typeface = SkTypeface::MakeFromFile(font_path.c_str(), index); + MinikinFontForTest* font = new MinikinFontForTest(font_path, std::move(typeface)); return font; } -MinikinFontForTest::MinikinFontForTest(const std::string& font_path, SkTypeface* typeface) : +MinikinFontForTest::MinikinFontForTest(const std::string& font_path, sk_sp typeface) : MinikinFont(typeface->uniqueID()), - mTypeface(typeface), + mTypeface(std::move(typeface)), mFontPath(font_path) { - SkSafeRef(mTypeface); -} - -MinikinFontForTest::~MinikinFontForTest() { - SkSafeUnref(mTypeface); } float MinikinFontForTest::GetHorizontalAdvance(uint32_t /* glyph_id */, diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.h b/engine/src/flutter/tests/util/MinikinFontForTest.h index 7b5322ca0b1..423792f8d54 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.h +++ b/engine/src/flutter/tests/util/MinikinFontForTest.h @@ -18,6 +18,7 @@ #define MINIKIN_TEST_MINIKIN_FONT_FOR_TEST_H #include +#include class SkTypeface; @@ -25,8 +26,7 @@ namespace minikin { class MinikinFontForTest : public MinikinFont { public: - MinikinFontForTest(const std::string& font_path, SkTypeface* typeface); - ~MinikinFontForTest(); + MinikinFontForTest(const std::string& font_path, sk_sp typeface); // Helper function for creating MinikinFontForTest instance from font file. // Calller need to unref returned object. @@ -45,7 +45,7 @@ private: MinikinFontForTest(const MinikinFontForTest&) = delete; MinikinFontForTest& operator=(MinikinFontForTest&) = delete; - SkTypeface *mTypeface; + sk_sp mTypeface; const std::string mFontPath; }; From 96fa633577dddbdd2b56d4a72382a8a90980d036 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Thu, 11 Aug 2016 21:03:00 +0000 Subject: [PATCH 197/364] Revert "Lookup glyph from color emoji font before and after ZWJ." This reverts commit 56bda7e82a59b3fcaa828960deeb2a766f8afdfe. Bug: 30815709 Change-Id: I057d9bcd05246e58894abb4e9633bd10f6fab211 --- .../flutter/libs/minikin/FontCollection.cpp | 18 +++++++----------- .../tests/FontCollectionItemizeTest.cpp | 12 +++--------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index e665615d93b..33418ab1b5d 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -335,15 +335,18 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, } const uint32_t NBSP = 0xa0; -const uint32_t ZWJ = 0x200d; -const uint32_t ZWNJ = 0x200c; +const uint32_t ZWJ = 0x200c; +const uint32_t ZWNJ = 0x200d; const uint32_t HYPHEN = 0x2010; const uint32_t NB_HYPHEN = 0x2011; +const uint32_t FEMALE_SIGN = 0x2640; +const uint32_t MALE_SIGN = 0x2642; +const uint32_t STAFF_OF_AESCULAPIUS = 0x2695; // Characters where we want to continue using existing font run instead of // recomputing the best match in the fallback list. static const uint32_t stickyWhitelist[] = { '!', ',', '-', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ, - HYPHEN, NB_HYPHEN }; + HYPHEN, NB_HYPHEN, FEMALE_SIGN, MALE_SIGN, STAFF_OF_AESCULAPIUS }; static bool isStickyWhitelisted(uint32_t c) { for (size_t i = 0; i < sizeof(stickyWhitelist) / sizeof(stickyWhitelist[0]); i++) { @@ -429,15 +432,8 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } if (!shouldContinueRun) { - FontFamily* family; - if ((prevCh == ZWJ || nextCh == ZWJ) && isEmoji(ch)) { - // Treat emoji before and after ZWJ as emoji presentation. - family = getFamilyForChar(ch, EMOJI_STYLE_VS, langListId, variant); - } else { - family = getFamilyForChar(ch, isVariationSelector(nextCh) ? nextCh : 0, + FontFamily* family = getFamilyForChar(ch, isVariationSelector(nextCh) ? nextCh : 0, langListId, variant); - } - if (utf16Pos == 0 || family != lastFamily) { size_t start = utf16Pos; // Workaround for combining marks and emoji modifiers until we implement diff --git a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp index 85d223ceaf0..468b4a28fac 100644 --- a/engine/src/flutter/tests/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/FontCollectionItemizeTest.cpp @@ -1223,7 +1223,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { EXPECT_EQ(2, runs[0].end); EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); - // U+26FA U+FE0E is specified but ColorTextMixedEmojiFont has a variation sequence U+26FA U+FE0F + // U+26FA U+FE0E is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. itemize(collection.get(), "U+26FA U+FE0E", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); @@ -1305,9 +1305,9 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { EXPECT_EQ(2, runs[0].end); EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); - // U+26F8 U+FE0F is specified but ColorTextMixedEmojiFont has a variation sequence U+26F8 U+FE0F + // U+26F9 U+FE0F is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. - itemize(collection.get(), "U+26F8 U+FE0F", kDefaultFontStyle, &runs); + itemize(collection.get(), "U+26F9 U+FE0F", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1396,10 +1396,4 @@ TEST_F(FontCollectionItemizeTest, itemize_genderBalancedEmoji) { EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); - - itemize(collection.get(), "U+26F9 U+200D U+2695", kDefaultFontStyle, &runs); - ASSERT_EQ(1U, runs.size()); - EXPECT_EQ(0, runs[0].start); - EXPECT_EQ(3, runs[0].end); - EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); } From 85c660fa984c4d3a61136459a74b872ed01ead77 Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Mon, 15 Aug 2016 12:29:41 -0700 Subject: [PATCH 198/364] Fix google-explicit-constructor warnings in minikin * Add explicit keyword to conversion constructors, or add NOLINT(implicit) for implicit converters. Bug: 28341362 Test: build with WITH_TIDY=1 Change-Id: I0c7b90f9bb953a9f2e4f0fb2032fa65ac604b9ca --- engine/src/flutter/include/minikin/FontFamily.h | 4 ++-- engine/src/flutter/include/minikin/MinikinFont.h | 4 ++-- engine/src/flutter/include/minikin/MinikinRefCounted.h | 2 +- engine/src/flutter/libs/minikin/FontLanguage.h | 2 +- engine/src/flutter/libs/minikin/MinikinInternal.h | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index f4b1f468d7d..10362c24de1 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -37,7 +37,7 @@ class FontStyle { public: FontStyle() : FontStyle(0 /* variant */, 4 /* weight */, false /* italic */) {} FontStyle(int weight, bool italic) : FontStyle(0 /* variant */, weight, italic) {} - FontStyle(uint32_t langListId) + FontStyle(uint32_t langListId) // NOLINT(implicit) : FontStyle(langListId, 0 /* variant */, 4 /* weight */, false /* italic */) {} FontStyle(int variant, int weight, bool italic); @@ -102,7 +102,7 @@ class FontFamily : public MinikinRefCounted { public: FontFamily(); - FontFamily(int variant); + explicit FontFamily(int variant); FontFamily(uint32_t langId, int variant) : mLangId(langId), diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 9d4f9370898..ac9235be8d3 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -33,7 +33,7 @@ namespace minikin { class HyphenEdit { public: HyphenEdit() : hyphen(0) { } - HyphenEdit(uint32_t hyphenInt) : hyphen(hyphenInt) { } + HyphenEdit(uint32_t hyphenInt) : hyphen(hyphenInt) { } // NOLINT(implicit) bool hasHyphen() const { return hyphen != 0; } bool operator==(const HyphenEdit &other) const { return hyphen == other.hyphen; } private: @@ -99,7 +99,7 @@ typedef void (*MinikinDestroyFunc) (void* data); class MinikinFont : public MinikinRefCounted { public: - MinikinFont(int32_t uniqueId) : mUniqueId(uniqueId) {} + explicit MinikinFont(int32_t uniqueId) : mUniqueId(uniqueId) {} virtual ~MinikinFont(); diff --git a/engine/src/flutter/include/minikin/MinikinRefCounted.h b/engine/src/flutter/include/minikin/MinikinRefCounted.h index 0ee44747c1b..960b6cc46da 100644 --- a/engine/src/flutter/include/minikin/MinikinRefCounted.h +++ b/engine/src/flutter/include/minikin/MinikinRefCounted.h @@ -42,7 +42,7 @@ private: template class MinikinAutoUnref { public: - MinikinAutoUnref(T* obj) : mObj(obj) { + explicit MinikinAutoUnref(T* obj) : mObj(obj) { } ~MinikinAutoUnref() { mObj->Unref(); diff --git a/engine/src/flutter/libs/minikin/FontLanguage.h b/engine/src/flutter/libs/minikin/FontLanguage.h index f28a4a8e720..b1bb6eb5f95 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.h +++ b/engine/src/flutter/libs/minikin/FontLanguage.h @@ -98,7 +98,7 @@ private: // An immutable list of languages. class FontLanguages { public: - FontLanguages(std::vector&& languages); + explicit FontLanguages(std::vector&& languages); FontLanguages() : mUnionOfSubScriptBits(0), mIsAllTheSameLanguage(false) {} FontLanguages(FontLanguages&&) = default; diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.h b/engine/src/flutter/libs/minikin/MinikinInternal.h index 88c0d5f510a..88d54d7b11f 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.h +++ b/engine/src/flutter/libs/minikin/MinikinInternal.h @@ -52,7 +52,7 @@ class HbBlob { public: // Takes ownership of hb_blob_t object, caller is no longer // responsible for calling hb_blob_destroy(). - HbBlob(hb_blob_t* blob) : mBlob(blob) { + explicit HbBlob(hb_blob_t* blob) : mBlob(blob) { } ~HbBlob() { From 32252e357f3898baec85bafe076debefd915adfe Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Mon, 15 Aug 2016 12:29:41 -0700 Subject: [PATCH 199/364] Fix google-explicit-constructor warnings in minikin * Add explicit keyword to conversion constructors, or add NOLINT(implicit) for implicit converters. Bug: 28341362 Test: build with WITH_TIDY=1 Change-Id: I0c7b90f9bb953a9f2e4f0fb2032fa65ac604b9ca Merged-In: I0c7b90f9bb953a9f2e4f0fb2032fa65ac604b9ca --- engine/src/flutter/include/minikin/FontFamily.h | 4 ++-- engine/src/flutter/include/minikin/MinikinFont.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 7bdff6eb4ff..4d7d08378aa 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -65,10 +65,10 @@ private: // so it can be efficiently copied, embedded in other objects, etc. class FontStyle { public: - FontStyle(int weight = 4, bool italic = false) { + explicit FontStyle(int weight = 4, bool italic = false) { bits = (weight & kWeightMask) | (italic ? kItalicMask : 0); } - FontStyle(FontLanguage lang, int variant = 0, int weight = 4, bool italic = false) { + explicit FontStyle(FontLanguage lang, int variant = 0, int weight = 4, bool italic = false) { bits = (weight & kWeightMask) | (italic ? kItalicMask : 0) | (variant << kVariantShift) | (lang.bits() << kLangShift); } diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 7f65cd7b0aa..b7e6f87f782 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -33,7 +33,7 @@ namespace android { class HyphenEdit { public: HyphenEdit() : hyphen(0) { } - HyphenEdit(uint32_t hyphenInt) : hyphen(hyphenInt) { } + HyphenEdit(uint32_t hyphenInt) : hyphen(hyphenInt) { } // NOLINT(implicit) bool hasHyphen() const { return hyphen != 0; } bool operator==(const HyphenEdit &other) const { return hyphen == other.hyphen; } private: From b4f4c16d32a6734f163a59cfa404536501d882fb Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Mon, 12 Sep 2016 14:37:02 -0700 Subject: [PATCH 200/364] Rename libicuuc-host/libicui18n-host to libicuuc/libicui18n These modules can be named the same between the target and host libraries, which simplifies references to them, particularly in Soong. To prevent accidentally loading the system copy of the library, we still rename the installed name to be libicu*-host.so. But modules do not need to know that in order to build against them. Change-Id: Ic38499bb236ace75333a84f23798af023e14cf5f --- engine/src/flutter/app/Android.mk | 2 +- engine/src/flutter/libs/minikin/Android.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/app/Android.mk b/engine/src/flutter/app/Android.mk index 20386830272..23305b7b4c6 100644 --- a/engine/src/flutter/app/Android.mk +++ b/engine/src/flutter/app/Android.mk @@ -28,7 +28,7 @@ LOCAL_STATIC_LIBRARIES := libminikin_host LOCAL_SHARED_LIBRARIES := \ liblog \ - libicuuc-host + libicuuc LOCAL_SRC_FILES += \ HyphTool.cpp diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 9d8257944f1..d6c3df7f621 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -109,7 +109,7 @@ LOCAL_MODULE_TAGS := optional LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include LOCAL_C_INCLUDES := $(minikin_c_includes) LOCAL_CPPFLAGS += -Werror -Wall -Wextra $(enable_race_detection) -LOCAL_SHARED_LIBRARIES := liblog libicuuc-host +LOCAL_SHARED_LIBRARIES := liblog libicuuc LOCAL_SRC_FILES := Hyphenator.cpp From fba88d3b3c5c0640b55effac84b1314760f46bf1 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Sun, 11 Sep 2016 14:47:29 -0700 Subject: [PATCH 201/364] Switch minikin to std::unique_ptr. Bug: http://b/22403888 Change-Id: I9e18496fcc38ad2e6b922455daa9f2a46778ec55 --- engine/src/flutter/include/minikin/SparseBitSet.h | 7 ++++--- engine/src/flutter/libs/minikin/FontFamily.cpp | 1 - engine/src/flutter/libs/minikin/Layout.cpp | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/include/minikin/SparseBitSet.h b/engine/src/flutter/include/minikin/SparseBitSet.h index 72b83057c6c..81f67c8f963 100644 --- a/engine/src/flutter/include/minikin/SparseBitSet.h +++ b/engine/src/flutter/include/minikin/SparseBitSet.h @@ -19,7 +19,8 @@ #include #include -#include + +#include // --------------------------------------------------------------------------- @@ -79,8 +80,8 @@ private: static int CountLeadingZeros(element x); uint32_t mMaxVal; - UniquePtr mIndices; - UniquePtr mBitmaps; + std::unique_ptr mIndices; + std::unique_ptr mBitmaps; uint32_t mZeroPageIndex; }; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index e2d86f0bbb0..7a8e79f508f 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -34,7 +34,6 @@ #include #include #include -#include using std::vector; diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 9c1d6a873a5..5ba72a4bb2c 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -496,7 +496,8 @@ private: size_t mRunCount; bool mIsRtl; - DISALLOW_COPY_AND_ASSIGN(BidiText); + BidiText(const BidiText&) = delete; + void operator=(const BidiText&) = delete; }; BidiText::Iter::Iter(UBiDi* bidi, size_t start, size_t end, size_t runIndex, size_t runCount, From 5bd8edea610210d041db240a0721a17f58f2a54e Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 23 Jun 2016 13:22:16 +0900 Subject: [PATCH 202/364] Fix lookup order for VS in itemization. This is partial revert of Iced1349e3ca750821d8882c551551f65bb569794. Due to sorting of target family vectors, the font family order from XML settings file is broken. Making unique operation stable doesn't fix the issue completely since some font families are appended for the fallback which also breaks the original order. By this change, itemization becomes 3x slower than before if variation selector is appended. Bug: 29585939 Change-Id: I7c1a8a57f04111a30cd41a5cd5bec25fcfb3972e --- .../flutter/libs/minikin/FontCollection.cpp | 17 +---- engine/src/flutter/tests/unittest/Android.mk | 1 + .../unittest/FontCollectionItemizeTest.cpp | 73 +++++++++++++++++++ 3 files changed, 77 insertions(+), 14 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 97c206881f1..19ad7523f7d 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -281,22 +281,11 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, return mFamilies[0]; } - const std::vector* familyVec = &mFamilyVec; + const std::vector& familyVec = (vs == 0) ? mFamilyVec : mFamilies; Range range = mRanges[ch >> kLogCharsPerPage]; - std::vector familyVecForVS; if (vs != 0) { - // If variation selector is specified, need to search for both the variation sequence and - // its base codepoint. Compute the union vector of them. - familyVecForVS = mVSFamilyVec; - familyVecForVS.insert(familyVecForVS.end(), - mFamilyVec.begin() + range.start, mFamilyVec.begin() + range.end); - std::sort(familyVecForVS.begin(), familyVecForVS.end()); - auto last = std::unique(familyVecForVS.begin(), familyVecForVS.end()); - familyVecForVS.erase(last, familyVecForVS.end()); - - familyVec = &familyVecForVS; - range = { 0, familyVecForVS.size() }; + range = { 0, mFamilies.size() }; } #ifdef VERBOSE_DEBUG @@ -305,7 +294,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, FontFamily* bestFamily = nullptr; uint32_t bestScore = kUnsupportedFontScore; for (size_t i = range.start; i < range.end; i++) { - FontFamily* family = (*familyVec)[i]; + FontFamily* family = familyVec[i]; const uint32_t score = calcFamilyScore(ch, vs, variant, langListId, family); if (score == kFirstFontScore) { // If the first font family supports the given character or variation sequence, always diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index b43e3c85703..a81d17cca7e 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -32,6 +32,7 @@ font_src_files := \ data/Italic.ttf \ data/Ja.ttf \ data/Ko.ttf \ + data/NoCmapFormat14.ttf \ data/NoGlyphFont.ttf \ data/Regular.ttf \ data/TextEmojiFont.ttf \ diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 367739683d1..978ba9f499f 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -44,6 +44,9 @@ const char kColorEmojiFont[] = kTestFontDir "ColorEmojiFont.ttf"; const char kTextEmojiFont[] = kTestFontDir "TextEmojiFont.ttf"; const char kMixedEmojiFont[] = kTestFontDir "ColorTextMixedEmojiFont.ttf"; +const char kHasCmapFormat14Font[] = kTestFontDir "NoCmapFormat14.ttf"; +const char kNoCmapFormat14Font[] = kTestFontDir "VarioationSelectorTest-Regular.ttf"; + typedef ICUTestBase FontCollectionItemizeTest; // Utility function for calling itemize function. @@ -1392,4 +1395,74 @@ TEST_F(FontCollectionItemizeTest, itemize_genderBalancedEmoji) { EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); } +// For b/29585939 +TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS) { + const FontStyle kDefaultFontStyle; + + MinikinAutoUnref dummyFont(MinikinFontForTest::createFromFile(kNoGlyphFont)); + MinikinAutoUnref fontA(MinikinFontForTest::createFromFile(kZH_HansFont)); + MinikinAutoUnref fontB(MinikinFontForTest::createFromFile(kZH_HansFont)); + + MinikinAutoUnref dummyFamily(new FontFamily()); + MinikinAutoUnref familyA(new FontFamily()); + MinikinAutoUnref familyB(new FontFamily()); + + dummyFamily->addFont(dummyFont.get()); + familyA->addFont(fontA.get()); + familyB->addFont(fontB.get()); + + std::vector families = + { dummyFamily.get(), familyA.get(), familyB.get() }; + std::vector reversedFamilies = + { dummyFamily.get(), familyB.get(), familyA.get() }; + + MinikinAutoUnref collection(new FontCollection(families)); + MinikinAutoUnref reversedCollection(new FontCollection(reversedFamilies)); + + // Both fontA/fontB support U+35A8 but don't support U+35A8 U+E0100. The first font should be + // selected. + std::vector runs; + itemize(collection.get(), "U+35A8 U+E0100", kDefaultFontStyle, &runs); + EXPECT_EQ(fontA.get(), runs[0].fakedFont.font); + + itemize(reversedCollection.get(), "U+35A8 U+E0100", kDefaultFontStyle, &runs); + EXPECT_EQ(fontB.get(), runs[0].fakedFont.font); +} + +// For b/29585939 +TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS2) { + const FontStyle kDefaultFontStyle; + + MinikinAutoUnref dummyFont(MinikinFontForTest::createFromFile(kNoGlyphFont)); + MinikinAutoUnref hasCmapFormat14Font( + MinikinFontForTest::createFromFile(kHasCmapFormat14Font)); + MinikinAutoUnref noCmapFormat14Font( + MinikinFontForTest::createFromFile(kNoCmapFormat14Font)); + + MinikinAutoUnref dummyFamily(new FontFamily()); + MinikinAutoUnref hasCmapFormat14Family(new FontFamily()); + MinikinAutoUnref noCmapFormat14Family(new FontFamily()); + + dummyFamily->addFont(dummyFont.get()); + hasCmapFormat14Family->addFont(hasCmapFormat14Font.get()); + noCmapFormat14Family->addFont(noCmapFormat14Font.get()); + + std::vector families = + { dummyFamily.get(), hasCmapFormat14Family.get(), noCmapFormat14Family.get() }; + std::vector reversedFamilies = + { dummyFamily.get(), noCmapFormat14Family.get(), hasCmapFormat14Family.get() }; + + MinikinAutoUnref collection(new FontCollection(families)); + MinikinAutoUnref reversedCollection(new FontCollection(reversedFamilies)); + + // Both hasCmapFormat14Font/noCmapFormat14Font support U+5380 but don't support U+5380 U+E0100. + // The first font should be selected. + std::vector runs; + itemize(collection.get(), "U+5380 U+E0100", kDefaultFontStyle, &runs); + EXPECT_EQ(hasCmapFormat14Font.get(), runs[0].fakedFont.font); + + itemize(reversedCollection.get(), "U+5380 U+E0100", kDefaultFontStyle, &runs); + EXPECT_EQ(noCmapFormat14Font.get(), runs[0].fakedFont.font); +} + } // namespace minikin From 7b02f5e95c4386c250f6f83db1ff61b69177140e Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 18 Oct 2016 11:21:59 +0900 Subject: [PATCH 203/364] Clean Up: Removing unused interface GetTable from MinikinFont. After Id766ab16a8d342bf7322a90e076e801271d527d4, GetTable is no longer used in production due to poor performance and it is now only used in tests. This CL removes GetTable interface from MinikinFont and update tests code to use new interfaces, GetFontData, GetFontSize and GetFontIndex. Bug: 27860101 Test: Manually done Change-Id: Ifcd7a348d7fb5af081192899dbcdfc7fb4eebbf9 --- .../src/flutter/include/minikin/MinikinFont.h | 2 - .../src/flutter/libs/minikin/HbFontCache.cpp | 31 +++-------- .../unittest/FontCollectionItemizeTest.cpp | 8 +-- .../tests/unittest/FontCollectionTest.cpp | 2 +- .../flutter/tests/unittest/FontFamilyTest.cpp | 4 +- .../tests/unittest/HbFontCacheTest.cpp | 8 +-- .../src/flutter/tests/util/FontTestUtils.cpp | 5 +- .../flutter/tests/util/MinikinFontForTest.cpp | 54 +++++++------------ .../flutter/tests/util/MinikinFontForTest.h | 18 +++---- 9 files changed, 47 insertions(+), 85 deletions(-) diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index ac9235be8d3..253160204ef 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -109,8 +109,6 @@ public: virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint &paint) const = 0; - virtual const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) = 0; - // Override if font can provide access to raw data virtual const void* GetFontData() const { return nullptr; diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index 45c3f5807ba..3c6619d10a4 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -28,22 +28,6 @@ namespace minikin { -static hb_blob_t* referenceTable(hb_face_t* /* face */, hb_tag_t tag, void* userData) { - MinikinFont* font = reinterpret_cast(userData); - MinikinDestroyFunc destroy = 0; - size_t size = 0; - const void* buffer = font->GetTable(tag, &size, &destroy); - if (buffer == nullptr) { - return nullptr; - } -#ifdef VERBOSE_DEBUG - ALOGD("referenceTable %c%c%c%c length=%zd", - (tag >>24)&0xff, (tag>>16)&0xff, (tag>>8)&0xff, tag&0xff, size); -#endif - return hb_blob_create(reinterpret_cast(buffer), size, - HB_MEMORY_MODE_READONLY, const_cast(buffer), destroy); -} - class HbFontCache : private android::OnEntryRemoved { public: HbFontCache() : mCache(kMaxEntries) { @@ -119,15 +103,12 @@ hb_font_t* getHbFontLocked(MinikinFont* minikinFont) { hb_face_t* face; const void* buf = minikinFont->GetFontData(); - if (buf == nullptr) { - face = hb_face_create_for_tables(referenceTable, minikinFont, nullptr); - } else { - size_t size = minikinFont->GetFontSize(); - hb_blob_t* blob = hb_blob_create(reinterpret_cast(buf), size, - HB_MEMORY_MODE_READONLY, nullptr, nullptr); - face = hb_face_create(blob, minikinFont->GetFontIndex()); - hb_blob_destroy(blob); - } + size_t size = minikinFont->GetFontSize(); + hb_blob_t* blob = hb_blob_create(reinterpret_cast(buf), size, + HB_MEMORY_MODE_READONLY, nullptr, nullptr); + face = hb_face_create(blob, minikinFont->GetFontIndex()); + hb_blob_destroy(blob); + hb_font_t* parent_font = hb_font_create(face); hb_ot_font_set_funcs(parent_font); diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 367739683d1..0d2a7cbfa6a 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -666,12 +666,12 @@ TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { std::vector families; FontFamily* family1 = new FontFamily(VARIANT_DEFAULT); - MinikinAutoUnref font(MinikinFontForTest::createFromFile(kLatinFont)); + MinikinAutoUnref font(new MinikinFontForTest(kLatinFont)); family1->addFont(font.get()); families.push_back(family1); FontFamily* family2 = new FontFamily(VARIANT_DEFAULT); - MinikinAutoUnref font2(MinikinFontForTest::createFromFile(kVSTestFont)); + MinikinAutoUnref font2(new MinikinFontForTest(kVSTestFont)); family2->addFont(font2.get()); families.push_back(family2); @@ -797,7 +797,7 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { FontFamily* firstFamily = new FontFamily( FontStyle::registerLanguageList("und"), 0 /* variant */); MinikinAutoUnref firstFamilyMinikinFont( - MinikinFontForTest::createFromFile(kNoGlyphFont)); + new MinikinFontForTest(kNoGlyphFont)); firstFamily->addFont(firstFamilyMinikinFont.get()); families.push_back(firstFamily); @@ -809,7 +809,7 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { for (size_t i = 0; i < testCase.fontLanguages.size(); ++i) { FontFamily* family = new FontFamily( FontStyle::registerLanguageList(testCase.fontLanguages[i]), 0 /* variant */); - MinikinAutoUnref minikin_font(MinikinFontForTest::createFromFile(kJAFont)); + MinikinAutoUnref minikin_font(new MinikinFontForTest(kJAFont)); family->addFont(minikin_font.get()); families.push_back(family); fontLangIdxMap.insert(std::make_pair(minikin_font.get(), i)); diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index ef2da66b2b3..62d2f022fa3 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -58,7 +58,7 @@ void expectVSGlyphs(const FontCollection* fc, uint32_t codepoint, const std::set TEST(FontCollectionTest, hasVariationSelectorTest) { MinikinAutoUnref family(new FontFamily()); - MinikinAutoUnref font(MinikinFontForTest::createFromFile(kVsTestFont)); + MinikinAutoUnref font(new MinikinFontForTest(kVsTestFont)); family->addFont(font.get()); std::vector families({family.get()}); MinikinAutoUnref fc(new FontCollection(families)); diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 69fef23da82..4aaa601a23e 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -351,7 +351,7 @@ void expectVSGlyphs(FontFamily* family, uint32_t codepoint, const std::set - minikinFont(MinikinFontForTest::createFromFile(kVsTestFont)); + minikinFont(new MinikinFontForTest(kVsTestFont)); MinikinAutoUnref family(new FontFamily); family->addFont(minikinFont.get()); @@ -405,7 +405,7 @@ TEST_F(FontFamilyTest, hasVSTableTest) { "Font " + testCase.fontPath + " shouldn't have a variation sequence table."); MinikinAutoUnref minikinFont( - MinikinFontForTest::createFromFile(testCase.fontPath)); + new MinikinFontForTest(testCase.fontPath)); MinikinAutoUnref family(new FontFamily); family->addFont(minikinFont.get()); android::AutoMutex _l(gMinikinLock); diff --git a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp index aa4cb34c053..5e560430c2f 100644 --- a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp @@ -38,13 +38,13 @@ public: TEST_F(HbFontCacheTest, getHbFontLockedTest) { MinikinAutoUnref fontA( - MinikinFontForTest::createFromFile(kTestFontDir "Regular.ttf")); + new MinikinFontForTest(kTestFontDir "Regular.ttf")); MinikinAutoUnref fontB( - MinikinFontForTest::createFromFile(kTestFontDir "Bold.ttf")); + new MinikinFontForTest(kTestFontDir "Bold.ttf")); MinikinAutoUnref fontC( - MinikinFontForTest::createFromFile(kTestFontDir "BoldItalic.ttf")); + new MinikinFontForTest(kTestFontDir "BoldItalic.ttf")); android::AutoMutex _l(gMinikinLock); // Never return NULL. @@ -66,7 +66,7 @@ TEST_F(HbFontCacheTest, getHbFontLockedTest) { TEST_F(HbFontCacheTest, purgeCacheTest) { MinikinAutoUnref minikinFont( - MinikinFontForTest::createFromFile(kTestFontDir "Regular.ttf")); + new MinikinFontForTest(kTestFontDir "Regular.ttf")); android::AutoMutex _l(gMinikinLock); hb_font_t* font = getHbFontLocked(minikinFont.get()); diff --git a/engine/src/flutter/tests/util/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp index 246c87231af..b675620e258 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.cpp +++ b/engine/src/flutter/tests/util/FontTestUtils.cpp @@ -77,12 +77,11 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { if (index == nullptr) { MinikinAutoUnref - minikinFont(MinikinFontForTest::createFromFile(fontPath)); + minikinFont(new MinikinFontForTest(fontPath)); family->addFont(minikinFont.get(), FontStyle(weight, italic)); } else { MinikinAutoUnref - minikinFont(MinikinFontForTest::createFromFileWithIndex(fontPath, - atoi((const char*)index))); + minikinFont(new MinikinFontForTest(fontPath, atoi((const char*)index))); family->addFont(minikinFont.get(), FontStyle(weight, italic)); } } diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.cpp b/engine/src/flutter/tests/util/MinikinFontForTest.cpp index 807b234296e..db4b8333f8b 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/util/MinikinFontForTest.cpp @@ -18,31 +18,31 @@ #include -#include - #include +#include +#include +#include namespace minikin { -// static -MinikinFontForTest* MinikinFontForTest::createFromFile(const std::string& font_path) { - sk_sp typeface = SkTypeface::MakeFromFile(font_path.c_str()); - MinikinFontForTest* font = new MinikinFontForTest(font_path, std::move(typeface)); - return font; +static int uniqueId = 0; // TODO: make thread safe if necessary. + +MinikinFontForTest::MinikinFontForTest(const std::string& font_path, int index) : + MinikinFont(uniqueId++), + mFontPath(font_path), + mFontIndex(index) { + int fd = open(font_path.c_str(), O_RDONLY); + LOG_ALWAYS_FATAL_IF(fd == -1); + struct stat st = {}; + LOG_ALWAYS_FATAL_IF(fstat(fd, &st) != 0); + mFontSize = st.st_size; + mFontData = mmap(NULL, mFontSize, PROT_READ, MAP_SHARED, fd, 0); + LOG_ALWAYS_FATAL_IF(mFontData == nullptr); + close(fd); } -// static -MinikinFontForTest* MinikinFontForTest::createFromFileWithIndex(const std::string& font_path, - int index) { - sk_sp typeface = SkTypeface::MakeFromFile(font_path.c_str(), index); - MinikinFontForTest* font = new MinikinFontForTest(font_path, std::move(typeface)); - return font; -} - -MinikinFontForTest::MinikinFontForTest(const std::string& font_path, sk_sp typeface) : - MinikinFont(typeface->uniqueID()), - mTypeface(std::move(typeface)), - mFontPath(font_path) { +MinikinFontForTest::~MinikinFontForTest() { + munmap(mFontData, mFontSize); } float MinikinFontForTest::GetHorizontalAdvance(uint32_t /* glyph_id */, @@ -56,20 +56,4 @@ void MinikinFontForTest::GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph_ LOG_ALWAYS_FATAL("MinikinFontForTest::GetBounds is not yet implemented"); } -const void* MinikinFontForTest::GetTable(uint32_t tag, size_t* size, - MinikinDestroyFunc* destroy) { - const size_t tableSize = mTypeface->getTableSize(tag); - *size = tableSize; - if (tableSize == 0) { - return nullptr; - } - void* buf = malloc(tableSize); - if (buf == nullptr) { - return nullptr; - } - mTypeface->getTableData(tag, 0, tableSize, buf); - *destroy = free; - return buf; -} - } // namespace minikin diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.h b/engine/src/flutter/tests/util/MinikinFontForTest.h index 423792f8d54..ee0eadbe0c2 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.h +++ b/engine/src/flutter/tests/util/MinikinFontForTest.h @@ -18,7 +18,6 @@ #define MINIKIN_TEST_MINIKIN_FONT_FOR_TEST_H #include -#include class SkTypeface; @@ -26,27 +25,28 @@ namespace minikin { class MinikinFontForTest : public MinikinFont { public: - MinikinFontForTest(const std::string& font_path, sk_sp typeface); - - // Helper function for creating MinikinFontForTest instance from font file. - // Calller need to unref returned object. - static MinikinFontForTest* createFromFile(const std::string& font_path); - static MinikinFontForTest* createFromFileWithIndex(const std::string& font_path, int index); + MinikinFontForTest(const std::string& font_path, int index); + MinikinFontForTest(const std::string& font_path) : MinikinFontForTest(font_path, 0) {} + virtual ~MinikinFontForTest(); // MinikinFont overrides. float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const; void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint& paint) const; - const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); const std::string& fontPath() const { return mFontPath; } + const void* GetFontData() const { return mFontData; } + size_t GetFontSize() const { return mFontSize; } + int GetFontIndex() const { return mFontIndex; } private: MinikinFontForTest() = delete; MinikinFontForTest(const MinikinFontForTest&) = delete; MinikinFontForTest& operator=(MinikinFontForTest&) = delete; - sk_sp mTypeface; const std::string mFontPath; + const int mFontIndex; + void* mFontData; + size_t mFontSize; }; } // namespace minikin From dc8de001df23f2263bbe2e5e3935f85a2be2ef5e Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 25 Oct 2016 00:49:52 +0000 Subject: [PATCH 204/364] Revert "Clean Up: Removing unused interface GetTable from MinikinFont." This reverts commit 7b02f5e95c4386c250f6f83db1ff61b69177140e. This causes a crash on Android Auto. Bug: 32374752 Change-Id: Ia2ff77bf9a12351c6949f79ef6fa2d8016e3022d --- .../src/flutter/include/minikin/MinikinFont.h | 2 + .../src/flutter/libs/minikin/HbFontCache.cpp | 31 ++++++++--- .../unittest/FontCollectionItemizeTest.cpp | 8 +-- .../tests/unittest/FontCollectionTest.cpp | 2 +- .../flutter/tests/unittest/FontFamilyTest.cpp | 4 +- .../tests/unittest/HbFontCacheTest.cpp | 8 +-- .../src/flutter/tests/util/FontTestUtils.cpp | 5 +- .../flutter/tests/util/MinikinFontForTest.cpp | 54 ++++++++++++------- .../flutter/tests/util/MinikinFontForTest.h | 18 +++---- 9 files changed, 85 insertions(+), 47 deletions(-) diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 253160204ef..ac9235be8d3 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -109,6 +109,8 @@ public: virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint &paint) const = 0; + virtual const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) = 0; + // Override if font can provide access to raw data virtual const void* GetFontData() const { return nullptr; diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index 3c6619d10a4..45c3f5807ba 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -28,6 +28,22 @@ namespace minikin { +static hb_blob_t* referenceTable(hb_face_t* /* face */, hb_tag_t tag, void* userData) { + MinikinFont* font = reinterpret_cast(userData); + MinikinDestroyFunc destroy = 0; + size_t size = 0; + const void* buffer = font->GetTable(tag, &size, &destroy); + if (buffer == nullptr) { + return nullptr; + } +#ifdef VERBOSE_DEBUG + ALOGD("referenceTable %c%c%c%c length=%zd", + (tag >>24)&0xff, (tag>>16)&0xff, (tag>>8)&0xff, tag&0xff, size); +#endif + return hb_blob_create(reinterpret_cast(buffer), size, + HB_MEMORY_MODE_READONLY, const_cast(buffer), destroy); +} + class HbFontCache : private android::OnEntryRemoved { public: HbFontCache() : mCache(kMaxEntries) { @@ -103,12 +119,15 @@ hb_font_t* getHbFontLocked(MinikinFont* minikinFont) { hb_face_t* face; const void* buf = minikinFont->GetFontData(); - size_t size = minikinFont->GetFontSize(); - hb_blob_t* blob = hb_blob_create(reinterpret_cast(buf), size, - HB_MEMORY_MODE_READONLY, nullptr, nullptr); - face = hb_face_create(blob, minikinFont->GetFontIndex()); - hb_blob_destroy(blob); - + if (buf == nullptr) { + face = hb_face_create_for_tables(referenceTable, minikinFont, nullptr); + } else { + size_t size = minikinFont->GetFontSize(); + hb_blob_t* blob = hb_blob_create(reinterpret_cast(buf), size, + HB_MEMORY_MODE_READONLY, nullptr, nullptr); + face = hb_face_create(blob, minikinFont->GetFontIndex()); + hb_blob_destroy(blob); + } hb_font_t* parent_font = hb_font_create(face); hb_ot_font_set_funcs(parent_font); diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 0d2a7cbfa6a..367739683d1 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -666,12 +666,12 @@ TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { std::vector families; FontFamily* family1 = new FontFamily(VARIANT_DEFAULT); - MinikinAutoUnref font(new MinikinFontForTest(kLatinFont)); + MinikinAutoUnref font(MinikinFontForTest::createFromFile(kLatinFont)); family1->addFont(font.get()); families.push_back(family1); FontFamily* family2 = new FontFamily(VARIANT_DEFAULT); - MinikinAutoUnref font2(new MinikinFontForTest(kVSTestFont)); + MinikinAutoUnref font2(MinikinFontForTest::createFromFile(kVSTestFont)); family2->addFont(font2.get()); families.push_back(family2); @@ -797,7 +797,7 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { FontFamily* firstFamily = new FontFamily( FontStyle::registerLanguageList("und"), 0 /* variant */); MinikinAutoUnref firstFamilyMinikinFont( - new MinikinFontForTest(kNoGlyphFont)); + MinikinFontForTest::createFromFile(kNoGlyphFont)); firstFamily->addFont(firstFamilyMinikinFont.get()); families.push_back(firstFamily); @@ -809,7 +809,7 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { for (size_t i = 0; i < testCase.fontLanguages.size(); ++i) { FontFamily* family = new FontFamily( FontStyle::registerLanguageList(testCase.fontLanguages[i]), 0 /* variant */); - MinikinAutoUnref minikin_font(new MinikinFontForTest(kJAFont)); + MinikinAutoUnref minikin_font(MinikinFontForTest::createFromFile(kJAFont)); family->addFont(minikin_font.get()); families.push_back(family); fontLangIdxMap.insert(std::make_pair(minikin_font.get(), i)); diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index 62d2f022fa3..ef2da66b2b3 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -58,7 +58,7 @@ void expectVSGlyphs(const FontCollection* fc, uint32_t codepoint, const std::set TEST(FontCollectionTest, hasVariationSelectorTest) { MinikinAutoUnref family(new FontFamily()); - MinikinAutoUnref font(new MinikinFontForTest(kVsTestFont)); + MinikinAutoUnref font(MinikinFontForTest::createFromFile(kVsTestFont)); family->addFont(font.get()); std::vector families({family.get()}); MinikinAutoUnref fc(new FontCollection(families)); diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 4aaa601a23e..69fef23da82 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -351,7 +351,7 @@ void expectVSGlyphs(FontFamily* family, uint32_t codepoint, const std::set - minikinFont(new MinikinFontForTest(kVsTestFont)); + minikinFont(MinikinFontForTest::createFromFile(kVsTestFont)); MinikinAutoUnref family(new FontFamily); family->addFont(minikinFont.get()); @@ -405,7 +405,7 @@ TEST_F(FontFamilyTest, hasVSTableTest) { "Font " + testCase.fontPath + " shouldn't have a variation sequence table."); MinikinAutoUnref minikinFont( - new MinikinFontForTest(testCase.fontPath)); + MinikinFontForTest::createFromFile(testCase.fontPath)); MinikinAutoUnref family(new FontFamily); family->addFont(minikinFont.get()); android::AutoMutex _l(gMinikinLock); diff --git a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp index 5e560430c2f..aa4cb34c053 100644 --- a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp @@ -38,13 +38,13 @@ public: TEST_F(HbFontCacheTest, getHbFontLockedTest) { MinikinAutoUnref fontA( - new MinikinFontForTest(kTestFontDir "Regular.ttf")); + MinikinFontForTest::createFromFile(kTestFontDir "Regular.ttf")); MinikinAutoUnref fontB( - new MinikinFontForTest(kTestFontDir "Bold.ttf")); + MinikinFontForTest::createFromFile(kTestFontDir "Bold.ttf")); MinikinAutoUnref fontC( - new MinikinFontForTest(kTestFontDir "BoldItalic.ttf")); + MinikinFontForTest::createFromFile(kTestFontDir "BoldItalic.ttf")); android::AutoMutex _l(gMinikinLock); // Never return NULL. @@ -66,7 +66,7 @@ TEST_F(HbFontCacheTest, getHbFontLockedTest) { TEST_F(HbFontCacheTest, purgeCacheTest) { MinikinAutoUnref minikinFont( - new MinikinFontForTest(kTestFontDir "Regular.ttf")); + MinikinFontForTest::createFromFile(kTestFontDir "Regular.ttf")); android::AutoMutex _l(gMinikinLock); hb_font_t* font = getHbFontLocked(minikinFont.get()); diff --git a/engine/src/flutter/tests/util/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp index b675620e258..246c87231af 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.cpp +++ b/engine/src/flutter/tests/util/FontTestUtils.cpp @@ -77,11 +77,12 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { if (index == nullptr) { MinikinAutoUnref - minikinFont(new MinikinFontForTest(fontPath)); + minikinFont(MinikinFontForTest::createFromFile(fontPath)); family->addFont(minikinFont.get(), FontStyle(weight, italic)); } else { MinikinAutoUnref - minikinFont(new MinikinFontForTest(fontPath, atoi((const char*)index))); + minikinFont(MinikinFontForTest::createFromFileWithIndex(fontPath, + atoi((const char*)index))); family->addFont(minikinFont.get(), FontStyle(weight, italic)); } } diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.cpp b/engine/src/flutter/tests/util/MinikinFontForTest.cpp index db4b8333f8b..807b234296e 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/util/MinikinFontForTest.cpp @@ -18,31 +18,31 @@ #include +#include + #include -#include -#include -#include namespace minikin { -static int uniqueId = 0; // TODO: make thread safe if necessary. - -MinikinFontForTest::MinikinFontForTest(const std::string& font_path, int index) : - MinikinFont(uniqueId++), - mFontPath(font_path), - mFontIndex(index) { - int fd = open(font_path.c_str(), O_RDONLY); - LOG_ALWAYS_FATAL_IF(fd == -1); - struct stat st = {}; - LOG_ALWAYS_FATAL_IF(fstat(fd, &st) != 0); - mFontSize = st.st_size; - mFontData = mmap(NULL, mFontSize, PROT_READ, MAP_SHARED, fd, 0); - LOG_ALWAYS_FATAL_IF(mFontData == nullptr); - close(fd); +// static +MinikinFontForTest* MinikinFontForTest::createFromFile(const std::string& font_path) { + sk_sp typeface = SkTypeface::MakeFromFile(font_path.c_str()); + MinikinFontForTest* font = new MinikinFontForTest(font_path, std::move(typeface)); + return font; } -MinikinFontForTest::~MinikinFontForTest() { - munmap(mFontData, mFontSize); +// static +MinikinFontForTest* MinikinFontForTest::createFromFileWithIndex(const std::string& font_path, + int index) { + sk_sp typeface = SkTypeface::MakeFromFile(font_path.c_str(), index); + MinikinFontForTest* font = new MinikinFontForTest(font_path, std::move(typeface)); + return font; +} + +MinikinFontForTest::MinikinFontForTest(const std::string& font_path, sk_sp typeface) : + MinikinFont(typeface->uniqueID()), + mTypeface(std::move(typeface)), + mFontPath(font_path) { } float MinikinFontForTest::GetHorizontalAdvance(uint32_t /* glyph_id */, @@ -56,4 +56,20 @@ void MinikinFontForTest::GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph_ LOG_ALWAYS_FATAL("MinikinFontForTest::GetBounds is not yet implemented"); } +const void* MinikinFontForTest::GetTable(uint32_t tag, size_t* size, + MinikinDestroyFunc* destroy) { + const size_t tableSize = mTypeface->getTableSize(tag); + *size = tableSize; + if (tableSize == 0) { + return nullptr; + } + void* buf = malloc(tableSize); + if (buf == nullptr) { + return nullptr; + } + mTypeface->getTableData(tag, 0, tableSize, buf); + *destroy = free; + return buf; +} + } // namespace minikin diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.h b/engine/src/flutter/tests/util/MinikinFontForTest.h index ee0eadbe0c2..423792f8d54 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.h +++ b/engine/src/flutter/tests/util/MinikinFontForTest.h @@ -18,6 +18,7 @@ #define MINIKIN_TEST_MINIKIN_FONT_FOR_TEST_H #include +#include class SkTypeface; @@ -25,28 +26,27 @@ namespace minikin { class MinikinFontForTest : public MinikinFont { public: - MinikinFontForTest(const std::string& font_path, int index); - MinikinFontForTest(const std::string& font_path) : MinikinFontForTest(font_path, 0) {} - virtual ~MinikinFontForTest(); + MinikinFontForTest(const std::string& font_path, sk_sp typeface); + + // Helper function for creating MinikinFontForTest instance from font file. + // Calller need to unref returned object. + static MinikinFontForTest* createFromFile(const std::string& font_path); + static MinikinFontForTest* createFromFileWithIndex(const std::string& font_path, int index); // MinikinFont overrides. float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const; void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint& paint) const; + const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); const std::string& fontPath() const { return mFontPath; } - const void* GetFontData() const { return mFontData; } - size_t GetFontSize() const { return mFontSize; } - int GetFontIndex() const { return mFontIndex; } private: MinikinFontForTest() = delete; MinikinFontForTest(const MinikinFontForTest&) = delete; MinikinFontForTest& operator=(MinikinFontForTest&) = delete; + sk_sp mTypeface; const std::string mFontPath; - const int mFontIndex; - void* mFontData; - size_t mFontSize; }; } // namespace minikin From 6b9c9dec1fbd2f0440ea2a8de06a9827afb2e47e Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 15 Nov 2016 19:02:52 +0900 Subject: [PATCH 205/364] Implement word spacing Add a wordSpacing paint parameter, which will be used for justification. Bug: 31707212 Test: ran minikin_tests Change-Id: I91224ab8ef882ac0c87425c28ab731fead283612 --- engine/src/flutter/include/minikin/Layout.h | 2 +- .../src/flutter/include/minikin/MinikinFont.h | 5 +- engine/src/flutter/libs/minikin/Layout.cpp | 29 +- .../src/flutter/libs/minikin/LayoutUtils.cpp | 15 +- engine/src/flutter/libs/minikin/LayoutUtils.h | 5 + engine/src/flutter/tests/unittest/Android.mk | 2 + .../src/flutter/tests/unittest/LayoutTest.cpp | 343 ++++++++++++++++++ .../flutter/tests/util/MinikinFontForTest.cpp | 12 +- 8 files changed, 395 insertions(+), 18 deletions(-) create mode 100644 engine/src/flutter/tests/unittest/LayoutTest.cpp diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 87d5e0534ba..625e05c433c 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -145,7 +145,7 @@ private: bool isRtl, LayoutContext* ctx); // Append another layout (for example, cached value) into this one - void appendLayout(Layout* src, size_t start); + void appendLayout(Layout* src, size_t start, float extraAdvance); std::vector mGlyphs; std::vector mAdvances; diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index ac9235be8d3..18848535d2d 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -45,8 +45,8 @@ class MinikinFont; // Possibly move into own .h file? // Note: if you add a field here, either add it to LayoutCacheKey or to skipCache() struct MinikinPaint { - MinikinPaint() : font(0), size(0), scaleX(0), skewX(0), letterSpacing(0), paintFlags(0), - fakery(), fontFeatureSettings() { } + MinikinPaint() : font(0), size(0), scaleX(0), skewX(0), letterSpacing(0), wordSpacing(0), + paintFlags(0), fakery(), hyphenEdit(), fontFeatureSettings() { } bool skipCache() const { return !fontFeatureSettings.empty(); @@ -57,6 +57,7 @@ struct MinikinPaint { float scaleX; float skewX; float letterSpacing; + float wordSpacing; uint32_t paintFlags; FontFakery fakery; HyphenEdit hyphenEdit; diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 452718217ff..a365411d8f9 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -653,27 +653,38 @@ float Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size Layout* layout, float* advances) { LayoutCache& cache = LayoutEngine::getInstance().layoutCache; LayoutCacheKey key(collection, ctx->paint, ctx->style, buf, start, count, bufSize, isRtl); - bool skipCache = ctx->paint.skipCache(); - if (skipCache) { + + float wordSpacing = count == 1 && isWordSpace(buf[start]) ? ctx->paint.wordSpacing : 0; + + float advance; + if (ctx->paint.skipCache()) { Layout layoutForWord; key.doLayout(&layoutForWord, ctx, collection); if (layout) { - layout->appendLayout(&layoutForWord, bufStart); + layout->appendLayout(&layoutForWord, bufStart, wordSpacing); } if (advances) { layoutForWord.getAdvances(advances); } - return layoutForWord.getAdvance(); + advance = layoutForWord.getAdvance(); } else { Layout* layoutForWord = cache.get(key, ctx, collection); if (layout) { - layout->appendLayout(layoutForWord, bufStart); + layout->appendLayout(layoutForWord, bufStart, wordSpacing); } if (advances) { layoutForWord->getAdvances(advances); } - return layoutForWord->getAdvance(); + advance = layoutForWord->getAdvance(); } + + if (wordSpacing != 0) { + advance += wordSpacing; + if (advances) { + advances[0] += wordSpacing; + } + } + return advance; } static void addFeatures(const string &str, vector* features) { @@ -855,7 +866,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t mAdvance = x; } -void Layout::appendLayout(Layout* src, size_t start) { +void Layout::appendLayout(Layout* src, size_t start, float extraAdvance) { int fontMapStack[16]; int* fontMap; if (src->mFaces.size() < sizeof(fontMapStack) / sizeof(fontMapStack[0])) { @@ -879,11 +890,13 @@ void Layout::appendLayout(Layout* src, size_t start) { } for (size_t i = 0; i < src->mAdvances.size(); i++) { mAdvances[i + start] = src->mAdvances[i]; + if (i == 0) + mAdvances[i + start] += extraAdvance; } MinikinRect srcBounds(src->mBounds); srcBounds.offset(x0, 0); mBounds.join(srcBounds); - mAdvance += src->mAdvance; + mAdvance += src->mAdvance + extraAdvance; if (fontMap != fontMapStack) { delete[] fontMap; diff --git a/engine/src/flutter/libs/minikin/LayoutUtils.cpp b/engine/src/flutter/libs/minikin/LayoutUtils.cpp index 4e59afd6b20..a3238d448d3 100644 --- a/engine/src/flutter/libs/minikin/LayoutUtils.cpp +++ b/engine/src/flutter/libs/minikin/LayoutUtils.cpp @@ -20,13 +20,22 @@ namespace minikin { +const uint16_t CHAR_NBSP = 0x00A0; + +/* + * Determine whether the code unit is a word space for the purposes of justification. + */ +bool isWordSpace(uint16_t code_unit) { + return code_unit == ' ' || code_unit == CHAR_NBSP; +} + /** * For the purpose of layout, a word break is a boundary with no * kerning or complex script processing. This is necessarily a * heuristic, but should be accurate most of the time. */ -static bool isWordBreakAfter(int c) { - if (c == ' ' || (c >= 0x2000 && c <= 0x200a) || c == 0x3000) { +static bool isWordBreakAfter(uint16_t c) { + if (isWordSpace(c) || (c >= 0x2000 && c <= 0x200a) || c == 0x3000) { // spaces return true; } @@ -34,7 +43,7 @@ static bool isWordBreakAfter(int c) { return false; } -static bool isWordBreakBefore(int c) { +static bool isWordBreakBefore(uint16_t c) { // CJK ideographs (and yijing hexagram symbols) return isWordBreakAfter(c) || (c >= 0x3400 && c <= 0x9fff); } diff --git a/engine/src/flutter/libs/minikin/LayoutUtils.h b/engine/src/flutter/libs/minikin/LayoutUtils.h index f35e843cfa5..b89004cf19f 100644 --- a/engine/src/flutter/libs/minikin/LayoutUtils.h +++ b/engine/src/flutter/libs/minikin/LayoutUtils.h @@ -21,6 +21,11 @@ namespace minikin { +/* + * Determine whether the code unit is a word space for the purposes of justification. + */ +bool isWordSpace(uint16_t code_unit); + /** * Return offset of previous word break. It is either < offset or == 0. * diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index a81d17cca7e..61d845b01b1 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -81,6 +81,7 @@ LOCAL_SRC_FILES += \ HbFontCacheTest.cpp \ MinikinInternalTest.cpp \ GraphemeBreakTests.cpp \ + LayoutTest.cpp \ LayoutUtilsTest.cpp \ UnicodeUtilsTest.cpp \ WordBreakerTests.cpp @@ -88,6 +89,7 @@ LOCAL_SRC_FILES += \ LOCAL_C_INCLUDES := \ $(LOCAL_PATH)/../../libs/minikin/ \ $(LOCAL_PATH)/../util \ + external/freetype/include \ external/harfbuzz_ng/src \ external/libxml2/include \ external/skia/src/core diff --git a/engine/src/flutter/tests/unittest/LayoutTest.cpp b/engine/src/flutter/tests/unittest/LayoutTest.cpp new file mode 100644 index 00000000000..c023625b16f --- /dev/null +++ b/engine/src/flutter/tests/unittest/LayoutTest.cpp @@ -0,0 +1,343 @@ +/* + * Copyright (C) 2016 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 + +#include "ICUTestBase.h" +#include "minikin/FontCollection.h" +#include "minikin/Layout.h" +#include "../util/FontTestUtils.h" +#include "../util/UnicodeUtils.h" + +const char* SYSTEM_FONT_PATH = "/system/fonts/"; +const char* SYSTEM_FONT_XML = "/system/etc/fonts.xml"; + +namespace minikin { + +const float UNTOUCHED_MARKER = 1e+38; + +static void expectAdvances(std::vector expected, float* advances, size_t length) { + EXPECT_LE(expected.size(), length); + for (size_t i = 0; i < expected.size(); ++i) { + EXPECT_EQ(expected[i], advances[i]) + << i << "th element is different. Expected: " << expected[i] + << ", Actual: " << advances[i]; + } + EXPECT_EQ(UNTOUCHED_MARKER, advances[expected.size()]); +} + +static void resetAdvances(float* advances, size_t length) { + for (size_t i = 0; i < length; ++i) { + advances[i] = UNTOUCHED_MARKER; + } +} + +class LayoutTest : public ICUTestBase { +protected: + LayoutTest() : mCollection(nullptr) { + } + + virtual ~LayoutTest() {} + + virtual void SetUp() override { + mCollection = getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML); + } + + virtual void TearDown() override { + mCollection->Unref(); + } + + FontCollection* mCollection; +}; + +TEST_F(LayoutTest, doLayoutTest) { + MinikinPaint paint; + MinikinRect rect; + const size_t kMaxAdvanceLength = 32; + float advances[kMaxAdvanceLength]; + std::vector expectedValues; + + Layout layout; + layout.setFontCollection(mCollection); + std::vector text; + + // The mock implementation returns 10.0f advance and 0,0-10x10 bounds for all glyph. + { + SCOPED_TRACE("one word"); + text = utf8ToUtf16("oneword"); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(70.0f, layout.getAdvance()); + layout.getBounds(&rect); + EXPECT_EQ(0.0f, rect.mLeft); + EXPECT_EQ(0.0f, rect.mTop); + EXPECT_EQ(70.0f, rect.mRight); + EXPECT_EQ(10.0f, rect.mBottom); + resetAdvances(advances, kMaxAdvanceLength); + layout.getAdvances(advances); + expectedValues.resize(text.size()); + for (size_t i = 0; i < expectedValues.size(); ++i) { + expectedValues[i] = 10.0f; + } + expectAdvances(expectedValues, advances, kMaxAdvanceLength); + } + { + SCOPED_TRACE("two words"); + text = utf8ToUtf16("two words"); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(90.0f, layout.getAdvance()); + layout.getBounds(&rect); + EXPECT_EQ(0.0f, rect.mLeft); + EXPECT_EQ(0.0f, rect.mTop); + EXPECT_EQ(90.0f, rect.mRight); + EXPECT_EQ(10.0f, rect.mBottom); + resetAdvances(advances, kMaxAdvanceLength); + layout.getAdvances(advances); + expectedValues.resize(text.size()); + for (size_t i = 0; i < expectedValues.size(); ++i) { + expectedValues[i] = 10.0f; + } + expectAdvances(expectedValues, advances, kMaxAdvanceLength); + } + { + SCOPED_TRACE("three words"); + text = utf8ToUtf16("three words test"); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(160.0f, layout.getAdvance()); + layout.getBounds(&rect); + EXPECT_EQ(0.0f, rect.mLeft); + EXPECT_EQ(0.0f, rect.mTop); + EXPECT_EQ(160.0f, rect.mRight); + EXPECT_EQ(10.0f, rect.mBottom); + resetAdvances(advances, kMaxAdvanceLength); + layout.getAdvances(advances); + expectedValues.resize(text.size()); + for (size_t i = 0; i < expectedValues.size(); ++i) { + expectedValues[i] = 10.0f; + } + expectAdvances(expectedValues, advances, kMaxAdvanceLength); + } + { + SCOPED_TRACE("two spaces"); + text = utf8ToUtf16("two spaces"); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(110.0f, layout.getAdvance()); + layout.getBounds(&rect); + EXPECT_EQ(0.0f, rect.mLeft); + EXPECT_EQ(0.0f, rect.mTop); + EXPECT_EQ(110.0f, rect.mRight); + EXPECT_EQ(10.0f, rect.mBottom); + resetAdvances(advances, kMaxAdvanceLength); + layout.getAdvances(advances); + expectedValues.resize(text.size()); + for (size_t i = 0; i < expectedValues.size(); ++i) { + expectedValues[i] = 10.0f; + } + expectAdvances(expectedValues, advances, kMaxAdvanceLength); + } +} + +TEST_F(LayoutTest, doLayoutTest_wordSpacing) { + MinikinPaint paint; + MinikinRect rect; + const size_t kMaxAdvanceLength = 32; + float advances[kMaxAdvanceLength]; + std::vector expectedValues; + std::vector text; + + Layout layout; + layout.setFontCollection(mCollection); + + paint.wordSpacing = 5.0f; + + // The mock implementation returns 10.0f advance and 0,0-10x10 bounds for all glyph. + { + SCOPED_TRACE("one word"); + text = utf8ToUtf16("oneword"); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(70.0f, layout.getAdvance()); + layout.getBounds(&rect); + EXPECT_EQ(0.0f, rect.mLeft); + EXPECT_EQ(0.0f, rect.mTop); + EXPECT_EQ(70.0f, rect.mRight); + EXPECT_EQ(10.0f, rect.mBottom); + resetAdvances(advances, kMaxAdvanceLength); + layout.getAdvances(advances); + expectedValues.resize(text.size()); + for (size_t i = 0; i < expectedValues.size(); ++i) { + expectedValues[i] = 10.0f; + } + expectAdvances(expectedValues, advances, kMaxAdvanceLength); + } + { + SCOPED_TRACE("two words"); + text = utf8ToUtf16("two words"); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(95.0f, layout.getAdvance()); + layout.getBounds(&rect); + EXPECT_EQ(0.0f, rect.mLeft); + EXPECT_EQ(0.0f, rect.mTop); + EXPECT_EQ(95.0f, rect.mRight); + EXPECT_EQ(10.0f, rect.mBottom); + resetAdvances(advances, kMaxAdvanceLength); + layout.getAdvances(advances); + EXPECT_EQ(UNTOUCHED_MARKER, advances[text.size()]); + resetAdvances(advances, kMaxAdvanceLength); + layout.getAdvances(advances); + expectedValues.resize(text.size()); + for (size_t i = 0; i < expectedValues.size(); ++i) { + expectedValues[i] = 10.0f; + } + expectedValues[3] = 15.0f; + expectAdvances(expectedValues, advances, kMaxAdvanceLength); + } + { + SCOPED_TRACE("three words test"); + text = utf8ToUtf16("three words test"); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(170.0f, layout.getAdvance()); + layout.getBounds(&rect); + EXPECT_EQ(0.0f, rect.mLeft); + EXPECT_EQ(0.0f, rect.mTop); + EXPECT_EQ(170.0f, rect.mRight); + EXPECT_EQ(10.0f, rect.mBottom); + resetAdvances(advances, kMaxAdvanceLength); + layout.getAdvances(advances); + expectedValues.resize(text.size()); + for (size_t i = 0; i < expectedValues.size(); ++i) { + expectedValues[i] = 10.0f; + } + expectedValues[5] = 15.0f; + expectedValues[11] = 15.0f; + expectAdvances(expectedValues, advances, kMaxAdvanceLength); + } + { + SCOPED_TRACE("two spaces"); + text = utf8ToUtf16("two spaces"); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(120.0f, layout.getAdvance()); + layout.getBounds(&rect); + EXPECT_EQ(0.0f, rect.mLeft); + EXPECT_EQ(0.0f, rect.mTop); + EXPECT_EQ(120.0f, rect.mRight); + EXPECT_EQ(10.0f, rect.mBottom); + resetAdvances(advances, kMaxAdvanceLength); + layout.getAdvances(advances); + expectedValues.resize(text.size()); + for (size_t i = 0; i < expectedValues.size(); ++i) { + expectedValues[i] = 10.0f; + } + expectedValues[3] = 15.0f; + expectedValues[4] = 15.0f; + expectAdvances(expectedValues, advances, kMaxAdvanceLength); + } +} + +TEST_F(LayoutTest, doLayoutTest_negativeWordSpacing) { + MinikinPaint paint; + MinikinRect rect; + const size_t kMaxAdvanceLength = 32; + float advances[kMaxAdvanceLength]; + std::vector expectedValues; + + Layout layout; + layout.setFontCollection(mCollection); + std::vector text; + + // Negative word spacing also should work. + paint.wordSpacing = -5.0f; + + { + SCOPED_TRACE("one word"); + text = utf8ToUtf16("oneword"); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(70.0f, layout.getAdvance()); + layout.getBounds(&rect); + EXPECT_EQ(0.0f, rect.mLeft); + EXPECT_EQ(0.0f, rect.mTop); + EXPECT_EQ(70.0f, rect.mRight); + EXPECT_EQ(10.0f, rect.mBottom); + resetAdvances(advances, kMaxAdvanceLength); + layout.getAdvances(advances); + expectedValues.resize(text.size()); + for (size_t i = 0; i < expectedValues.size(); ++i) { + expectedValues[i] = 10.0f; + } + expectAdvances(expectedValues, advances, kMaxAdvanceLength); + } + { + SCOPED_TRACE("two words"); + text = utf8ToUtf16("two words"); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(85.0f, layout.getAdvance()); + layout.getBounds(&rect); + EXPECT_EQ(0.0f, rect.mLeft); + EXPECT_EQ(0.0f, rect.mTop); + EXPECT_EQ(85.0f, rect.mRight); + EXPECT_EQ(10.0f, rect.mBottom); + resetAdvances(advances, kMaxAdvanceLength); + layout.getAdvances(advances); + expectedValues.resize(text.size()); + for (size_t i = 0; i < expectedValues.size(); ++i) { + expectedValues[i] = 10.0f; + } + expectedValues[3] = 5.0f; + expectAdvances(expectedValues, advances, kMaxAdvanceLength); + } + { + SCOPED_TRACE("three words"); + text = utf8ToUtf16("three word test"); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(140.0f, layout.getAdvance()); + layout.getBounds(&rect); + EXPECT_EQ(0.0f, rect.mLeft); + EXPECT_EQ(0.0f, rect.mTop); + EXPECT_EQ(140.0f, rect.mRight); + EXPECT_EQ(10.0f, rect.mBottom); + resetAdvances(advances, kMaxAdvanceLength); + layout.getAdvances(advances); + expectedValues.resize(text.size()); + for (size_t i = 0; i < expectedValues.size(); ++i) { + expectedValues[i] = 10.0f; + } + expectedValues[5] = 5.0f; + expectedValues[10] = 5.0f; + expectAdvances(expectedValues, advances, kMaxAdvanceLength); + } + { + SCOPED_TRACE("two spaces"); + text = utf8ToUtf16("two spaces"); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(100.0f, layout.getAdvance()); + layout.getBounds(&rect); + EXPECT_EQ(0.0f, rect.mLeft); + EXPECT_EQ(0.0f, rect.mTop); + EXPECT_EQ(100.0f, rect.mRight); + EXPECT_EQ(10.0f, rect.mBottom); + resetAdvances(advances, kMaxAdvanceLength); + layout.getAdvances(advances); + expectedValues.resize(text.size()); + for (size_t i = 0; i < expectedValues.size(); ++i) { + expectedValues[i] = 10.0f; + } + expectedValues[3] = 5.0f; + expectedValues[4] = 5.0f; + expectAdvances(expectedValues, advances, kMaxAdvanceLength); + } +} + +// TODO: Add more test cases, e.g. measure text, letter spacing. + +} // namespace minikin diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.cpp b/engine/src/flutter/tests/util/MinikinFontForTest.cpp index 807b234296e..fd5f5645064 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/util/MinikinFontForTest.cpp @@ -47,13 +47,17 @@ MinikinFontForTest::MinikinFontForTest(const std::string& font_path, sk_spmLeft = 0.0f; + bounds->mTop = 0.0f; + bounds->mRight = 10.0f; + bounds->mBottom = 10.0f; } const void* MinikinFontForTest::GetTable(uint32_t tag, size_t* size, From 7c620ba62dc2c7e6e055c34967db6e16164468da Mon Sep 17 00:00:00 2001 From: Martijn Coenen Date: Mon, 14 Nov 2016 16:47:18 +0100 Subject: [PATCH 206/364] Fix calls to deprecated range_x. Test: fixes master build. Change-Id: I8b2822d310c0cf423b15834e6d6ae3a9ea64233b --- engine/src/flutter/tests/perftests/FontCollection.cpp | 6 +++--- engine/src/flutter/tests/perftests/GraphemeBreak.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/tests/perftests/FontCollection.cpp b/engine/src/flutter/tests/perftests/FontCollection.cpp index 490f5d85fea..a54607d1833 100644 --- a/engine/src/flutter/tests/perftests/FontCollection.cpp +++ b/engine/src/flutter/tests/perftests/FontCollection.cpp @@ -30,8 +30,8 @@ static void BM_FontCollection_hasVariationSelector(benchmark::State& state) { MinikinAutoUnref collection( getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); - uint32_t baseCp = state.range_x(); - uint32_t vsCp = state.range_y(); + uint32_t baseCp = state.range(0); + uint32_t vsCp = state.range(1); char titleBuffer[64]; snprintf(titleBuffer, 64, "hasVariationSelector U+%04X,U+%04X", baseCp, vsCp); @@ -66,7 +66,7 @@ static void BM_FontCollection_itemize(benchmark::State& state) { MinikinAutoUnref collection( getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); - size_t testIndex = state.range_x(); + size_t testIndex = state.range(0); state.SetLabel("Itemize: " + ITEMIZE_TEST_CASES[testIndex].labelText); uint16_t buffer[64]; diff --git a/engine/src/flutter/tests/perftests/GraphemeBreak.cpp b/engine/src/flutter/tests/perftests/GraphemeBreak.cpp index 4db8f75d3da..cfee7c642c1 100644 --- a/engine/src/flutter/tests/perftests/GraphemeBreak.cpp +++ b/engine/src/flutter/tests/perftests/GraphemeBreak.cpp @@ -36,7 +36,7 @@ static void BM_GraphemeBreak_Ascii(benchmark::State& state) { uint16_t buffer[12]; ParseUnicode(buffer, 12, ASCII_TEST_STR, &result_size, nullptr); LOG_ALWAYS_FATAL_IF(result_size != 12); - const size_t testIndex = state.range_x(); + const size_t testIndex = state.range(0); while (state.KeepRunning()) { GraphemeBreak::isGraphemeBreak(buffer, 0, result_size, testIndex); } @@ -51,7 +51,7 @@ static void BM_GraphemeBreak_Emoji(benchmark::State& state) { uint16_t buffer[12]; ParseUnicode(buffer, 12, EMOJI_TEST_STR, &result_size, nullptr); LOG_ALWAYS_FATAL_IF(result_size != 12); - const size_t testIndex = state.range_x(); + const size_t testIndex = state.range(0); while (state.KeepRunning()) { GraphemeBreak::isGraphemeBreak(buffer, 0, result_size, testIndex); } @@ -66,7 +66,7 @@ static void BM_GraphemeBreak_Emoji_Flags(benchmark::State& state) { uint16_t buffer[12]; ParseUnicode(buffer, 12, FLAGS_TEST_STR, &result_size, nullptr); LOG_ALWAYS_FATAL_IF(result_size != 12); - const size_t testIndex = state.range_x(); + const size_t testIndex = state.range(0); while (state.KeepRunning()) { GraphemeBreak::isGraphemeBreak(buffer, 0, result_size, testIndex); } From 964f053ea478eb5c7441f43c0d49996353e0211f Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 18 Oct 2016 11:21:59 +0900 Subject: [PATCH 207/364] Clean Up: Removing unused interface GetTable from MinikinFont. This is 2nd attempt of Ifcd7a348d7fb5af081192899dbcdfc7fb4eebbf9 After Id766ab16a8d342bf7322a90e076e801271d527d4, GetTable is no longer used in production due to poor performance and it is now only used in tests. This CL removes GetTable interface from MinikinFont and update tests code to use new interfaces, GetFontData, GetFontSize and GetFontIndex. Bug: 27860101 Test: Manually done Change-Id: Ib48973ff25cdc61a4c666d28128266df0aaea83e --- .../src/flutter/include/minikin/MinikinFont.h | 2 - .../src/flutter/libs/minikin/HbFontCache.cpp | 31 +++-------- .../unittest/FontCollectionItemizeTest.cpp | 20 +++---- .../tests/unittest/FontCollectionTest.cpp | 2 +- .../flutter/tests/unittest/FontFamilyTest.cpp | 4 +- .../tests/unittest/HbFontCacheTest.cpp | 8 +-- .../src/flutter/tests/util/FontTestUtils.cpp | 5 +- .../flutter/tests/util/MinikinFontForTest.cpp | 54 +++++++------------ .../flutter/tests/util/MinikinFontForTest.h | 18 +++---- 9 files changed, 53 insertions(+), 91 deletions(-) diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 18848535d2d..353edd6566e 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -110,8 +110,6 @@ public: virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint &paint) const = 0; - virtual const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) = 0; - // Override if font can provide access to raw data virtual const void* GetFontData() const { return nullptr; diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index 45c3f5807ba..3c6619d10a4 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -28,22 +28,6 @@ namespace minikin { -static hb_blob_t* referenceTable(hb_face_t* /* face */, hb_tag_t tag, void* userData) { - MinikinFont* font = reinterpret_cast(userData); - MinikinDestroyFunc destroy = 0; - size_t size = 0; - const void* buffer = font->GetTable(tag, &size, &destroy); - if (buffer == nullptr) { - return nullptr; - } -#ifdef VERBOSE_DEBUG - ALOGD("referenceTable %c%c%c%c length=%zd", - (tag >>24)&0xff, (tag>>16)&0xff, (tag>>8)&0xff, tag&0xff, size); -#endif - return hb_blob_create(reinterpret_cast(buffer), size, - HB_MEMORY_MODE_READONLY, const_cast(buffer), destroy); -} - class HbFontCache : private android::OnEntryRemoved { public: HbFontCache() : mCache(kMaxEntries) { @@ -119,15 +103,12 @@ hb_font_t* getHbFontLocked(MinikinFont* minikinFont) { hb_face_t* face; const void* buf = minikinFont->GetFontData(); - if (buf == nullptr) { - face = hb_face_create_for_tables(referenceTable, minikinFont, nullptr); - } else { - size_t size = minikinFont->GetFontSize(); - hb_blob_t* blob = hb_blob_create(reinterpret_cast(buf), size, - HB_MEMORY_MODE_READONLY, nullptr, nullptr); - face = hb_face_create(blob, minikinFont->GetFontIndex()); - hb_blob_destroy(blob); - } + size_t size = minikinFont->GetFontSize(); + hb_blob_t* blob = hb_blob_create(reinterpret_cast(buf), size, + HB_MEMORY_MODE_READONLY, nullptr, nullptr); + face = hb_face_create(blob, minikinFont->GetFontIndex()); + hb_blob_destroy(blob); + hb_font_t* parent_font = hb_font_create(face); hb_ot_font_set_funcs(parent_font); diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 978ba9f499f..02bc03bbe6b 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -669,12 +669,12 @@ TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { std::vector families; FontFamily* family1 = new FontFamily(VARIANT_DEFAULT); - MinikinAutoUnref font(MinikinFontForTest::createFromFile(kLatinFont)); + MinikinAutoUnref font(new MinikinFontForTest(kLatinFont)); family1->addFont(font.get()); families.push_back(family1); FontFamily* family2 = new FontFamily(VARIANT_DEFAULT); - MinikinAutoUnref font2(MinikinFontForTest::createFromFile(kVSTestFont)); + MinikinAutoUnref font2(new MinikinFontForTest(kVSTestFont)); family2->addFont(font2.get()); families.push_back(family2); @@ -800,7 +800,7 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { FontFamily* firstFamily = new FontFamily( FontStyle::registerLanguageList("und"), 0 /* variant */); MinikinAutoUnref firstFamilyMinikinFont( - MinikinFontForTest::createFromFile(kNoGlyphFont)); + new MinikinFontForTest(kNoGlyphFont)); firstFamily->addFont(firstFamilyMinikinFont.get()); families.push_back(firstFamily); @@ -812,7 +812,7 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { for (size_t i = 0; i < testCase.fontLanguages.size(); ++i) { FontFamily* family = new FontFamily( FontStyle::registerLanguageList(testCase.fontLanguages[i]), 0 /* variant */); - MinikinAutoUnref minikin_font(MinikinFontForTest::createFromFile(kJAFont)); + MinikinAutoUnref minikin_font(new MinikinFontForTest(kJAFont)); family->addFont(minikin_font.get()); families.push_back(family); fontLangIdxMap.insert(std::make_pair(minikin_font.get(), i)); @@ -1399,9 +1399,9 @@ TEST_F(FontCollectionItemizeTest, itemize_genderBalancedEmoji) { TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS) { const FontStyle kDefaultFontStyle; - MinikinAutoUnref dummyFont(MinikinFontForTest::createFromFile(kNoGlyphFont)); - MinikinAutoUnref fontA(MinikinFontForTest::createFromFile(kZH_HansFont)); - MinikinAutoUnref fontB(MinikinFontForTest::createFromFile(kZH_HansFont)); + MinikinAutoUnref dummyFont(new MinikinFontForTest(kNoGlyphFont)); + MinikinAutoUnref fontA(new MinikinFontForTest(kZH_HansFont)); + MinikinAutoUnref fontB(new MinikinFontForTest(kZH_HansFont)); MinikinAutoUnref dummyFamily(new FontFamily()); MinikinAutoUnref familyA(new FontFamily()); @@ -1433,11 +1433,11 @@ TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS) { TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS2) { const FontStyle kDefaultFontStyle; - MinikinAutoUnref dummyFont(MinikinFontForTest::createFromFile(kNoGlyphFont)); + MinikinAutoUnref dummyFont(new MinikinFontForTest(kNoGlyphFont)); MinikinAutoUnref hasCmapFormat14Font( - MinikinFontForTest::createFromFile(kHasCmapFormat14Font)); + new MinikinFontForTest(kHasCmapFormat14Font)); MinikinAutoUnref noCmapFormat14Font( - MinikinFontForTest::createFromFile(kNoCmapFormat14Font)); + new MinikinFontForTest(kNoCmapFormat14Font)); MinikinAutoUnref dummyFamily(new FontFamily()); MinikinAutoUnref hasCmapFormat14Family(new FontFamily()); diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index ef2da66b2b3..62d2f022fa3 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -58,7 +58,7 @@ void expectVSGlyphs(const FontCollection* fc, uint32_t codepoint, const std::set TEST(FontCollectionTest, hasVariationSelectorTest) { MinikinAutoUnref family(new FontFamily()); - MinikinAutoUnref font(MinikinFontForTest::createFromFile(kVsTestFont)); + MinikinAutoUnref font(new MinikinFontForTest(kVsTestFont)); family->addFont(font.get()); std::vector families({family.get()}); MinikinAutoUnref fc(new FontCollection(families)); diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 69fef23da82..4aaa601a23e 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -351,7 +351,7 @@ void expectVSGlyphs(FontFamily* family, uint32_t codepoint, const std::set - minikinFont(MinikinFontForTest::createFromFile(kVsTestFont)); + minikinFont(new MinikinFontForTest(kVsTestFont)); MinikinAutoUnref family(new FontFamily); family->addFont(minikinFont.get()); @@ -405,7 +405,7 @@ TEST_F(FontFamilyTest, hasVSTableTest) { "Font " + testCase.fontPath + " shouldn't have a variation sequence table."); MinikinAutoUnref minikinFont( - MinikinFontForTest::createFromFile(testCase.fontPath)); + new MinikinFontForTest(testCase.fontPath)); MinikinAutoUnref family(new FontFamily); family->addFont(minikinFont.get()); android::AutoMutex _l(gMinikinLock); diff --git a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp index aa4cb34c053..5e560430c2f 100644 --- a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp @@ -38,13 +38,13 @@ public: TEST_F(HbFontCacheTest, getHbFontLockedTest) { MinikinAutoUnref fontA( - MinikinFontForTest::createFromFile(kTestFontDir "Regular.ttf")); + new MinikinFontForTest(kTestFontDir "Regular.ttf")); MinikinAutoUnref fontB( - MinikinFontForTest::createFromFile(kTestFontDir "Bold.ttf")); + new MinikinFontForTest(kTestFontDir "Bold.ttf")); MinikinAutoUnref fontC( - MinikinFontForTest::createFromFile(kTestFontDir "BoldItalic.ttf")); + new MinikinFontForTest(kTestFontDir "BoldItalic.ttf")); android::AutoMutex _l(gMinikinLock); // Never return NULL. @@ -66,7 +66,7 @@ TEST_F(HbFontCacheTest, getHbFontLockedTest) { TEST_F(HbFontCacheTest, purgeCacheTest) { MinikinAutoUnref minikinFont( - MinikinFontForTest::createFromFile(kTestFontDir "Regular.ttf")); + new MinikinFontForTest(kTestFontDir "Regular.ttf")); android::AutoMutex _l(gMinikinLock); hb_font_t* font = getHbFontLocked(minikinFont.get()); diff --git a/engine/src/flutter/tests/util/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp index 246c87231af..b675620e258 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.cpp +++ b/engine/src/flutter/tests/util/FontTestUtils.cpp @@ -77,12 +77,11 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { if (index == nullptr) { MinikinAutoUnref - minikinFont(MinikinFontForTest::createFromFile(fontPath)); + minikinFont(new MinikinFontForTest(fontPath)); family->addFont(minikinFont.get(), FontStyle(weight, italic)); } else { MinikinAutoUnref - minikinFont(MinikinFontForTest::createFromFileWithIndex(fontPath, - atoi((const char*)index))); + minikinFont(new MinikinFontForTest(fontPath, atoi((const char*)index))); family->addFont(minikinFont.get(), FontStyle(weight, italic)); } } diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.cpp b/engine/src/flutter/tests/util/MinikinFontForTest.cpp index fd5f5645064..a6abc1e167c 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/util/MinikinFontForTest.cpp @@ -18,31 +18,31 @@ #include -#include - #include +#include +#include +#include namespace minikin { -// static -MinikinFontForTest* MinikinFontForTest::createFromFile(const std::string& font_path) { - sk_sp typeface = SkTypeface::MakeFromFile(font_path.c_str()); - MinikinFontForTest* font = new MinikinFontForTest(font_path, std::move(typeface)); - return font; +static int uniqueId = 0; // TODO: make thread safe if necessary. + +MinikinFontForTest::MinikinFontForTest(const std::string& font_path, int index) : + MinikinFont(uniqueId++), + mFontPath(font_path), + mFontIndex(index) { + int fd = open(font_path.c_str(), O_RDONLY); + LOG_ALWAYS_FATAL_IF(fd == -1); + struct stat st = {}; + LOG_ALWAYS_FATAL_IF(fstat(fd, &st) != 0); + mFontSize = st.st_size; + mFontData = mmap(NULL, mFontSize, PROT_READ, MAP_SHARED, fd, 0); + LOG_ALWAYS_FATAL_IF(mFontData == nullptr); + close(fd); } -// static -MinikinFontForTest* MinikinFontForTest::createFromFileWithIndex(const std::string& font_path, - int index) { - sk_sp typeface = SkTypeface::MakeFromFile(font_path.c_str(), index); - MinikinFontForTest* font = new MinikinFontForTest(font_path, std::move(typeface)); - return font; -} - -MinikinFontForTest::MinikinFontForTest(const std::string& font_path, sk_sp typeface) : - MinikinFont(typeface->uniqueID()), - mTypeface(std::move(typeface)), - mFontPath(font_path) { +MinikinFontForTest::~MinikinFontForTest() { + munmap(mFontData, mFontSize); } float MinikinFontForTest::GetHorizontalAdvance(uint32_t /* glyph_id */, @@ -60,20 +60,4 @@ void MinikinFontForTest::GetBounds(MinikinRect* bounds, uint32_t /* glyph_id */, bounds->mBottom = 10.0f; } -const void* MinikinFontForTest::GetTable(uint32_t tag, size_t* size, - MinikinDestroyFunc* destroy) { - const size_t tableSize = mTypeface->getTableSize(tag); - *size = tableSize; - if (tableSize == 0) { - return nullptr; - } - void* buf = malloc(tableSize); - if (buf == nullptr) { - return nullptr; - } - mTypeface->getTableData(tag, 0, tableSize, buf); - *destroy = free; - return buf; -} - } // namespace minikin diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.h b/engine/src/flutter/tests/util/MinikinFontForTest.h index 423792f8d54..ee0eadbe0c2 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.h +++ b/engine/src/flutter/tests/util/MinikinFontForTest.h @@ -18,7 +18,6 @@ #define MINIKIN_TEST_MINIKIN_FONT_FOR_TEST_H #include -#include class SkTypeface; @@ -26,27 +25,28 @@ namespace minikin { class MinikinFontForTest : public MinikinFont { public: - MinikinFontForTest(const std::string& font_path, sk_sp typeface); - - // Helper function for creating MinikinFontForTest instance from font file. - // Calller need to unref returned object. - static MinikinFontForTest* createFromFile(const std::string& font_path); - static MinikinFontForTest* createFromFileWithIndex(const std::string& font_path, int index); + MinikinFontForTest(const std::string& font_path, int index); + MinikinFontForTest(const std::string& font_path) : MinikinFontForTest(font_path, 0) {} + virtual ~MinikinFontForTest(); // MinikinFont overrides. float GetHorizontalAdvance(uint32_t glyph_id, const MinikinPaint &paint) const; void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint& paint) const; - const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); const std::string& fontPath() const { return mFontPath; } + const void* GetFontData() const { return mFontData; } + size_t GetFontSize() const { return mFontSize; } + int GetFontIndex() const { return mFontIndex; } private: MinikinFontForTest() = delete; MinikinFontForTest(const MinikinFontForTest&) = delete; MinikinFontForTest& operator=(MinikinFontForTest&) = delete; - sk_sp mTypeface; const std::string mFontPath; + const int mFontIndex; + void* mFontData; + size_t mFontSize; }; } // namespace minikin From 9bc8f531178afecfeb5b9de35118b8574b10f488 Mon Sep 17 00:00:00 2001 From: yirui Date: Mon, 12 Sep 2016 10:37:11 +0900 Subject: [PATCH 208/364] Parse Emoji subtag and store it to FontLanguage Parse Emoji subtag and store into 4 different styles: default, text, color and empty. Replace hasEmojiFlag function with getEmojiStyle to get effective status according to script and subtag. However, score calculation for the font selection needs to be completed in the next stage. No performance regression is observed with this CL. Bug: 31608997 Test: Done by unittests. Change-Id: I923243641c946248dd5a0aa9fb9c940515310d34 --- .../flutter/libs/minikin/FontCollection.cpp | 2 +- .../src/flutter/libs/minikin/FontFamily.cpp | 2 +- .../src/flutter/libs/minikin/FontLanguage.cpp | 45 ++++++- .../src/flutter/libs/minikin/FontLanguage.h | 40 ++++-- .../flutter/tests/perftests/FontLanguage.cpp | 7 ++ .../flutter/tests/unittest/FontFamilyTest.cpp | 119 +++++++++++++++++- .../src/flutter/tests/unittest/how_to_run.txt | 2 +- 7 files changed, 194 insertions(+), 23 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 19ad7523f7d..5bc3634e82c 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -219,7 +219,7 @@ uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, FontFamily* const FontLanguages& langs = FontLanguageListCache::getById(fontFamily->langId()); bool hasEmojiFlag = false; for (size_t i = 0; i < langs.size(); ++i) { - if (langs[i].hasEmojiFlag()) { + if (langs[i].getEmojiStyle() == FontLanguage::EMSTYLE_EMOJI) { hasEmojiFlag = true; break; } diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index f41a20a4f9e..f5f397681ae 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -161,7 +161,7 @@ FontStyle FontFamily::getStyle(size_t index) const { bool FontFamily::isColorEmojiFamily() const { const FontLanguages& languageList = FontLanguageListCache::getById(mLangId); for (size_t i = 0; i < languageList.size(); ++i) { - if (languageList[i].hasEmojiFlag()) { + if (languageList[i].getEmojiStyle() == FontLanguage::EMSTYLE_EMOJI) { return true; } } diff --git a/engine/src/flutter/libs/minikin/FontLanguage.cpp b/engine/src/flutter/libs/minikin/FontLanguage.cpp index 9cfa0aa664a..fca4cdbfcd5 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguage.cpp @@ -18,7 +18,9 @@ #include "FontLanguage.h" +#include #include +#include #include namespace minikin { @@ -27,6 +29,18 @@ namespace minikin { (((uint32_t)(c1)) << 24 | ((uint32_t)(c2)) << 16 | ((uint32_t)(c3)) << 8 | \ ((uint32_t)(c4))) +// Check if a language code supports emoji according to its subtag +static bool isEmojiSubtag(const char* buf, size_t bufLen, const char* subtag, size_t subtagLen) { + if (bufLen < subtagLen) { + return false; + } + if (strncmp(buf, subtag, subtagLen) != 0) { + return false; // no match between two strings + } + return (bufLen == subtagLen || buf[subtagLen] == '\0' || + buf[subtagLen] == '-' || buf[subtagLen] == '_'); +} + // Parse BCP 47 language identifier into internal structure FontLanguage::FontLanguage(const char* buf, size_t length) : FontLanguage() { size_t i; @@ -53,8 +67,34 @@ FontLanguage::FontLanguage(const char* buf, size_t length) : FontLanguage() { mScript = SCRIPT_TAG(buf[i], buf[i + 1], buf[i + 2], buf[i + 3]); } } - mSubScriptBits = scriptToSubScriptBits(mScript); + + if (mScript == SCRIPT_TAG('Z', 's', 'y', 'e')) { + mEmojiStyle = EMSTYLE_EMOJI; + } else if (mScript == SCRIPT_TAG('Z', 's', 'y', 'm')) { + mEmojiStyle = EMSTYLE_TEXT; + } + // 10 is the length of "-u-em-text", which is the shortest emoji subtag, + // unnecessary comparison can be avoided if total length is smaller than 10. + const size_t kMinSubtagLength = 10; + if (length < kMinSubtagLength) { + return; + } + + static const char kPrefix[] = "-u-em-"; + const char *pos = std::search(buf, buf + length, kPrefix, kPrefix + strlen(kPrefix)); + if (pos == buf + length) { + return; + } + pos += strlen(kPrefix); + const size_t remainingLength = length - (pos - buf); + if (isEmojiSubtag(pos, remainingLength, "emoji", 5)){ + mEmojiStyle = EMSTYLE_EMOJI; + } else if (isEmojiSubtag(pos, remainingLength, "text", 4)){ + mEmojiStyle = EMSTYLE_TEXT; + } else if (isEmojiSubtag(pos, remainingLength, "default", 7)){ + mEmojiStyle = EMSTYLE_DEFAULT; + } } //static @@ -95,9 +135,6 @@ uint8_t FontLanguage::scriptToSubScriptBits(uint32_t script) { case SCRIPT_TAG('K', 'o', 'r', 'e'): subScriptBits = kHanFlag | kHangulFlag; break; - case SCRIPT_TAG('Z', 's', 'y', 'e'): - subScriptBits = kEmojiFlag; - break; } return subScriptBits; } diff --git a/engine/src/flutter/libs/minikin/FontLanguage.h b/engine/src/flutter/libs/minikin/FontLanguage.h index b1bb6eb5f95..25a5cc3dfa9 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.h +++ b/engine/src/flutter/libs/minikin/FontLanguage.h @@ -34,14 +34,25 @@ class FontLanguages; // font rendering. struct FontLanguage { public: + enum EmojiStyle : uint8_t { + EMSTYLE_EMPTY = 0, + EMSTYLE_DEFAULT = 1, + EMSTYLE_EMOJI = 2, + EMSTYLE_TEXT = 3, + }; // Default constructor creates the unsupported language. - FontLanguage() : mScript(0ul), mLanguage(0ul), mSubScriptBits(0ul) {} + FontLanguage() + : mScript(0ul), + mLanguage(0ul), + mSubScriptBits(0ul), + mEmojiStyle(EMSTYLE_EMPTY) {} // Parse from string FontLanguage(const char* buf, size_t length); bool operator==(const FontLanguage other) const { - return !isUnsupported() && isEqualScript(other) && mLanguage == other.mLanguage; + return !isUnsupported() && isEqualScript(other) && mLanguage == other.mLanguage && + mEmojiStyle == other.mEmojiStyle; } bool operator!=(const FontLanguage other) const { @@ -49,7 +60,7 @@ public: } bool isUnsupported() const { return mLanguage == 0ul; } - bool hasEmojiFlag() const { return mSubScriptBits & kEmojiFlag; } + EmojiStyle getEmojiStyle() const { return mEmojiStyle; } bool isEqualScript(const FontLanguage& other) const; @@ -64,7 +75,9 @@ public: // 0 = no match, 1 = script match, 2 = script and primary language match. int calcScoreFor(const FontLanguages& supported) const; - uint64_t getIdentifier() const { return (uint64_t)mScript << 32 | (uint64_t)mLanguage; } + uint64_t getIdentifier() const { + return (uint64_t)mScript << 32 | (uint64_t)mEmojiStyle << 24 | (uint64_t)mLanguage; + } private: friend class FontLanguages; // for FontLanguages constructor @@ -73,21 +86,22 @@ private: uint32_t mScript; // ISO 639-1 or ISO 639-2 compliant language code. - // The two or three letter language code is packed into 32 bit integer. + // The two or three letter language code is packed into 24 bit integer. // mLanguage = 0 means the FontLanguage is unsupported. uint32_t mLanguage; - // For faster comparing, use 8 bits for specific scripts. + // For faster comparing, use 7 bits for specific scripts. static const uint8_t kBopomofoFlag = 1u; - static const uint8_t kEmojiFlag = 1u << 1; - static const uint8_t kHanFlag = 1u << 2; - static const uint8_t kHangulFlag = 1u << 3; - static const uint8_t kHiraganaFlag = 1u << 4; - static const uint8_t kKatakanaFlag = 1u << 5; - static const uint8_t kSimplifiedChineseFlag = 1u << 6; - static const uint8_t kTraditionalChineseFlag = 1u << 7; + static const uint8_t kHanFlag = 1u << 1; + static const uint8_t kHangulFlag = 1u << 2; + static const uint8_t kHiraganaFlag = 1u << 3; + static const uint8_t kKatakanaFlag = 1u << 4; + static const uint8_t kSimplifiedChineseFlag = 1u << 5; + static const uint8_t kTraditionalChineseFlag = 1u << 6; uint8_t mSubScriptBits; + EmojiStyle mEmojiStyle; + static uint8_t scriptToSubScriptBits(uint32_t script); // Returns true if the provide subscript bits has the requested subscript bits. diff --git a/engine/src/flutter/tests/perftests/FontLanguage.cpp b/engine/src/flutter/tests/perftests/FontLanguage.cpp index 8f77e12b75d..6c9c84de888 100644 --- a/engine/src/flutter/tests/perftests/FontLanguage.cpp +++ b/engine/src/flutter/tests/perftests/FontLanguage.cpp @@ -33,4 +33,11 @@ static void BM_FontLanguage_en_Latn_US(benchmark::State& state) { } BENCHMARK(BM_FontLanguage_en_Latn_US); +static void BM_FontLanguage_en_Latn_US_u_em_emoji(benchmark::State& state) { + while (state.KeepRunning()) { + FontLanguage language("en-Latn-US-u-em-emoji", 21); + } +} +BENCHMARK(BM_FontLanguage_en_Latn_US_u_em_emoji); + } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 4aaa601a23e..95151a2163f 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -269,17 +269,130 @@ TEST_F(FontLanguagesTest, repeatedLanguageTests) { TEST_F(FontLanguagesTest, undEmojiTests) { FontLanguage emoji = createFontLanguage("und-Zsye"); - EXPECT_TRUE(emoji.hasEmojiFlag()); + EXPECT_EQ(FontLanguage::EMSTYLE_EMOJI, emoji.getEmojiStyle()); FontLanguage und = createFontLanguage("und"); - EXPECT_FALSE(und.hasEmojiFlag()); + EXPECT_EQ(FontLanguage::EMSTYLE_EMPTY, und.getEmojiStyle()); EXPECT_FALSE(emoji == und); FontLanguage undExample = createFontLanguage("und-example"); - EXPECT_FALSE(undExample.hasEmojiFlag()); + EXPECT_EQ(FontLanguage::EMSTYLE_EMPTY, undExample.getEmojiStyle()); EXPECT_FALSE(emoji == undExample); } +TEST_F(FontLanguagesTest, subtagEmojiTest) { + std::string subtagEmojiStrings[] = { + // Duplicate subtag case. + "und-Latn-u-em-emoji-u-em-text", + + // Strings that contain language. + "und-u-em-emoji", + "en-u-em-emoji", + + // Strings that contain the script. + "und-Jpan-u-em-emoji", + "en-Latn-u-em-emoji", + "und-Zsym-u-em-emoji", + "und-Zsye-u-em-emoji", + "en-Zsym-u-em-emoji", + "en-Zsye-u-em-emoji", + + // Strings that contain the county. + "und-US-u-em-emoji", + "en-US-u-em-emoji", + "und-Latn-US-u-em-emoji", + "en-Zsym-US-u-em-emoji", + "en-Zsye-US-u-em-emoji", + }; + + for (auto subtagEmojiString : subtagEmojiStrings) { + SCOPED_TRACE("Test for \"" + subtagEmojiString + "\""); + FontLanguage subtagEmoji = createFontLanguage(subtagEmojiString); + EXPECT_EQ(FontLanguage::EMSTYLE_EMOJI, subtagEmoji.getEmojiStyle()); + } +} + +TEST_F(FontLanguagesTest, subtagTextTest) { + std::string subtagTextStrings[] = { + // Duplicate subtag case. + "und-Latn-u-em-text-u-em-emoji", + + // Strings that contain language. + "und-u-em-text", + "en-u-em-text", + + // Strings that contain the script. + "und-Latn-u-em-text", + "en-Jpan-u-em-text", + "und-Zsym-u-em-text", + "und-Zsye-u-em-text", + "en-Zsym-u-em-text", + "en-Zsye-u-em-text", + + // Strings that contain the county. + "und-US-u-em-text", + "en-US-u-em-text", + "und-Latn-US-u-em-text", + "en-Zsym-US-u-em-text", + "en-Zsye-US-u-em-text", + }; + + for (auto subtagTextString : subtagTextStrings) { + SCOPED_TRACE("Test for \"" + subtagTextString + "\""); + FontLanguage subtagText = createFontLanguage(subtagTextString); + EXPECT_EQ(FontLanguage::EMSTYLE_TEXT, subtagText.getEmojiStyle()); + } +} + +// TODO: add more "und" language cases whose language and script are +// unexpectedly translated to en-Latn by ICU. +TEST_F(FontLanguagesTest, subtagDefaultTest) { + std::string subtagDefaultStrings[] = { + // Duplicate subtag case. + "en-Latn-u-em-default-u-em-emoji", + "en-Latn-u-em-default-u-em-text", + + // Strings that contain language. + "und-u-em-default", + "en-u-em-default", + + // Strings that contain the script. + "en-Latn-u-em-default", + "en-Zsym-u-em-default", + "en-Zsye-u-em-default", + + // Strings that contain the county. + "en-US-u-em-default", + "en-Latn-US-u-em-default", + "en-Zsym-US-u-em-default", + "en-Zsye-US-u-em-default", + }; + + for (auto subtagDefaultString : subtagDefaultStrings) { + SCOPED_TRACE("Test for \"" + subtagDefaultString + "\""); + FontLanguage subtagDefault = createFontLanguage(subtagDefaultString); + EXPECT_EQ(FontLanguage::EMSTYLE_DEFAULT, subtagDefault.getEmojiStyle()); + } +} + +TEST_F(FontLanguagesTest, subtagEmptyTest) { + std::string subtagEmptyStrings[] = { + "und", + "jp", + "en-US", + "en-Latn", + "en-Latn-US", + "en-Latn-US-u-em", + "en-Latn-US-u-em-defaultemoji", + }; + + for (auto subtagEmptyString : subtagEmptyStrings) { + SCOPED_TRACE("Test for \"" + subtagEmptyString + "\""); + FontLanguage subtagEmpty = createFontLanguage(subtagEmptyString); + EXPECT_EQ(FontLanguage::EMSTYLE_EMPTY, subtagEmpty.getEmojiStyle()); + } +} + TEST_F(FontLanguagesTest, registerLanguageListTest) { EXPECT_EQ(0UL, FontStyle::registerLanguageList("")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en")); diff --git a/engine/src/flutter/tests/unittest/how_to_run.txt b/engine/src/flutter/tests/unittest/how_to_run.txt index c90c6640bdf..4adfcb8d055 100644 --- a/engine/src/flutter/tests/unittest/how_to_run.txt +++ b/engine/src/flutter/tests/unittest/how_to_run.txt @@ -1,4 +1,4 @@ -mmm -j8 frameworks/minikin/tests/unittests && +mmm -j8 frameworks/minikin/tests/unittest && adb push $OUT/data/nativetest/minikin_tests/minikin_tests \ /data/nativetest/minikin_tests/minikin_tests && adb push frameworks/minikin/tests/data /data/nativetest/minikin_tests/ && From ccce2fd909ad4086c6fc1a7ffc09659646bdd4fb Mon Sep 17 00:00:00 2001 From: Hal Canary Date: Thu, 24 Nov 2016 12:06:33 -0500 Subject: [PATCH 209/364] SkImageEncoder->SkEncodeImage Test: none Change-Id: I9115c41f1699ab5d9d677251d96ea8f4fb844845 --- engine/src/flutter/sample/example_skia.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/sample/example_skia.cpp b/engine/src/flutter/sample/example_skia.cpp index 5e15a107c27..b04c8abcbcc 100644 --- a/engine/src/flutter/sample/example_skia.cpp +++ b/engine/src/flutter/sample/example_skia.cpp @@ -141,7 +141,8 @@ int runMinikinTest() { paint.setStyle(SkPaint::kFill_Style); drawToSkia(&canvas, &paint, &layout, 10, 300); - SkImageEncoder::EncodeFile("/data/local/tmp/foo.png", bitmap, SkImageEncoder::kPNG_Type, 100); + SkFILEWStream file("/data/local/tmp/foo.png"); + SkEncodeImage(&file, bitmap, SkEncodedImageFormat::kPNG, 100); return 0; } From be7c33a74ed7a8a30d4ff6d8cbfa1308050256a7 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 2 Dec 2016 18:04:42 -0800 Subject: [PATCH 210/364] Move LOCAL_PICKUP_FILES out of $OUT/data minikin_tests was copying its test data to $OUT/data/DATA/nativetest/minikin_test, and then packaging that with LOCAL_PICKUP_FILES=$OUT/data/DATA, which would also pick up anything any other module copyied to $OUT/data/DATA. $OUT/data/DATA isn't where the tests expect to find their data, they look in /data/nativetest/minikin_test. Copy the files to the intermediates directory instead. A future change will install LOCAL_PICKUP_FILES for local builds to the correct place, so adb sync and adb shell /data/nativetest/minikin_tests/minikin_tests will run the tests. Test: mma -j Change-Id: I808ce743f51e5ccac711e22821e7e0d7cd94ffdf --- engine/src/flutter/tests/Android.mk | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index b33631eb28e..bcc49193d5b 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -18,11 +18,6 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -data_root_for_test_zip := $(TARGET_OUT_DATA)/DATA/ -minikin_tests_subpath_from_data := nativetest/minikin_tests -minikin_tests_root_in_device := /data/$(minikin_tests_subpath_from_data) -minikin_tests_root_for_test_zip := $(data_root_for_test_zip)/$(minikin_tests_subpath_from_data) - font_src_files := \ data/BoldItalic.ttf \ data/Bold.ttf \ @@ -43,6 +38,12 @@ font_src_files := \ LOCAL_MODULE := minikin_tests LOCAL_MODULE_TAGS := tests +LOCAL_MODULE_CLASS := NATIVE_TESTS + +data_root_for_test_zip := $(local-intermediates-dir)/DATA +minikin_tests_subpath_from_data := nativetest/minikin_tests +minikin_tests_root_in_device := /data/$(minikin_tests_subpath_from_data) +minikin_tests_root_for_test_zip := $(data_root_for_test_zip)/$(minikin_tests_subpath_from_data) GEN := $(addprefix $(minikin_tests_root_for_test_zip)/, $(font_src_files)) $(GEN): PRIVATE_PATH := $(LOCAL_PATH) From f20a2ef2715ef026763e7b639788ccdad4ed5dc4 Mon Sep 17 00:00:00 2001 From: Yirui Huang Date: Thu, 15 Sep 2016 18:04:34 +0900 Subject: [PATCH 211/364] Change language score calculation Change language score calculation in the calculation of the font family. Instead of language and script matching, a match in subtag is added. In addition, a match in subtag has a higher priority than a match in script. The score levels are divided into 5 score levels and the limit of the number of font languages is changed to 12 from 17. Multiple languages selection rule could to be added in the future. Bug: 31608997 Test: Done by unittests. Change-Id: I1e7177095f604fd1794bc99ca36c705dcb4c56e7 --- .../flutter/libs/minikin/FontCollection.cpp | 20 ++++++----- .../src/flutter/libs/minikin/FontLanguage.cpp | 35 +++++++++++++------ .../src/flutter/libs/minikin/FontLanguage.h | 4 +-- .../unittest/FontCollectionItemizeTest.cpp | 14 ++++++++ 4 files changed, 51 insertions(+), 22 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 5bc3634e82c..291833c5537 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -234,22 +234,24 @@ uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, FontFamily* return 1; } -// Calculates font scores based on the script matching and primary langauge matching. +// Calculate font scores based on the script matching, subtag matching and primary langauge matching. // -// If the font's script doesn't support the requested script, the font gets a score of 0. If the -// font's script supports the requested script and the font has the same primary language as the -// requested one, the font gets a score of 2. If the font's script supports the requested script -// but the primary language is different from the requested one, the font gets a score of 1. +// 1. If only the font's language matches or there is no matches between requested font and +// supported font, then the font obtains a score of 0. +// 2. Without a match in language, considering subtag may change font's EmojiStyle over script, +// a match in subtag gets a score of 2 and a match in scripts gains a score of 1. +// 3. Regarding to two elements matchings, language-and-subtag matching has a score of 4, while +// language-and-script obtains a socre of 3 with the same reason above. // // If two languages in the requested list have the same language score, the font matching with // higher priority language gets a higher score. For example, in the case the user requested // language list is "ja-Jpan,en-Latn". The score of for the font of "ja-Jpan" gets a higher score // than the font of "en-Latn". // -// To achieve the above two conditions, the language score is determined as follows: -// LanguageScore = s(0) * 3^(m - 1) + s(1) * 3^(m - 2) + ... + s(m - 2) * 3 + s(m - 1) +// To achieve score calculation with priorities, the language score is determined as follows: +// LanguageScore = s(0) * 5^(m - 1) + s(1) * 5^(m - 2) + ... + s(m - 2) * 5 + s(m - 1) // Here, m is the maximum number of languages to be compared, and s(i) is the i-th language's -// matching score. The possible values of s(i) are 0, 1 and 2. +// matching score. The possible values of s(i) are 0, 1, 2, 3 and 4. uint32_t FontCollection::calcLanguageMatchingScore( uint32_t userLangListId, const FontFamily& fontFamily) { const FontLanguages& langList = FontLanguageListCache::getById(userLangListId); @@ -258,7 +260,7 @@ uint32_t FontCollection::calcLanguageMatchingScore( const size_t maxCompareNum = std::min(langList.size(), FONT_LANGUAGES_LIMIT); uint32_t score = 0; for (size_t i = 0; i < maxCompareNum; ++i) { - score = score * 3u + langList[i].calcScoreFor(fontLanguages); + score = score * 5u + langList[i].calcScoreFor(fontLanguages); } return score; } diff --git a/engine/src/flutter/libs/minikin/FontLanguage.cpp b/engine/src/flutter/libs/minikin/FontLanguage.cpp index fca4cdbfcd5..c6ddda5ae9f 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguage.cpp @@ -176,28 +176,41 @@ bool FontLanguage::supportsHbScript(hb_script_t script) const { } int FontLanguage::calcScoreFor(const FontLanguages& supported) const { - int score = 0; + bool languageScriptMatch = false; + bool subtagMatch = false; + bool scriptMatch = false; + for (size_t i = 0; i < supported.size(); ++i) { + if (mEmojiStyle != EMSTYLE_EMPTY && + mEmojiStyle == supported[i].mEmojiStyle) { + subtagMatch = true; + if (mLanguage == supported[i].mLanguage) { + return 4; + } + } if (isEqualScript(supported[i]) || supportsScript(supported[i].mSubScriptBits, mSubScriptBits)) { + scriptMatch = true; if (mLanguage == supported[i].mLanguage) { - return 2; - } else { - score = 1; + languageScriptMatch = true; } } } - if (score == 1) { - return score; - } - if (supportsScript(supported.getUnionOfSubScriptBits(), mSubScriptBits)) { - // Gives score of 2 only if the language matches all of the font languages except for the - // exact match case handled above. - return (mLanguage == supported[0].mLanguage && supported.isAllTheSameLanguage()) ? 2 : 1; + scriptMatch = true; + if (mLanguage == supported[0].mLanguage && supported.isAllTheSameLanguage()) { + return 3; + } } + if (languageScriptMatch) { + return 3; + } else if (subtagMatch) { + return 2; + } else if (scriptMatch) { + return 1; + } return 0; } diff --git a/engine/src/flutter/libs/minikin/FontLanguage.h b/engine/src/flutter/libs/minikin/FontLanguage.h index 25a5cc3dfa9..1bebdfeeb91 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.h +++ b/engine/src/flutter/libs/minikin/FontLanguage.h @@ -24,9 +24,9 @@ namespace minikin { -// Due to the limits in font fallback score calculation, we can't use anything more than 17 +// Due to the limits in font fallback score calculation, we can't use anything more than 12 // languages. -const size_t FONT_LANGUAGES_LIMIT = 17; +const size_t FONT_LANGUAGES_LIMIT = 12; class FontLanguages; // FontLanguage is a compact representation of a BCP 47 language tag. It diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 02bc03bbe6b..52786d0c7e0 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -780,6 +780,20 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { // Language match with unified subscript bits. { "zh-Hanb", { "zh-Hant", "zh-Bopo", "ja-Hant,ja-Bopo", "zh-Hant,zh-Bopo"}, 3 }, { "zh-Hanb", { "zh-Hant", "zh-Bopo", "ja-Hant,zh-Bopo", "zh-Hant,zh-Bopo"}, 3 }, + + // Two elements subtag matching: language and subtag or language or script. + { "ja-Kana-u-em-emoji", { "zh-Hant", "ja-Kana"}, 1 }, + { "ja-Kana-u-em-emoji", { "zh-Hant", "ja-Kana", "ja-Zsye"}, 2 }, + { "ja-Zsym-u-em-emoji", { "ja-Kana", "ja-Zsym", "ja-Zsye"}, 2 }, + + // One element subtag matching: subtag only or script only. + { "en-Latn-u-em-emoji", { "ja-Latn", "ja-Zsye"}, 1 }, + { "en-Zsym-u-em-emoji", { "ja-Zsym", "ja-Zsye"}, 1 }, + { "en-Zsye-u-em-text", { "ja-Zsym", "ja-Zsye"}, 0 }, + + // Multiple languages list with subtags. + { "en-Latn,ja-Jpan-u-em-text", { "en-Latn", "en-Zsye", "en-Zsym"}, 0 }, + { "en-Latn,en-Zsye,ja-Jpan-u-em-text", { "zh", "en-Zsye", "en-Zsym"}, 1 }, }; for (auto testCase : testCases) { From 6c5e3f184469787c7ab3d580092d8a9ef0fd5ffe Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Fri, 9 Dec 2016 16:31:40 -0800 Subject: [PATCH 212/364] Use LOCAL_TEST_DATA to install test data This will handle installation for local builds as well as for the test bundles. Test: m -j minikin_tests; ls $OUT/data/nativetest*/minikin_tests Test: m -j continous_native_tests dist; zipinfo -1 out/dist/*continuous_native_tests*.zip Test: /data/nativetest{,64}/minikin_tests/minikin_tests Change-Id: Iafd31fa119e7c4d92937ca8ae8346e268a6c1f38 --- engine/src/flutter/tests/unittest/Android.mk | 23 ++++++------------- .../src/flutter/tests/unittest/how_to_run.txt | 4 +--- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index b88f1e70fce..cced5457373 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -18,7 +18,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -font_src_files := \ +LOCAL_TEST_DATA := \ data/BoldItalic.ttf \ data/Bold.ttf \ data/ColorEmojiFont.ttf \ @@ -37,24 +37,13 @@ font_src_files := \ data/itemize.xml \ data/emoji.xml +LOCAL_TEST_DATA := $(foreach f,$(LOCAL_TEST_DATA),frameworks/minikin/tests:$(f)) + LOCAL_MODULE := minikin_tests LOCAL_MODULE_TAGS := tests LOCAL_MODULE_CLASS := NATIVE_TESTS -data_root_for_test_zip := $(local-intermediates-dir)/DATA -minikin_tests_subpath_from_data := nativetest/minikin_tests -minikin_tests_root_in_device := /data/$(minikin_tests_subpath_from_data) -minikin_tests_root_for_test_zip := $(data_root_for_test_zip)/$(minikin_tests_subpath_from_data) - -GEN := $(addprefix $(minikin_tests_root_for_test_zip)/, $(font_src_files)) -$(GEN): PRIVATE_PATH := $(LOCAL_PATH)/../ -$(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@ -$(GEN): $(minikin_tests_root_for_test_zip)/data/% : $(LOCAL_PATH)/../data/% - $(transform-generated-source) -LOCAL_GENERATED_SOURCES += $(GEN) - LOCAL_STATIC_LIBRARIES := libminikin -LOCAL_PICKUP_FILES := $(data_root_for_test_zip) # Shared libraries which are dependencies of minikin; these are not automatically # pulled in by the build system (and thus sadly must be repeated). @@ -95,7 +84,9 @@ LOCAL_C_INCLUDES := \ external/libxml2/include \ external/skia/src/core -LOCAL_CPPFLAGS += -Werror -Wall -Wextra \ - -DkTestFontDir="\"$(minikin_tests_root_in_device)/data/\"" +LOCAL_CPPFLAGS += -Werror -Wall -Wextra + +LOCAL_CPPFLAGS_32 += -DkTestFontDir="\"/data/nativetest/minikin_tests/data/\"" +LOCAL_CPPFLAGS_64 += -DkTestFontDir="\"/data/nativetest64/minikin_tests/data/\"" include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/unittest/how_to_run.txt b/engine/src/flutter/tests/unittest/how_to_run.txt index 4adfcb8d055..e94c904becf 100644 --- a/engine/src/flutter/tests/unittest/how_to_run.txt +++ b/engine/src/flutter/tests/unittest/how_to_run.txt @@ -1,5 +1,3 @@ mmm -j8 frameworks/minikin/tests/unittest && -adb push $OUT/data/nativetest/minikin_tests/minikin_tests \ - /data/nativetest/minikin_tests/minikin_tests && -adb push frameworks/minikin/tests/data /data/nativetest/minikin_tests/ && +adb push $OUT/data/nativetest/minikin_tests /data/nativetest/ && adb shell /data/nativetest/minikin_tests/minikin_tests From 7e38090b575faaebc1193291bd114dc885650087 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Fri, 9 Dec 2016 16:31:40 -0800 Subject: [PATCH 213/364] Use LOCAL_TEST_DATA to install test data This will handle installation for local builds as well as for the test bundles. Test: m -j minikin_tests; ls $OUT/data/nativetest*/minikin_tests Test: m -j continous_native_tests dist; zipinfo -1 out/dist/*continuous_native_tests*.zip Test: /data/nativetest{,64}/minikin_tests/minikin_tests Change-Id: Iafd31fa119e7c4d92937ca8ae8346e268a6c1f38 Merged-In: Iafd31fa119e7c4d92937ca8ae8346e268a6c1f38 --- engine/src/flutter/tests/Android.mk | 21 +++++---------------- engine/src/flutter/tests/how_to_run.txt | 4 +--- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk index bcc49193d5b..2f215323771 100644 --- a/engine/src/flutter/tests/Android.mk +++ b/engine/src/flutter/tests/Android.mk @@ -18,7 +18,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -font_src_files := \ +LOCAL_TEST_DATA := \ data/BoldItalic.ttf \ data/Bold.ttf \ data/ColorEmojiFont.ttf \ @@ -40,20 +40,7 @@ LOCAL_MODULE := minikin_tests LOCAL_MODULE_TAGS := tests LOCAL_MODULE_CLASS := NATIVE_TESTS -data_root_for_test_zip := $(local-intermediates-dir)/DATA -minikin_tests_subpath_from_data := nativetest/minikin_tests -minikin_tests_root_in_device := /data/$(minikin_tests_subpath_from_data) -minikin_tests_root_for_test_zip := $(data_root_for_test_zip)/$(minikin_tests_subpath_from_data) - -GEN := $(addprefix $(minikin_tests_root_for_test_zip)/, $(font_src_files)) -$(GEN): PRIVATE_PATH := $(LOCAL_PATH) -$(GEN): PRIVATE_CUSTOM_TOOL = cp $< $@ -$(GEN): $(minikin_tests_root_for_test_zip)/data/% : $(LOCAL_PATH)/data/% - $(transform-generated-source) -LOCAL_GENERATED_SOURCES += $(GEN) - LOCAL_STATIC_LIBRARIES := libminikin -LOCAL_PICKUP_FILES := $(data_root_for_test_zip) # Shared libraries which are dependencies of minikin; these are not automatically # pulled in by the build system (and thus sadly must be repeated). @@ -90,7 +77,9 @@ LOCAL_C_INCLUDES := \ external/libxml2/include \ external/skia/src/core -LOCAL_CPPFLAGS += -Werror -Wall -Wextra \ - -DkTestFontDir="\"$(minikin_tests_root_in_device)/data/\"" +LOCAL_CPPFLAGS += -Werror -Wall -Wextra + +LOCAL_CPPFLAGS_32 += -DkTestFontDir="\"/data/nativetest/minikin_tests/data/\"" +LOCAL_CPPFLAGS_64 += -DkTestFontDir="\"/data/nativetest64/minikin_tests/data/\"" include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/how_to_run.txt b/engine/src/flutter/tests/how_to_run.txt index bee367bd179..03a55244b33 100644 --- a/engine/src/flutter/tests/how_to_run.txt +++ b/engine/src/flutter/tests/how_to_run.txt @@ -1,5 +1,3 @@ mmm -j8 frameworks/minikin/tests && -adb push $OUT/data/nativetest/minikin_tests/minikin_tests \ - /data/nativetest/minikin_tests/minikin_tests && -adb push frameworks/minikin/tests/data /data/nativetest/minikin_tests/ && +adb push $OUT/data/nativetest/minikin_tests /data/nativetest/ && adb shell /data/nativetest/minikin_tests/minikin_tests From ff6cd90494440d28b2f755c3e9f46fae22b2f92f Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Wed, 28 Sep 2016 15:23:30 -0700 Subject: [PATCH 214/364] minikin: Replace cutils/log.h with android/log.h or log/log.h - replace cutils/log.h with android/log.h (main buffer logging) - replace cutils/log.h with log.log.h (+SafetyNet logging) - define LOG_TAG before use. Test: compile Bug: 26552300 Bug: 31289077 Change-Id: I7a4803dd66f31b7103e09e5ff5b8fa523fa0fd60 --- engine/src/flutter/libs/minikin/CmapCoverage.cpp | 3 ++- engine/src/flutter/libs/minikin/FontCollection.cpp | 3 ++- engine/src/flutter/libs/minikin/FontFamily.cpp | 10 +++++----- .../src/flutter/libs/minikin/FontLanguageListCache.cpp | 5 +++-- engine/src/flutter/libs/minikin/HbFontCache.cpp | 5 +++-- engine/src/flutter/libs/minikin/Layout.cpp | 9 ++++----- engine/src/flutter/libs/minikin/LineBreaker.cpp | 5 +++-- engine/src/flutter/libs/minikin/Measurement.cpp | 3 ++- engine/src/flutter/libs/minikin/MinikinInternal.cpp | 3 ++- engine/src/flutter/libs/minikin/SparseBitSet.cpp | 6 +++++- engine/src/flutter/libs/minikin/WordBreaker.cpp | 3 ++- engine/src/flutter/tests/FontFamilyTest.cpp | 5 ++--- engine/src/flutter/tests/FontTestUtils.cpp | 10 ++++++---- engine/src/flutter/tests/HbFontCacheTest.cpp | 8 ++++---- engine/src/flutter/tests/MinikinFontForTest.cpp | 4 +++- engine/src/flutter/tests/WordBreakerTests.cpp | 7 ++++--- 16 files changed, 52 insertions(+), 37 deletions(-) diff --git a/engine/src/flutter/libs/minikin/CmapCoverage.cpp b/engine/src/flutter/libs/minikin/CmapCoverage.cpp index 2961d2ffa8d..86d8981c8b0 100644 --- a/engine/src/flutter/libs/minikin/CmapCoverage.cpp +++ b/engine/src/flutter/libs/minikin/CmapCoverage.cpp @@ -17,11 +17,12 @@ // Determine coverage of font given its raw "cmap" OpenType table #define LOG_TAG "Minikin" -#include #include using std::vector; +#include + #include #include diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 33418ab1b5d..ddda7bc09a6 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -17,9 +17,10 @@ // #define VERBOSE_DEBUG #define LOG_TAG "Minikin" -#include + #include +#include #include "unicode/unistr.h" #include "unicode/unorm2.h" diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 7a8e79f508f..6d45c67126e 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -16,24 +16,24 @@ #define LOG_TAG "Minikin" -#include -#include #include +#include #include +#include +#include + #include #include -#include - #include "FontLanguage.h" #include "FontLanguageListCache.h" #include "HbFontCache.h" #include "MinikinInternal.h" -#include #include #include #include +#include using std::vector; diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp index 6b661f03846..9a409e658bf 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp @@ -18,12 +18,13 @@ #include "FontLanguageListCache.h" -#include #include #include -#include "MinikinInternal.h" +#include + #include "FontLanguage.h" +#include "MinikinInternal.h" namespace android { diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index 3be942d7b9e..08687571ba8 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -18,10 +18,11 @@ #include "HbFontCache.h" -#include +#include +#include + #include #include -#include #include #include "MinikinInternal.h" diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 5ba72a4bb2c..45cb06680ff 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -15,29 +15,28 @@ */ #define LOG_TAG "Minikin" -#include - -#include #include #include #include // for debugging +#include #include +#include #include +#include #include #include #include #include -#include #include #include #include "FontLanguage.h" #include "FontLanguageListCache.h" -#include "LayoutUtils.h" #include "HbFontCache.h" +#include "LayoutUtils.h" #include "MinikinInternal.h" #include #include diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 2a71f044d23..bc8cb800ee7 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -16,10 +16,11 @@ #define VERBOSE_DEBUG 0 +#define LOG_TAG "Minikin" + #include -#define LOG_TAG "Minikin" -#include +#include #include #include diff --git a/engine/src/flutter/libs/minikin/Measurement.cpp b/engine/src/flutter/libs/minikin/Measurement.cpp index 1ba6678373b..b292c9aba94 100644 --- a/engine/src/flutter/libs/minikin/Measurement.cpp +++ b/engine/src/flutter/libs/minikin/Measurement.cpp @@ -15,11 +15,12 @@ */ #define LOG_TAG "Minikin" -#include #include #include +#include + #include #include diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index 5cb94914c9e..5900c1852ca 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -15,12 +15,13 @@ */ // Definitions internal to Minikin +#define LOG_TAG "Minikin" #include "MinikinInternal.h" #include "HbFontCache.h" #include "generated/UnicodeData.h" -#include +#include namespace android { diff --git a/engine/src/flutter/libs/minikin/SparseBitSet.cpp b/engine/src/flutter/libs/minikin/SparseBitSet.cpp index de0791445cd..aa73c126707 100644 --- a/engine/src/flutter/libs/minikin/SparseBitSet.cpp +++ b/engine/src/flutter/libs/minikin/SparseBitSet.cpp @@ -14,9 +14,13 @@ * limitations under the License. */ -#include +#define LOG_TAG "SparseBitSet" + #include #include + +#include + #include namespace android { diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index 38f03caf6a0..7fc5824b6d0 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -15,7 +15,8 @@ */ #define LOG_TAG "Minikin" -#include + +#include #include #include "MinikinInternal.h" diff --git a/engine/src/flutter/tests/FontFamilyTest.cpp b/engine/src/flutter/tests/FontFamilyTest.cpp index 1b2457695c4..1975b7e7fd5 100644 --- a/engine/src/flutter/tests/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/FontFamilyTest.cpp @@ -14,11 +14,10 @@ * limitations under the License. */ -#include - #include -#include +#include +#include #include "FontLanguageListCache.h" #include "ICUTestBase.h" diff --git a/engine/src/flutter/tests/FontTestUtils.cpp b/engine/src/flutter/tests/FontTestUtils.cpp index fdc3ed6ee91..9d36d2f6cb9 100644 --- a/engine/src/flutter/tests/FontTestUtils.cpp +++ b/engine/src/flutter/tests/FontTestUtils.cpp @@ -14,15 +14,17 @@ * limitations under the License. */ +#define LOG_TAG "Minikin" + #include +#include -#include -#include - -#include +#include #include "FontLanguage.h" #include "MinikinFontForTest.h" +#include +#include android::FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { xmlDoc* doc = xmlReadFile(fontXml, NULL, 0); diff --git a/engine/src/flutter/tests/HbFontCacheTest.cpp b/engine/src/flutter/tests/HbFontCacheTest.cpp index 2dee61aff06..f1b1d311190 100644 --- a/engine/src/flutter/tests/HbFontCacheTest.cpp +++ b/engine/src/flutter/tests/HbFontCacheTest.cpp @@ -14,14 +14,14 @@ * limitations under the License. */ -#include - #include "HbFontCache.h" -#include -#include +#include +#include #include +#include + #include "MinikinInternal.h" #include "MinikinFontForTest.h" #include diff --git a/engine/src/flutter/tests/MinikinFontForTest.cpp b/engine/src/flutter/tests/MinikinFontForTest.cpp index 66dd4ea4734..7933d2457e0 100644 --- a/engine/src/flutter/tests/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/MinikinFontForTest.cpp @@ -14,13 +14,15 @@ * limitations under the License. */ +#define LOG_TAG "Minikin" + #include "MinikinFontForTest.h" #include #include -#include +#include MinikinFontForTest::MinikinFontForTest(const std::string& font_path) : MinikinFontForTest(font_path, SkTypeface::CreateFromFile(font_path.c_str())) { diff --git a/engine/src/flutter/tests/WordBreakerTests.cpp b/engine/src/flutter/tests/WordBreakerTests.cpp index 8ed87cc5069..0bb614732a6 100644 --- a/engine/src/flutter/tests/WordBreakerTests.cpp +++ b/engine/src/flutter/tests/WordBreakerTests.cpp @@ -14,7 +14,11 @@ * limitations under the License. */ +#define LOG_TAG "Minikin" + +#include #include + #include "ICUTestBase.h" #include "UnicodeUtils.h" #include @@ -22,9 +26,6 @@ #include #include -#define LOG_TAG "Minikin" -#include - #ifndef NELEM #define NELEM(x) ((sizeof(x) / sizeof((x)[0]))) #endif From 311d94f4161f17e80a86c646b9111a3fe1b4de48 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 24 Nov 2016 13:24:53 +0900 Subject: [PATCH 215/364] Tune line breaking for justification Add an "mJustified" for justification, and tune the line breaking to produce good results. Major differences for fully justified text include: - Space can be shrunk in justified text. - Hyphenation should be more aggressive in justified text. Also adds a penalty for the last line being very short. This is tuned to be more aggressive for ragged right than for justified text. This is based on a patch by Raph Levien (raph@google.com). Bug: 31707212 Test: Manually tested with Icbfab2faa11a6a0b52e6f0a77a9c9b5ef6e191da Change-Id: If366f82800831ccc247ec07b7bc28ca4c6ae0ed6 --- .../src/flutter/include/minikin/LineBreaker.h | 12 +++- .../src/flutter/libs/minikin/LineBreaker.cpp | 69 ++++++++++++++++--- 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index feaffe74e32..75e54b05f1b 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -147,6 +147,8 @@ class LineBreaker { void setStrategy(BreakStrategy strategy) { mStrategy = strategy; } + void setJustified(bool justified) { mJustified = justified; } + HyphenationFrequency getHyphenationFrequency() const { return mHyphenationFrequency; } void setHyphenationFrequency(HyphenationFrequency frequency) { @@ -194,19 +196,23 @@ class LineBreaker { float penalty; // penalty of this break (for example, hyphen penalty) float score; // best score found for this break size_t lineNumber; // only updated for non-constant line widths + size_t preSpaceCount; // preceding space count before breaking + size_t postSpaceCount; // preceding space count after breaking uint8_t hyphenEdit; }; float currentLineWidth() const; - void addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, float penalty, - uint8_t hyph); + void addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, + size_t preSpaceCount, size_t postSpaceCount, float penalty, uint8_t hyph); void addCandidate(Candidate cand); // push an actual break to the output. Takes care of setting flags for tab void pushBreak(int offset, float width, uint8_t hyph); + float getSpaceWidth() const; + void computeBreaksGreedy(); void computeBreaksOptimal(bool isRectangular); @@ -223,6 +229,7 @@ class LineBreaker { // layout parameters BreakStrategy mStrategy = kBreakStrategy_Greedy; HyphenationFrequency mHyphenationFrequency = kHyphenationFrequency_Normal; + bool mJustified; LineWidths mLineWidths; TabStops mTabStops; @@ -241,6 +248,7 @@ class LineBreaker { float mBestScore; ParaWidth mPreBreak; // prebreak of last break int mFirstTabIndex; + size_t mSpaceCount; }; } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 5ed6ab28fc7..f7d1fd92146 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -22,6 +22,7 @@ #include +#include "LayoutUtils.h" #include #include @@ -44,6 +45,9 @@ const float LAST_LINE_PENALTY_MULTIPLIER = 4.0f; // probably not the most appropriate method. const float LINE_PENALTY_MULTIPLIER = 2.0f; +// Penalty assigned to shrinking the whitepsace. +const float SHRINK_PENALTY_MULTIPLIER = 4.0f; + // Very long words trigger O(n^2) behavior in hyphenation, so we disable hyphenation for // unreasonably long words. This is somewhat of a heuristic because extremely long words // are possible in some languages. This does mean that very long real words can get @@ -54,6 +58,9 @@ const size_t LONGEST_HYPHENATED_WORD = 45; // to avoid allocation. const size_t MAX_TEXT_BUF_RETAIN = 32678; +// Maximum amount that spaces can shrink, in justified text. +const float SHRINKABILITY = 1.0 / 3.0; + void LineBreaker::setLocale(const icu::Locale& locale, Hyphenator* hyphenator) { mWordBreaker.setLocale(locale); @@ -66,7 +73,7 @@ void LineBreaker::setText() { // handle initial break here because addStyleRun may never be called mWordBreaker.next(); mCandidates.clear(); - Candidate cand = {0, 0, 0.0, 0.0, 0.0, 0.0, 0, 0}; + Candidate cand = {0, 0, 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0}; mCandidates.push_back(cand); // reset greedy breaker state @@ -78,6 +85,7 @@ void LineBreaker::setText() { mBestScore = SCORE_INFTY; mPreBreak = 0; mFirstTabIndex = INT_MAX; + mSpaceCount = 0; } void LineBreaker::setLineWidths(float firstWidth, int firstWidthLineCount, float restWidth) { @@ -137,7 +145,14 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa hyphenPenalty *= 4.0; // TODO: Replace with a better value after some testing } - mLinePenalty = std::max(mLinePenalty, hyphenPenalty * LINE_PENALTY_MULTIPLIER); + if (mJustified) { + // Make hyphenation more aggressive for fully justified text (so that "normal" in + // justified mode is the same as "full" in ragged-right). + hyphenPenalty *= 0.25; + } else { + // Line penalty is zero for justified text. + mLinePenalty = std::max(mLinePenalty, hyphenPenalty * LINE_PENALTY_MULTIPLIER); + } } size_t current = (size_t)mWordBreaker.current(); @@ -145,6 +160,7 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa size_t lastBreak = start; ParaWidth lastBreakWidth = mWidth; ParaWidth postBreak = mWidth; + size_t postSpaceCount = mSpaceCount; bool temporarilySkipHyphenation = false; for (size_t i = start; i < end; i++) { uint16_t c = mTextBuf[i]; @@ -156,9 +172,11 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa // fall back to greedy; other modes don't know how to deal with tabs mStrategy = kBreakStrategy_Greedy; } else { + if (isWordSpace(c)) mSpaceCount += 1; mWidth += mCharWidths[i]; if (!isLineEndSpace(c)) { postBreak = mWidth; + postSpaceCount = mSpaceCount; afterWord = i + 1; } } @@ -196,11 +214,12 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa ParaWidth hyphPostBreak = lastBreakWidth + firstPartWidth; paint->hyphenEdit = 0; - const float secondPartWith = Layout::measureText(mTextBuf.data(), j, + const float secondPartWidth = Layout::measureText(mTextBuf.data(), j, afterWord - j, mTextBuf.size(), bidiFlags, style, *paint, typeface, nullptr); - ParaWidth hyphPreBreak = postBreak - secondPartWith; - addWordBreak(j, hyphPreBreak, hyphPostBreak, hyphenPenalty, hyph); + ParaWidth hyphPreBreak = postBreak - secondPartWidth; + addWordBreak(j, hyphPreBreak, hyphPostBreak, postSpaceCount, postSpaceCount, + hyphenPenalty, hyph); } } } @@ -210,7 +229,7 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa // Skip break for zero-width characters inside replacement span if (paint != nullptr || current == end || mCharWidths[current] > 0) { float penalty = hyphenPenalty * mWordBreaker.breakBadness(); - addWordBreak(current, mWidth, postBreak, penalty, 0); + addWordBreak(current, mWidth, postBreak, mSpaceCount, postSpaceCount, penalty, 0); } lastBreak = current; lastBreakWidth = mWidth; @@ -224,7 +243,7 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typefa // add a word break (possibly for a hyphenated fragment), and add desperate breaks if // needed (ie when word exceeds current line width) void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, - float penalty, uint8_t hyph) { + size_t preSpaceCount, size_t postSpaceCount, float penalty, uint8_t hyph) { Candidate cand; ParaWidth width = mCandidates.back().preBreak; if (postBreak - width > currentLineWidth()) { @@ -239,6 +258,9 @@ void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth post cand.offset = i; cand.preBreak = width; cand.postBreak = width; + // postSpaceCount doesn't include trailing spaces + cand.preSpaceCount = postSpaceCount; + cand.postSpaceCount = postSpaceCount; cand.penalty = SCORE_DESPERATE; cand.hyphenEdit = 0; #if VERBOSE_DEBUG @@ -255,6 +277,8 @@ void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth post cand.preBreak = preBreak; cand.postBreak = postBreak; cand.penalty = penalty; + cand.preSpaceCount = preSpaceCount; + cand.postSpaceCount = postSpaceCount; cand.hyphenEdit = hyph; #if VERBOSE_DEBUG ALOGD("cand: %zd %g:%g", mCandidates.size(), cand.postBreak, cand.preBreak); @@ -301,6 +325,18 @@ void LineBreaker::addReplacement(size_t start, size_t end, float width) { addStyleRun(nullptr, nullptr, FontStyle(), start, end, false); } +// Get the width of a space. May return 0 if there are no spaces. +// Note: if there are multiple different widths for spaces (for example, because of mixing of +// fonts), it's only guaranteed to pick one. +float LineBreaker::getSpaceWidth() const { + for (size_t i = 0; i < mTextBuf.size(); i++) { + if (isWordSpace(mTextBuf[i])) { + return mCharWidths[i]; + } + } + return 0.0f; +} + float LineBreaker::currentLineWidth() const { return mLineWidths.getLineWidth(mBreaks.size()); } @@ -340,6 +376,10 @@ void LineBreaker::computeBreaksOptimal(bool isRectangle) { size_t active = 0; size_t nCand = mCandidates.size(); float width = mLineWidths.getLineWidth(0); + float shortLineFactor = mJustified ? 0.75f : 0.5f; + float maxShrink = mJustified ? SHRINKABILITY * getSpaceWidth() : 0.0f; + + // "i" iterates through candidates for the end of the line. for (size_t i = 1; i < nCand; i++) { bool atEnd = i == nCand - 1; float best = SCORE_INFTY; @@ -353,6 +393,7 @@ void LineBreaker::computeBreaksOptimal(bool isRectangle) { ParaWidth leftEdge = mCandidates[i].postBreak - width; float bestHope = 0; + // "j" iterates through candidates for the beginning of the line. for (size_t j = active; j < i; j++) { if (!isRectangle) { size_t lineNumber = mCandidates[j].lineNumber; @@ -377,13 +418,24 @@ void LineBreaker::computeBreaksOptimal(bool isRectangle) { // breaks are considered. float widthScore = 0.0f; float additionalPenalty = 0.0f; - if (delta < 0) { + if ((atEnd || !mJustified) && delta < 0) { widthScore = SCORE_OVERFULL; } else if (atEnd && mStrategy != kBreakStrategy_Balanced) { // increase penalty for hyphen on last line additionalPenalty = LAST_LINE_PENALTY_MULTIPLIER * mCandidates[j].penalty; + // Penalize very short (< 1 - shortLineFactor of total width) lines. + float underfill = delta - shortLineFactor * width; + widthScore = underfill > 0 ? underfill * underfill : 0; } else { widthScore = delta * delta; + if (delta < 0) { + if (-delta < maxShrink * + (mCandidates[i].postSpaceCount - mCandidates[j].preSpaceCount)) { + widthScore *= SHRINK_PENALTY_MULTIPLIER; + } else { + widthScore = SCORE_OVERFULL; + } + } } if (delta < 0) { @@ -440,6 +492,7 @@ void LineBreaker::finish() { mStrategy = kBreakStrategy_Greedy; mHyphenationFrequency = kHyphenationFrequency_Normal; mLinePenalty = 0.0f; + mJustified = false; } } // namespace minikin From 41ef8b376f4616ba13e13096f7c03a4caa0c695a Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 13 Dec 2016 16:29:16 +0900 Subject: [PATCH 216/364] Reduce memory usage of FontCollection. Since switching to 64-bit devices, size_t is now a 64-bit integer. FontCollection::Range uses two size_t integers but they just point to an index in mFamilies. To reduce the memory usage, this CL changes the size_t integers to uint8_t. The maximum size of each integer in Range is the size of FontCollection::mFamilies. The largest this can go is the system font list plus a user defined family, which has 91 families. So an 8-bit integer should be enough. With this change, about 84 KiB of memory will be saved per font collection. Since eight font collections are created during bootstrap, about 670 KiB of memory will be saved with this CL. Bug: 33562608 Test: Ran FontCollection.collectionAllocationSizeTest on a 64-bit device. On my Nexus 5X, it changed from 327358 to 241342. Change-Id: I9e01d237c9adcb05e200932401cb1a4780049f86 --- engine/src/flutter/include/minikin/FontCollection.h | 10 +++++----- engine/src/flutter/libs/minikin/FontCollection.cpp | 13 +++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index c9c8520be6b..f6312dcea59 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -58,8 +58,8 @@ private: static const int kPageMask = (1 << kLogCharsPerPage) - 1; struct Range { - size_t start; - size_t end; + uint8_t start; + uint8_t end; }; FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const; @@ -87,14 +87,14 @@ private: // This vector can't be empty. std::vector mFamilies; - // This vector contains pointers into mInstances + // This vector contains indices into mFamilies. // This vector can't be empty. - std::vector mFamilyVec; + std::vector mFamilyVec; // This vector has pointers to the font family instance which has cmap 14 subtable. std::vector mVSFamilyVec; - // These are offsets into mInstanceVec, one range per page + // These are offsets into mFamilyVec, one range per page std::vector mRanges; }; diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 365d7752b00..7ad2f48565a 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -111,6 +111,8 @@ FontCollection::FontCollection(const vector& typefaces) : nTypefaces = mFamilies.size(); LOG_ALWAYS_FATAL_IF(nTypefaces == 0, "Font collection must have at least one valid typeface"); + LOG_ALWAYS_FATAL_IF(nTypefaces > 254, + "Up to 254 font families can be registered to collection."); size_t nPages = (mMaxChar + kPageMask) >> kLogCharsPerPage; size_t offset = 0; // TODO: Use variation selector map for mRanges construction. @@ -124,11 +126,11 @@ FontCollection::FontCollection(const vector& typefaces) : #ifdef VERBOSE_DEBUG ALOGD("i=%zd: range start = %zd\n", i, offset); #endif - range->start = offset; + range->start = (uint8_t)offset; for (size_t j = 0; j < nTypefaces; j++) { if (lastChar[j] < (i + 1) << kLogCharsPerPage) { FontFamily* family = mFamilies[j]; - mFamilyVec.push_back(family); + mFamilyVec.push_back((uint8_t)j); offset++; uint32_t nextChar = family->getCoverage()->nextSetBit((i + 1) << kLogCharsPerPage); #ifdef VERBOSE_DEBUG @@ -137,7 +139,7 @@ FontCollection::FontCollection(const vector& typefaces) : lastChar[j] = nextChar; } } - range->end = offset; + range->end = (uint8_t)offset; } } @@ -284,11 +286,10 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, return mFamilies[0]; } - const std::vector& familyVec = (vs == 0) ? mFamilyVec : mFamilies; Range range = mRanges[ch >> kLogCharsPerPage]; if (vs != 0) { - range = { 0, mFamilies.size() }; + range = { 0, (uint8_t)mFamilies.size() }; } #ifdef VERBOSE_DEBUG @@ -297,7 +298,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, FontFamily* bestFamily = nullptr; uint32_t bestScore = kUnsupportedFontScore; for (size_t i = range.start; i < range.end; i++) { - FontFamily* family = familyVec[i]; + FontFamily* family = vs == 0 ? mFamilies[mFamilyVec[i]] : mFamilies[i]; const uint32_t score = calcFamilyScore(ch, vs, variant, langListId, family); if (score == kFirstFontScore) { // If the first font family supports the given character or variation sequence, always From 707bbae8ffe73ecc96a1937113ed596de6633d56 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Mon, 9 Jan 2017 13:33:48 -0800 Subject: [PATCH 217/364] minikin: use log/log.h when utilizing ALOG macros Use log/log.h to harden code against liblog changes. Test: compile Bug: 30465923 Change-Id: I3dea82e76d28d9ef52d7c0f11e038c4298863eb9 --- engine/src/flutter/libs/minikin/FontCollection.cpp | 2 +- engine/src/flutter/libs/minikin/FontFamily.cpp | 2 +- engine/src/flutter/libs/minikin/FontLanguageListCache.cpp | 2 +- engine/src/flutter/libs/minikin/HbFontCache.cpp | 2 +- engine/src/flutter/libs/minikin/Layout.cpp | 2 +- engine/src/flutter/libs/minikin/LineBreaker.cpp | 2 +- engine/src/flutter/libs/minikin/MinikinInternal.cpp | 2 +- engine/src/flutter/libs/minikin/SparseBitSet.cpp | 2 +- engine/src/flutter/tests/FontTestUtils.cpp | 2 +- engine/src/flutter/tests/MinikinFontForTest.cpp | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index ddda7bc09a6..f5e22903180 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -20,7 +20,7 @@ #include -#include +#include #include "unicode/unistr.h" #include "unicode/unorm2.h" diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 6d45c67126e..cbfa1cfffc3 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp index 9a409e658bf..b5c40f1ddb7 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include "FontLanguage.h" #include "MinikinInternal.h" diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index 08687571ba8..3137125a264 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -18,7 +18,7 @@ #include "HbFontCache.h" -#include +#include #include #include diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 45cb06680ff..d63cda0d300 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index bc8cb800ee7..21d1d8df6cf 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -20,7 +20,7 @@ #include -#include +#include #include #include diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index 5900c1852ca..a5d1eada1f7 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -21,7 +21,7 @@ #include "HbFontCache.h" #include "generated/UnicodeData.h" -#include +#include namespace android { diff --git a/engine/src/flutter/libs/minikin/SparseBitSet.cpp b/engine/src/flutter/libs/minikin/SparseBitSet.cpp index aa73c126707..ac21bb8f0ca 100644 --- a/engine/src/flutter/libs/minikin/SparseBitSet.cpp +++ b/engine/src/flutter/libs/minikin/SparseBitSet.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include diff --git a/engine/src/flutter/tests/FontTestUtils.cpp b/engine/src/flutter/tests/FontTestUtils.cpp index 9d36d2f6cb9..f799f199e0b 100644 --- a/engine/src/flutter/tests/FontTestUtils.cpp +++ b/engine/src/flutter/tests/FontTestUtils.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include "FontLanguage.h" #include "MinikinFontForTest.h" diff --git a/engine/src/flutter/tests/MinikinFontForTest.cpp b/engine/src/flutter/tests/MinikinFontForTest.cpp index 7933d2457e0..9330a652dd9 100644 --- a/engine/src/flutter/tests/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/MinikinFontForTest.cpp @@ -22,7 +22,7 @@ #include -#include +#include MinikinFontForTest::MinikinFontForTest(const std::string& font_path) : MinikinFontForTest(font_path, SkTypeface::CreateFromFile(font_path.c_str())) { From d1c5b172cb9638daab6864b0cade9ed3eab6d6f0 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Sun, 4 Dec 2016 08:52:34 -0800 Subject: [PATCH 218/364] Use HarfBuzz metric implementation for emoji font. To avoid lock contention in Skia, use HarfBuzz implementation for retrieving boundary box and advance information from font. Bug: 21705974 Test: Manually done Change-Id: Ia88cb670ca9e0bb352bccef22c5ea3a789bcc1da --- engine/src/flutter/libs/minikin/Layout.cpp | 54 +++++++++++++++---- .../flutter/libs/minikin/MinikinInternal.h | 4 +- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 15441a2d663..874002c18bd 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -294,16 +294,36 @@ static hb_bool_t harfbuzzGetGlyphHorizontalOrigin(hb_font_t* /* hbFont */, void* return true; } -hb_font_funcs_t* getHbFontFuncs() { - static hb_font_funcs_t* hbFontFuncs = 0; +hb_font_funcs_t* getHbFontFuncs(bool forColorBitmapFont) { + assertMinikinLocked(); - if (hbFontFuncs == 0) { - hbFontFuncs = hb_font_funcs_create(); - hb_font_funcs_set_glyph_h_advance_func(hbFontFuncs, harfbuzzGetGlyphHorizontalAdvance, 0, 0); - hb_font_funcs_set_glyph_h_origin_func(hbFontFuncs, harfbuzzGetGlyphHorizontalOrigin, 0, 0); - hb_font_funcs_make_immutable(hbFontFuncs); + static hb_font_funcs_t* hbFuncs = nullptr; + static hb_font_funcs_t* hbFuncsForColorBitmap = nullptr; + + hb_font_funcs_t** funcs = forColorBitmapFont ? &hbFuncs : &hbFuncsForColorBitmap; + if (*funcs == nullptr) { + *funcs = hb_font_funcs_create(); + if (forColorBitmapFont) { + // Override the h_advance function since we can't use HarfBuzz's implemenation. It may + // return the wrong value if the font uses hinting aggressively. + hb_font_funcs_set_glyph_h_advance_func(*funcs, harfbuzzGetGlyphHorizontalAdvance, 0, 0); + } else { + // Don't override the h_advance function since we use HarfBuzz's implementation for + // emoji for performance reasons. + // Note that it is technically possible for a TrueType font to have outline and embedded + // bitmap at the same time. We ignore modified advances of hinted outline glyphs in that + // case. + } + hb_font_funcs_set_glyph_h_origin_func(*funcs, harfbuzzGetGlyphHorizontalOrigin, 0, 0); + hb_font_funcs_make_immutable(*funcs); } - return hbFontFuncs; + return *funcs; +} + +static bool isColorBitmapFont(hb_font_t* font) { + hb_face_t* face = hb_font_get_face(font); + HbBlob cbdt(hb_face_reference_table(face, HB_TAG('C', 'B', 'D', 'T'))); + return cbdt.size() > 0; } static float HBFixedToFloat(hb_position_t v) @@ -335,7 +355,7 @@ int Layout::findFace(FakedFont face, LayoutContext* ctx) { // corresponding hb_font object. if (ctx != NULL) { hb_font_t* font = getHbFontLocked(face.font); - hb_font_set_funcs(font, getHbFontFuncs(), &ctx->paint, 0); + hb_font_set_funcs(font, getHbFontFuncs(isColorBitmapFont(font)), &ctx->paint, 0); ctx->hbFonts.push_back(font); } return ix; @@ -753,6 +773,8 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t hb_font_set_ppem(hbFont, size * scaleX, size); hb_font_set_scale(hbFont, HBFloatToFixed(size * scaleX), HBFloatToFixed(size)); + const bool is_color_bitmap_font = isColorBitmapFont(hbFont); + // TODO: if there are multiple scripts within a font in an RTL run, // we need to reorder those runs. This is unlikely with our current // font stack, but should be done for correctness. @@ -844,7 +866,19 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t xAdvance = roundf(xAdvance); } MinikinRect glyphBounds; - ctx->paint.font->GetBounds(&glyphBounds, glyph_ix, ctx->paint); + hb_glyph_extents_t extents = {}; + if (is_color_bitmap_font && hb_font_get_glyph_extents(hbFont, glyph_ix, &extents)) { + // Note that it is technically possible for a TrueType font to have outline and + // embedded bitmap at the same time. We ignore modified bbox of hinted outline + // glyphs in that case. + glyphBounds.mLeft = roundf(HBFixedToFloat(extents.x_bearing)); + glyphBounds.mTop = roundf(HBFixedToFloat(-extents.y_bearing)); + glyphBounds.mRight = roundf(HBFixedToFloat(extents.x_bearing + extents.width)); + glyphBounds.mBottom = + roundf(HBFixedToFloat(-extents.y_bearing - extents.height)); + } else { + ctx->paint.font->GetBounds(&glyphBounds, glyph_ix, ctx->paint); + } glyphBounds.offset(x + xoff, y + yoff); mBounds.join(glyphBounds); if (info[i].cluster - start < count) { diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.h b/engine/src/flutter/libs/minikin/MinikinInternal.h index 88d54d7b11f..9557d827df1 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.h +++ b/engine/src/flutter/libs/minikin/MinikinInternal.h @@ -65,9 +65,7 @@ public: } size_t size() const { - unsigned int length = 0; - hb_blob_get_data(mBlob, &length); - return (size_t)length; + return (size_t)hb_blob_get_length(mBlob); } private: From 16768d72e08177581af129e6846555948d883b53 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Fri, 6 Jan 2017 15:25:59 +0900 Subject: [PATCH 219/364] Fix GraphemeBreak test failures. GraphemeBreak.tailoring/GraphemeBreak.genderBalancedEmoji start failing after ICU update to 58. The failure is around Rule GB9 in Unicode Standard Annex #29. GB9 forbids breaks before extending characters and before ZWJ. However the implementation in minikin only checks for extending characters. It used to work with Unicode 8.0 since ZWJ had the Grapheme_Cluster_Break property of Extend in Unicode 8.0 but it no longer has that property in Uniocde 9.0. Thus, we need to check for ZWJ explicitly. At the same time, this removes manually added PREPEND characters case from tailoredGraphemeClusterBreak which is already supported in ICU 58. Test: minikin_tests passes Bug: 34117643 Change-Id: Ib46d48bebe4a866208e050d7defc715c61fcbeb1 --- .../flutter/libs/minikin/GraphemeBreak.cpp | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index dc5a7619370..1b3d1ab33ba 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -39,17 +39,6 @@ int32_t tailoredGraphemeClusterBreak(uint32_t c) { || c == 0xFEFF // BOM || ((c | 0x7F) == 0xE007F)) // recently undeprecated tag characters in Plane 14 return U_GCB_EXTEND; - // UTC-approved characters for the Prepend class, per - // http://www.unicode.org/L2/L2015/15183r-graph-cluster-brk.txt - // These should be removed when our copy of ICU gets updated to Unicode 9.0 (~2016 or 2017). - else if ((0x0600 <= c && c <= 0x0605) // Arabic subtending marks - || c == 0x06DD // ARABIC SUBTENDING MARK - || c == 0x070F // SYRIAC ABBREVIATION MARK - || c == 0x0D4E // MALAYALAM LETTER DOT REPH - || c == 0x110BD // KAITHI NUMBER SIGN - || c == 0x111C2 // SHARADA SIGN JIHVAMULIYA - || c == 0x111C3) // SHARADA SIGN UPADHMANIYA - return U_GCB_PREPEND; // THAI CHARACTER SARA AM is treated as a normal letter by most other implementations: they // allow a grapheme break before it. else if (c == 0x0E33) @@ -59,7 +48,7 @@ int32_t tailoredGraphemeClusterBreak(uint32_t c) { } // Returns true for all characters whose IndicSyllabicCategory is Pure_Killer. -// From http://www.unicode.org/Public/8.0.0/ucd/IndicSyllabicCategory.txt +// From http://www.unicode.org/Public/9.0.0/ucd/IndicSyllabicCategory.txt bool isPureKiller(uint32_t c) { return (c == 0x0E3A || c == 0x0E4E || c == 0x0F84 || c == 0x103A || c == 0x1714 || c == 0x1734 || c == 0x17D1 || c == 0x1BAA || c == 0x1BF2 || c == 0x1BF3 || c == 0xA806 @@ -132,8 +121,8 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co // The number 4 comes from the number of code units in a whole flag. return (offset - 2 - offset_back) % 4 == 0; } - // Rule GB9, x Extend; Rule GB9a, x SpacingMark; Rule GB9b, Prepend x - if (p2 == U_GCB_EXTEND || p2 == U_GCB_SPACING_MARK || p1 == U_GCB_PREPEND) { + // Rule GB9, x (Extend | ZWJ); Rule GB9a, x SpacingMark; Rule GB9b, Prepend x + if (p2 == U_GCB_EXTEND || p2 == U_GCB_ZWJ || p2 == U_GCB_SPACING_MARK || p1 == U_GCB_PREPEND) { return false; } // Cluster indic syllables together (tailoring of UAX #29) @@ -150,7 +139,7 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co return false; } // Tailoring: make emoji sequences with ZWJ a single grapheme cluster - if (c1 == 0x200D && isEmoji(c2) && offset_back > start) { + if (p1 == U_GCB_ZWJ && isEmoji(c2) && offset_back > start) { // look at character before ZWJ to see that both can participate in an emoji zwj sequence uint32_t c0 = 0; U16_PREV(buf, start, offset_back, c0); @@ -164,6 +153,10 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co } // Proposed Rule GB9c from http://www.unicode.org/L2/L2016/16011r3-break-prop-emoji.pdf // E_Base x E_Modifier + // TODO: Migrate to Rule GB10 and Rule GB11 with fixing following test cases in + // GraphemeBreak.tailoring and GraphemeBreak.emojiModifiers (Bug: 34211654) + // U+0628 U+200D U+2764 is expected to have grapheme boundary after U+200D. + // U+270C U+FE0E U+1F3FB is expected to have grapheme boundary after U+200D. if (isEmojiModifier(c2)) { if (c1 == 0xFE0F && offset_back > start) { // skip over emoji variation selector From 0470cdb3e41f0ae603f6a3e89efabdc196424652 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 29 Dec 2016 00:36:30 +0900 Subject: [PATCH 220/364] Remove FontFamily.addFont and make FontFamily immutable. This lays the groundwork for making SparseBitSet serializable. FontFamily.addFont is only used when the FontFamily is constructed. Thus, instead of calling FontFamily.addFont multiple time, passes Font list to the constructor. By this change, FontFamily can be immutable now. By making FontFamily immutable, We can create FontFamily with pre-calculated SparseBitSet. Bug: 34042446 Test: minikin_tests has passed Change-Id: I2576789fba6cb27687e920e2488e8bedbcf7d36f --- .../src/flutter/include/minikin/FontFamily.h | 57 ++++----- .../flutter/libs/minikin/FontCollection.cpp | 18 ++- .../src/flutter/libs/minikin/FontFamily.cpp | 115 ++++++++---------- engine/src/flutter/sample/example.cpp | 8 +- engine/src/flutter/sample/example_skia.cpp | 8 +- .../unittest/FontCollectionItemizeTest.cpp | 46 ++++--- .../tests/unittest/FontCollectionTest.cpp | 4 +- .../flutter/tests/unittest/FontFamilyTest.cpp | 22 ++-- .../src/flutter/tests/util/FontTestUtils.cpp | 25 ++-- 9 files changed, 139 insertions(+), 164 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 10362c24de1..bdf00e9f7c4 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -98,64 +98,61 @@ struct FakedFont { FontFakery fakery; }; +struct Font { + Font(MinikinFont* typeface, FontStyle style); + Font(Font&& o); + Font(const Font& o); + ~Font(); + + MinikinFont* typeface; + FontStyle style; +}; + class FontFamily : public MinikinRefCounted { public: - FontFamily(); - - explicit FontFamily(int variant); - - FontFamily(uint32_t langId, int variant) - : mLangId(langId), - mVariant(variant), - mHasVSTable(false), - mCoverageValid(false) { - } + explicit FontFamily(std::vector&& fonts); + FontFamily(int variant, std::vector&& fonts); + FontFamily(uint32_t langId, int variant, std::vector&& fonts); ~FontFamily(); - // Add font to family, extracting style information from the font - bool addFont(MinikinFont* typeface); + // TODO: Good to expose FontUtil.h. + static bool analyzeStyle(MinikinFont* typeface, int* weight, bool* italic); - void addFont(MinikinFont* typeface, FontStyle style); FakedFont getClosestMatch(FontStyle style) const; uint32_t langId() const { return mLangId; } int variant() const { return mVariant; } // API's for enumerating the fonts in a family. These don't guarantee any particular order - size_t getNumFonts() const; - MinikinFont* getFont(size_t index) const; - FontStyle getStyle(size_t index) const; + size_t getNumFonts() const { return mFonts.size(); } + MinikinFont* getFont(size_t index) const { return mFonts[index].typeface; } + FontStyle getStyle(size_t index) const { return mFonts[index].style; } bool isColorEmojiFamily() const; - // Get Unicode coverage. Lifetime of returned bitset is same as receiver. May return nullptr on - // error. - const SparseBitSet* getCoverage(); + // Get Unicode coverage. + const SparseBitSet& getCoverage() const { return mCoverage; } // Returns true if the font has a glyph for the code point and variation selector pair. // Caller should acquire a lock before calling the method. - bool hasGlyph(uint32_t codepoint, uint32_t variationSelector); + bool hasGlyph(uint32_t codepoint, uint32_t variationSelector) const; // Returns true if this font family has a variaion sequence table (cmap format 14 subtable). - bool hasVSTable() const; + bool hasVSTable() const { return mHasVSTable; } private: - void addFontLocked(MinikinFont* typeface, FontStyle style); + void computeCoverage(); - class Font { - public: - Font(MinikinFont* typeface, FontStyle style) : - typeface(typeface), style(style) { } - MinikinFont* typeface; - FontStyle style; - }; uint32_t mLangId; int mVariant; std::vector mFonts; SparseBitSet mCoverage; bool mHasVSTable; - bool mCoverageValid; + + // Forbid copying and assignment. + FontFamily(const FontFamily&) = delete; + void operator=(const FontFamily&) = delete; }; } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 9d26377e6d1..4688520699d 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -96,17 +96,13 @@ FontCollection::FontCollection(const vector& typefaces) : continue; } family->RefLocked(); - const SparseBitSet* coverage = family->getCoverage(); - if (coverage == nullptr) { - family->UnrefLocked(); - continue; - } + const SparseBitSet& coverage = family->getCoverage(); mFamilies.push_back(family); // emplace_back would be better if (family->hasVSTable()) { mVSFamilyVec.push_back(family); } - mMaxChar = max(mMaxChar, coverage->length()); - lastChar.push_back(coverage->nextSetBit(0)); + mMaxChar = max(mMaxChar, coverage.length()); + lastChar.push_back(coverage.nextSetBit(0)); } nTypefaces = mFamilies.size(); LOG_ALWAYS_FATAL_IF(nTypefaces == 0, @@ -130,7 +126,7 @@ FontCollection::FontCollection(const vector& typefaces) : FontFamily* family = mFamilies[j]; mFamilyVec.push_back(family); offset++; - uint32_t nextChar = family->getCoverage()->nextSetBit((i + 1) << kLogCharsPerPage); + uint32_t nextChar = family->getCoverage().nextSetBit((i + 1) << kLogCharsPerPage); #ifdef VERBOSE_DEBUG ALOGD("nextChar = %d (j = %zd)\n", nextChar, j); #endif @@ -197,7 +193,7 @@ uint32_t FontCollection::calcFamilyScore(uint32_t ch, uint32_t vs, int variant, // variation sequence's base character. uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, FontFamily* fontFamily) const { const bool hasVSGlyph = (vs != 0) && fontFamily->hasGlyph(ch, vs); - if (!hasVSGlyph && !fontFamily->getCoverage()->get(ch)) { + if (!hasVSGlyph && !fontFamily->getCoverage().get(ch)) { // The font doesn't support either variation sequence or even the base character. return kUnsupportedFontScore; } @@ -416,7 +412,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty if (lastFamily != nullptr) { if (isStickyWhitelisted(ch)) { // Continue using existing font as long as it has coverage and is whitelisted - shouldContinueRun = lastFamily->getCoverage()->get(ch); + shouldContinueRun = lastFamily->getCoverage().get(ch); } else if (isVariationSelector(ch)) { // Always continue if the character is a variation selector. shouldContinueRun = true; @@ -436,7 +432,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty if (utf16Pos != 0 && ((U_GET_GC_MASK(ch) & U_GC_M_MASK) != 0 || (isEmojiModifier(ch) && isEmojiBase(prevCh))) && - family && family->getCoverage()->get(prevCh)) { + family && family->getCoverage().get(prevCh)) { const size_t prevChLength = U16_LENGTH(prevCh); run->end -= prevChLength; if (run->start == run->end) { diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 8efa32a937e..164cc7d8ad8 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -64,45 +64,51 @@ uint32_t FontStyle::pack(int variant, int weight, bool italic) { return (weight & kWeightMask) | (italic ? kItalicMask : 0) | (variant << kVariantShift); } -FontFamily::FontFamily() : FontFamily(0 /* variant */) { +Font::Font(MinikinFont* typeface, FontStyle style) + : typeface(typeface), style(style) { + typeface->Ref(); } -FontFamily::FontFamily(int variant) : FontFamily(FontLanguageListCache::kEmptyListId, variant) { +Font::Font(Font&& o) { + typeface = o.typeface; + style = o.style; + o.typeface = nullptr; +} + +Font::Font(const Font& o) { + typeface = o.typeface; + typeface->Ref(); + style = o.style; +} + +Font::~Font() { + if (typeface == nullptr) { + return; + } + typeface->UnrefLocked(); +} + +FontFamily::FontFamily(std::vector&& fonts) : FontFamily(0 /* variant */, std::move(fonts)) { +} + +FontFamily::FontFamily(int variant, std::vector&& fonts) + : FontFamily(FontLanguageListCache::kEmptyListId, variant, std::move(fonts)) { +} + +FontFamily::FontFamily(uint32_t langId, int variant, std::vector&& fonts) + : mLangId(langId), mVariant(variant), mFonts(std::move(fonts)), mHasVSTable(false) { + computeCoverage(); } FontFamily::~FontFamily() { - for (size_t i = 0; i < mFonts.size(); i++) { - mFonts[i].typeface->UnrefLocked(); - } } -bool FontFamily::addFont(MinikinFont* typeface) { +bool FontFamily::analyzeStyle(MinikinFont* typeface, int* weight, bool* italic) { android::AutoMutex _l(gMinikinLock); const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2'); HbBlob os2Table(getFontTable(typeface, os2Tag)); if (os2Table.get() == nullptr) return false; - int weight; - bool italic; - if (analyzeStyle(os2Table.get(), os2Table.size(), &weight, &italic)) { - //ALOGD("analyzed weight = %d, italic = %s", weight, italic ? "true" : "false"); - FontStyle style(weight, italic); - addFontLocked(typeface, style); - return true; - } else { - ALOGD("failed to analyze style"); - } - return false; -} - -void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { - android::AutoMutex _l(gMinikinLock); - addFontLocked(typeface, style); -} - -void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { - typeface->RefLocked(); - mFonts.push_back(Font(typeface, style)); - mCoverageValid = false; + return ::minikin::analyzeStyle(os2Table.get(), os2Table.size(), weight, italic); } // Compute a matching metric between two styles - 0 is an exact match @@ -146,18 +152,6 @@ FakedFont FontFamily::getClosestMatch(FontStyle style) const { return result; } -size_t FontFamily::getNumFonts() const { - return mFonts.size(); -} - -MinikinFont* FontFamily::getFont(size_t index) const { - return mFonts[index].typeface; -} - -FontStyle FontFamily::getStyle(size_t index) const { - return mFonts[index].style; -} - bool FontFamily::isColorEmojiFamily() const { const FontLanguages& languageList = FontLanguageListCache::getById(mLangId); for (size_t i = 0; i < languageList.size(); ++i) { @@ -168,30 +162,24 @@ bool FontFamily::isColorEmojiFamily() const { return false; } -const SparseBitSet* FontFamily::getCoverage() { - if (!mCoverageValid) { - const FontStyle defaultStyle; - MinikinFont* typeface = getClosestMatch(defaultStyle).font; - const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); - HbBlob cmapTable(getFontTable(typeface, cmapTag)); - if (cmapTable.get() == nullptr) { - ALOGE("Could not get cmap table size!\n"); - // Note: This means we will retry on the next call to getCoverage, as we can't store - // the failure. This is fine, as we assume this doesn't really happen in practice. - return nullptr; - } - // TODO: Error check? - CmapCoverage::getCoverage(mCoverage, cmapTable.get(), cmapTable.size(), &mHasVSTable); -#ifdef VERBOSE_DEBUG - ALOGD("font coverage length=%d, first ch=%x\n", mCoverage.length(), - mCoverage.nextSetBit(0)); -#endif - mCoverageValid = true; +void FontFamily::computeCoverage() { + android::AutoMutex _l(gMinikinLock); + const FontStyle defaultStyle; + MinikinFont* typeface = getClosestMatch(defaultStyle).font; + const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); + HbBlob cmapTable(getFontTable(typeface, cmapTag)); + if (cmapTable.get() == nullptr) { + ALOGE("Could not get cmap table size!\n"); + return; } - return &mCoverage; + // TODO: Error check? + CmapCoverage::getCoverage(mCoverage, cmapTable.get(), cmapTable.size(), &mHasVSTable); +#ifdef VERBOSE_DEBUG + ALOGD("font coverage length=%d, first ch=%x\n", mCoverage.length(), mCoverage.nextSetBit(0)); +#endif } -bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) { +bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) const { assertMinikinLocked(); if (variationSelector != 0 && !mHasVSTable) { // Early exit if the variation selector is specified but the font doesn't have a cmap format @@ -208,9 +196,4 @@ bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) { return result; } -bool FontFamily::hasVSTable() const { - LOG_ALWAYS_FATAL_IF(!mCoverageValid, "Do not call this method before getCoverage() call"); - return mHasVSTable; -} - } // namespace minikin diff --git a/engine/src/flutter/sample/example.cpp b/engine/src/flutter/sample/example.cpp index a27918ea758..1c9c322d232 100644 --- a/engine/src/flutter/sample/example.cpp +++ b/engine/src/flutter/sample/example.cpp @@ -45,9 +45,9 @@ FontCollection *makeFontCollection() { "/system/fonts/Roboto-LightItalic.ttf" }; - FontFamily *family = new FontFamily(); FT_Face face; FT_Error error; + std::vector fonts; for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) { const char *fn = fns[i]; printf("adding %s\n", fn); @@ -56,16 +56,16 @@ FontCollection *makeFontCollection() { printf("error loading %s, %d\n", fn, error); } MinikinFont *font = new MinikinFontFreeType(face); - family->addFont(font); + fonts.push_back(Font(font, FontStyle())); } + FontFamily *family = new FontFamily(std::move(fonts)); typefaces.push_back(family); #if 1 - family = new FontFamily(); const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf"; error = FT_New_Face(library, fn, 0, &face); MinikinFont *font = new MinikinFontFreeType(face); - family->addFont(font); + family = new FontFamily(std::vector({ Font(font, FontStyle()) })); typefaces.push_back(family); #endif diff --git a/engine/src/flutter/sample/example_skia.cpp b/engine/src/flutter/sample/example_skia.cpp index b04c8abcbcc..6e6f868051c 100644 --- a/engine/src/flutter/sample/example_skia.cpp +++ b/engine/src/flutter/sample/example_skia.cpp @@ -54,21 +54,21 @@ FontCollection *makeFontCollection() { "/system/fonts/Roboto-LightItalic.ttf" }; - FontFamily *family = new FontFamily(); + std::vector fonts; for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) { const char *fn = fns[i]; sk_sp skFace = SkTypeface::MakeFromFile(fn); MinikinFont *font = new MinikinFontSkia(std::move(skFace)); - family->addFont(font); + fonts.push_back(Font(font, FontStyle())); } + FontFamily *family = new FontFamily(std::move(fonts)); typefaces.push_back(family); #if 1 - family = new FontFamily(); const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf"; sk_sp skFace = SkTypeface::MakeFromFile(fn); MinikinFont *font = new MinikinFontSkia(std::move(skFace)); - family->addFont(font); + family = new FontFamily(std::vector({ Font(font, FontStyle()) })); typefaces.push_back(family); #endif diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 52786d0c7e0..5c5a5d343cb 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -668,14 +668,14 @@ TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { const std::string kVSTestFont = kTestFontDir "VarioationSelectorTest-Regular.ttf"; std::vector families; - FontFamily* family1 = new FontFamily(VARIANT_DEFAULT); MinikinAutoUnref font(new MinikinFontForTest(kLatinFont)); - family1->addFont(font.get()); + FontFamily* family1 = new FontFamily(VARIANT_DEFAULT, + std::vector{ Font(font.get(), FontStyle()) }); families.push_back(family1); - FontFamily* family2 = new FontFamily(VARIANT_DEFAULT); MinikinAutoUnref font2(new MinikinFontForTest(kVSTestFont)); - family2->addFont(font2.get()); + FontFamily* family2 = new FontFamily(VARIANT_DEFAULT, + std::vector{ Font(font2.get(), FontStyle()) }); families.push_back(family2); FontCollection collection(families); @@ -811,11 +811,11 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { std::vector families; // Prepare first font which doesn't supports U+9AA8 - FontFamily* firstFamily = new FontFamily( - FontStyle::registerLanguageList("und"), 0 /* variant */); MinikinAutoUnref firstFamilyMinikinFont( new MinikinFontForTest(kNoGlyphFont)); - firstFamily->addFont(firstFamilyMinikinFont.get()); + FontFamily* firstFamily = new FontFamily( + FontStyle::registerLanguageList("und"), 0 /* variant */, + std::vector({ Font(firstFamilyMinikinFont.get(), FontStyle()) })); families.push_back(firstFamily); // Prepare font families @@ -824,10 +824,10 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { std::unordered_map fontLangIdxMap; for (size_t i = 0; i < testCase.fontLanguages.size(); ++i) { - FontFamily* family = new FontFamily( - FontStyle::registerLanguageList(testCase.fontLanguages[i]), 0 /* variant */); MinikinAutoUnref minikin_font(new MinikinFontForTest(kJAFont)); - family->addFont(minikin_font.get()); + FontFamily* family = new FontFamily( + FontStyle::registerLanguageList(testCase.fontLanguages[i]), 0 /* variant */, + std::vector({ Font(minikin_font.get(), FontStyle()) })); families.push_back(family); fontLangIdxMap.insert(std::make_pair(minikin_font.get(), i)); } @@ -1417,13 +1417,12 @@ TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS) { MinikinAutoUnref fontA(new MinikinFontForTest(kZH_HansFont)); MinikinAutoUnref fontB(new MinikinFontForTest(kZH_HansFont)); - MinikinAutoUnref dummyFamily(new FontFamily()); - MinikinAutoUnref familyA(new FontFamily()); - MinikinAutoUnref familyB(new FontFamily()); - - dummyFamily->addFont(dummyFont.get()); - familyA->addFont(fontA.get()); - familyB->addFont(fontB.get()); + MinikinAutoUnref dummyFamily(new FontFamily( + std::vector({ Font(dummyFont.get(), FontStyle()) }))); + MinikinAutoUnref familyA(new FontFamily( + std::vector({ Font(fontA.get(), FontStyle()) }))); + MinikinAutoUnref familyB(new FontFamily( + std::vector({ Font(fontB.get(), FontStyle()) }))); std::vector families = { dummyFamily.get(), familyA.get(), familyB.get() }; @@ -1453,13 +1452,12 @@ TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS2) { MinikinAutoUnref noCmapFormat14Font( new MinikinFontForTest(kNoCmapFormat14Font)); - MinikinAutoUnref dummyFamily(new FontFamily()); - MinikinAutoUnref hasCmapFormat14Family(new FontFamily()); - MinikinAutoUnref noCmapFormat14Family(new FontFamily()); - - dummyFamily->addFont(dummyFont.get()); - hasCmapFormat14Family->addFont(hasCmapFormat14Font.get()); - noCmapFormat14Family->addFont(noCmapFormat14Font.get()); + MinikinAutoUnref dummyFamily(new FontFamily( + std::vector({ Font(dummyFont.get(), FontStyle()) }))); + MinikinAutoUnref hasCmapFormat14Family(new FontFamily( + std::vector({ Font(hasCmapFormat14Font.get(), FontStyle()) }))); + MinikinAutoUnref noCmapFormat14Family(new FontFamily( + std::vector({ Font(noCmapFormat14Font.get(), FontStyle()) }))); std::vector families = { dummyFamily.get(), hasCmapFormat14Family.get(), noCmapFormat14Family.get() }; diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index 62d2f022fa3..c0b6b526b78 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -57,9 +57,9 @@ void expectVSGlyphs(const FontCollection* fc, uint32_t codepoint, const std::set } TEST(FontCollectionTest, hasVariationSelectorTest) { - MinikinAutoUnref family(new FontFamily()); MinikinAutoUnref font(new MinikinFontForTest(kVsTestFont)); - family->addFont(font.get()); + MinikinAutoUnref family(new FontFamily( + std::vector({ Font(font.get(), FontStyle()) }))); std::vector families({family.get()}); MinikinAutoUnref fc(new FontCollection(families)); diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 44098018929..ddc36e45704 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -464,8 +464,10 @@ void expectVSGlyphs(FontFamily* family, uint32_t codepoint, const std::set minikinFont(new MinikinFontForTest(kVsTestFont)); - MinikinAutoUnref family(new FontFamily); - family->addFont(minikinFont.get()); + MinikinAutoUnref family( + new FontFamily(std::vector{ + Font(minikinFont.get(), FontStyle()) + })); android::AutoMutex _l(gMinikinLock); @@ -478,23 +480,23 @@ TEST_F(FontFamilyTest, hasVariationSelectorTest) { const uint32_t kVS20 = 0xE0103; const uint32_t kSupportedChar1 = 0x82A6; - EXPECT_TRUE(family->getCoverage()->get(kSupportedChar1)); + EXPECT_TRUE(family->getCoverage().get(kSupportedChar1)); expectVSGlyphs(family.get(), kSupportedChar1, std::set({kVS1, kVS17, kVS18, kVS19})); const uint32_t kSupportedChar2 = 0x845B; - EXPECT_TRUE(family->getCoverage()->get(kSupportedChar2)); + EXPECT_TRUE(family->getCoverage().get(kSupportedChar2)); expectVSGlyphs(family.get(), kSupportedChar2, std::set({kVS2, kVS18, kVS19, kVS20})); const uint32_t kNoVsSupportedChar = 0x537F; - EXPECT_TRUE(family->getCoverage()->get(kNoVsSupportedChar)); + EXPECT_TRUE(family->getCoverage().get(kNoVsSupportedChar)); expectVSGlyphs(family.get(), kNoVsSupportedChar, std::set()); const uint32_t kVsOnlySupportedChar = 0x717D; - EXPECT_FALSE(family->getCoverage()->get(kVsOnlySupportedChar)); + EXPECT_FALSE(family->getCoverage().get(kVsOnlySupportedChar)); expectVSGlyphs(family.get(), kVsOnlySupportedChar, std::set({kVS3, kVS19, kVS20})); const uint32_t kNotSupportedChar = 0x845C; - EXPECT_FALSE(family->getCoverage()->get(kNotSupportedChar)); + EXPECT_FALSE(family->getCoverage().get(kNotSupportedChar)); expectVSGlyphs(family.get(), kNotSupportedChar, std::set()); } @@ -518,11 +520,9 @@ TEST_F(FontFamilyTest, hasVSTableTest) { MinikinAutoUnref minikinFont( new MinikinFontForTest(testCase.fontPath)); - MinikinAutoUnref family(new FontFamily); - family->addFont(minikinFont.get()); + MinikinAutoUnref family(new FontFamily( + std::vector{ Font(minikinFont.get(), FontStyle()) })); android::AutoMutex _l(gMinikinLock); - family->getCoverage(); - EXPECT_EQ(testCase.hasVSTable, family->hasVSTable()); } } diff --git a/engine/src/flutter/tests/util/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp index 0c7b2ba032c..e29a2fe5344 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.cpp +++ b/engine/src/flutter/tests/util/FontTestUtils.cpp @@ -48,16 +48,7 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { } } - xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); - FontFamily* family; - if (lang == nullptr) { - family = new FontFamily(variant); - } else { - uint32_t langId = FontStyle::registerLanguageList( - std::string((const char*)lang, xmlStrlen(lang))); - family = new FontFamily(langId, variant); - } - + std::vector fonts; for (xmlNode* fontNode = familyNode->children; fontNode; fontNode = fontNode->next) { if (xmlStrcmp(fontNode->name, (const xmlChar*)"font") != 0) { continue; @@ -80,13 +71,23 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { if (index == nullptr) { MinikinAutoUnref minikinFont(new MinikinFontForTest(fontPath)); - family->addFont(minikinFont.get(), FontStyle(weight, italic)); + fonts.push_back(Font(minikinFont.get(), FontStyle(weight, italic))); } else { MinikinAutoUnref minikinFont(new MinikinFontForTest(fontPath, atoi((const char*)index))); - family->addFont(minikinFont.get(), FontStyle(weight, italic)); + fonts.push_back(Font(minikinFont.get(), FontStyle(weight, italic))); } } + + xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); + FontFamily* family; + if (lang == nullptr) { + family = new FontFamily(variant, std::move(fonts)); + } else { + uint32_t langId = FontStyle::registerLanguageList( + std::string((const char*)lang, xmlStrlen(lang))); + family = new FontFamily(langId, variant, std::move(fonts)); + } families.push_back(family); } xmlFreeDoc(doc); From ed8318e4e860e7e542fa5143c399c3d1328bc25e Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 22 Nov 2016 18:10:57 +0900 Subject: [PATCH 221/364] Introduce createCollectionWithVariation. This lays the groundwork for variation settings support. Since we should regard different variations of a font as different fonts, we need to create new typefaces. To reuse the same instance of MinikinFont, as much as possible, FontFamily::createFamilyWithVariation now reuses an existence instance, while incrementing the reference count. Test: minikin_tests Bug: 33062398 Change-Id: I08e9b74192f8af1d045f1276498fa4e60d73863e --- .../flutter/include/minikin/FontCollection.h | 8 ++ .../src/flutter/include/minikin/FontFamily.h | 17 +++- .../src/flutter/include/minikin/MinikinFont.h | 4 + .../src/flutter/libs/minikin/AnalyzeStyle.cpp | 43 ----------- engine/src/flutter/libs/minikin/Android.mk | 2 +- .../flutter/libs/minikin/FontCollection.cpp | 39 ++++++++++ .../src/flutter/libs/minikin/FontFamily.cpp | 67 ++++++++++++++-- engine/src/flutter/libs/minikin/FontUtils.cpp | 77 +++++++++++++++++++ .../minikin/FontUtils.h} | 9 ++- engine/src/flutter/tests/unittest/Android.mk | 1 + .../tests/unittest/FontCollectionTest.cpp | 72 +++++++++++++++++ .../flutter/tests/unittest/FontFamilyTest.cpp | 63 +++++++++++++++ .../flutter/tests/util/MinikinFontForTest.cpp | 9 ++- .../flutter/tests/util/MinikinFontForTest.h | 9 ++- 14 files changed, 365 insertions(+), 55 deletions(-) delete mode 100644 engine/src/flutter/libs/minikin/AnalyzeStyle.cpp create mode 100644 engine/src/flutter/libs/minikin/FontUtils.cpp rename engine/src/flutter/{include/minikin/AnalyzeStyle.h => libs/minikin/FontUtils.h} (75%) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index f6312dcea59..eaebcbcf935 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -18,6 +18,7 @@ #define MINIKIN_FONT_COLLECTION_H #include +#include #include #include @@ -51,6 +52,10 @@ public: // Get base font with fakery information (fake bold could affect metrics) FakedFont baseFontFaked(FontStyle style); + // Creates new FontCollection based on this collection while applying font variations. Returns + // nullptr if none of variations apply to this collection. + FontCollection* createCollectionWithVariation(const std::vector& variations); + uint32_t getId() const; private: @@ -96,6 +101,9 @@ private: // These are offsets into mFamilyVec, one range per page std::vector mRanges; + + // Set of supported axes in this collection. + std::unordered_set mSupportedAxes; }; } // namespace minikin diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index bdf00e9f7c4..b848a046308 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -98,6 +99,8 @@ struct FakedFont { FontFakery fakery; }; +typedef uint32_t AxisTag; + struct Font { Font(MinikinFont* typeface, FontStyle style); Font(Font&& o); @@ -106,6 +109,13 @@ struct Font { MinikinFont* typeface; FontStyle style; + std::unordered_set supportedAxes; +}; + +struct FontVariation { + FontVariation(AxisTag axisTag, float value) : axisTag(axisTag), value(value) {} + AxisTag axisTag; + float value; }; class FontFamily : public MinikinRefCounted { @@ -129,6 +139,7 @@ public: MinikinFont* getFont(size_t index) const { return mFonts[index].typeface; } FontStyle getStyle(size_t index) const { return mFonts[index].style; } bool isColorEmojiFamily() const; + const std::unordered_set& supportedAxes() const { return mSupportedAxes; } // Get Unicode coverage. const SparseBitSet& getCoverage() const { return mCoverage; } @@ -140,12 +151,16 @@ public: // Returns true if this font family has a variaion sequence table (cmap format 14 subtable). bool hasVSTable() const { return mHasVSTable; } + // Creates new FontFamily based on this family while applying font variations. Returns nullptr + // if none of variations apply to this family. + FontFamily* createFamilyWithVariation(const std::vector& variations) const; + private: void computeCoverage(); - uint32_t mLangId; int mVariant; std::vector mFonts; + std::unordered_set mSupportedAxes; SparseBitSet mCoverage; bool mHasVSTable; diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 353edd6566e..57b939788ac 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -126,6 +126,10 @@ public: return 0; } + virtual MinikinFont* createFontWithVariation(const std::vector&) const { + return nullptr; + } + static uint32_t MakeTag(char c1, char c2, char c3, char c4) { return ((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) | ((uint32_t)c3 << 8) | (uint32_t)c4; diff --git a/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp b/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp deleted file mode 100644 index 333f008f7fd..00000000000 --- a/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2013 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 -#include - -#include - -namespace minikin { - -// should we have a single FontAnalyzer class this stuff lives in, to avoid dup? -static int32_t readU16(const uint8_t* data, size_t offset) { - return data[offset] << 8 | data[offset + 1]; -} - -bool analyzeStyle(const uint8_t* os2_data, size_t os2_size, int* weight, bool* italic) { - const size_t kUsWeightClassOffset = 4; - const size_t kFsSelectionOffset = 62; - const uint16_t kItalicFlag = (1 << 0); - if (os2_size < kFsSelectionOffset + 2) { - return false; - } - uint16_t weightClass = readU16(os2_data, kUsWeightClassOffset); - *weight = weightClass / 100; - uint16_t fsSelection = readU16(os2_data, kFsSelectionOffset); - *italic = (fsSelection & kItalicFlag) != 0; - return true; -} - -} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index d6c3df7f621..44abb885325 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -30,12 +30,12 @@ $(UNICODE_EMOJI_H): include $(CLEAR_VARS) minikin_src_files := \ - AnalyzeStyle.cpp \ CmapCoverage.cpp \ FontCollection.cpp \ FontFamily.cpp \ FontLanguage.cpp \ FontLanguageListCache.cpp \ + FontUtils.cpp \ GraphemeBreak.cpp \ HbFontCache.cpp \ Hyphenator.cpp \ diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 9e9223fd2eb..ac6f8f336dd 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -103,6 +103,9 @@ FontCollection::FontCollection(const vector& typefaces) : } mMaxChar = max(mMaxChar, coverage.length()); lastChar.push_back(coverage.nextSetBit(0)); + + const std::unordered_set& supportedAxes = family->supportedAxes(); + mSupportedAxes.insert(supportedAxes.begin(), supportedAxes.end()); } nTypefaces = mFamilies.size(); LOG_ALWAYS_FATAL_IF(nTypefaces == 0, @@ -462,6 +465,42 @@ FakedFont FontCollection::baseFontFaked(FontStyle style) { return mFamilies[0]->getClosestMatch(style); } +FontCollection* FontCollection::createCollectionWithVariation( + const std::vector& variations) { + if (variations.empty() || mSupportedAxes.empty()) { + return nullptr; + } + + bool hasSupportedAxis = false; + for (const FontVariation& variation : variations) { + if (mSupportedAxes.find(variation.axisTag) != mSupportedAxes.end()) { + hasSupportedAxis = true; + break; + } + } + if (!hasSupportedAxis) { + // None of variation axes are supported by this font collection. + return nullptr; + } + + std::vector families; + for (FontFamily* family : mFamilies) { + FontFamily* newFamily = family->createFamilyWithVariation(variations); + if (newFamily) { + families.push_back(newFamily); + } else { + family->Ref(); + families.push_back(family); + } + } + + FontCollection* result = new FontCollection(families); + for (FontFamily* family : families) { + family->Unref(); + } + return result; +} + uint32_t FontCollection::getId() const { return mId; } diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 164cc7d8ad8..5a277f78107 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -28,10 +28,11 @@ #include "FontLanguage.h" #include "FontLanguageListCache.h" +#include "FontUtils.h" #include "HbFontCache.h" #include "MinikinInternal.h" -#include #include +#include #include #include @@ -66,19 +67,30 @@ uint32_t FontStyle::pack(int variant, int weight, bool italic) { Font::Font(MinikinFont* typeface, FontStyle style) : typeface(typeface), style(style) { - typeface->Ref(); + android::AutoMutex _l(gMinikinLock); + typeface->RefLocked(); + + const uint32_t fvarTag = MinikinFont::MakeTag('f', 'v', 'a', 'r'); + HbBlob fvarTable(getFontTable(typeface, fvarTag)); + if (fvarTable.size() == 0) { + return; + } + + analyzeAxes(fvarTable.get(), fvarTable.size(), &supportedAxes); } Font::Font(Font&& o) { typeface = o.typeface; style = o.style; o.typeface = nullptr; + supportedAxes = std::move(o.supportedAxes); } Font::Font(const Font& o) { typeface = o.typeface; typeface->Ref(); style = o.style; + supportedAxes = o.supportedAxes; } Font::~Font() { @@ -174,9 +186,10 @@ void FontFamily::computeCoverage() { } // TODO: Error check? CmapCoverage::getCoverage(mCoverage, cmapTable.get(), cmapTable.size(), &mHasVSTable); -#ifdef VERBOSE_DEBUG - ALOGD("font coverage length=%d, first ch=%x\n", mCoverage.length(), mCoverage.nextSetBit(0)); -#endif + + for (size_t i = 0; i < mFonts.size(); ++i) { + mSupportedAxes.insert(mFonts[i].supportedAxes.begin(), mFonts[i].supportedAxes.end()); + } } bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) const { @@ -196,4 +209,48 @@ bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) const return result; } +FontFamily* FontFamily::createFamilyWithVariation( + const std::vector& variations) const { + if (variations.empty() || mSupportedAxes.empty()) { + return nullptr; + } + + bool hasSupportedAxis = false; + for (const FontVariation& variation : variations) { + if (mSupportedAxes.find(variation.axisTag) != mSupportedAxes.end()) { + hasSupportedAxis = true; + break; + } + } + if (!hasSupportedAxis) { + // None of variation axes are suppored by this family. + return nullptr; + } + + std::vector fonts; + for (const Font& font : mFonts) { + bool supportedVariations = false; + if (!font.supportedAxes.empty()) { + for (const FontVariation& variation : variations) { + if (font.supportedAxes.find(variation.axisTag) != font.supportedAxes.end()) { + supportedVariations = true; + break; + } + } + } + MinikinFont* minikinFont = nullptr; + if (supportedVariations) { + minikinFont = font.typeface->createFontWithVariation(variations); + } + if (minikinFont == nullptr) { + minikinFont = font.typeface; + minikinFont->Ref(); + } + fonts.push_back(Font(minikinFont, font.style)); + minikinFont->Unref(); + } + + return new FontFamily(mLangId, mVariant, std::move(fonts)); +} + } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/FontUtils.cpp b/engine/src/flutter/libs/minikin/FontUtils.cpp new file mode 100644 index 00000000000..56be16d696c --- /dev/null +++ b/engine/src/flutter/libs/minikin/FontUtils.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2016 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 +#include + +#include "FontUtils.h" + +namespace minikin { + +static uint16_t readU16(const uint8_t* data, size_t offset) { + return data[offset] << 8 | data[offset + 1]; +} + +static uint32_t readU32(const uint8_t* data, size_t offset) { + return ((uint32_t)data[offset]) << 24 | ((uint32_t)data[offset + 1]) << 16 | + ((uint32_t)data[offset + 2]) << 8 | ((uint32_t)data[offset + 3]); +} + +bool analyzeStyle(const uint8_t* os2_data, size_t os2_size, int* weight, bool* italic) { + const size_t kUsWeightClassOffset = 4; + const size_t kFsSelectionOffset = 62; + const uint16_t kItalicFlag = (1 << 0); + if (os2_size < kFsSelectionOffset + 2) { + return false; + } + uint16_t weightClass = readU16(os2_data, kUsWeightClassOffset); + *weight = weightClass / 100; + uint16_t fsSelection = readU16(os2_data, kFsSelectionOffset); + *italic = (fsSelection & kItalicFlag) != 0; + return true; +} + +void analyzeAxes(const uint8_t* fvar_data, size_t fvar_size, std::unordered_set* axes) { + const size_t kMajorVersionOffset = 0; + const size_t kMinorVersionOffset = 2; + const size_t kOffsetToAxesArrayOffset = 4; + const size_t kAxisCountOffset = 8; + const size_t kAxisSizeOffset = 10; + + axes->clear(); + + if (fvar_size < kAxisSizeOffset + 2) { + return; + } + const uint16_t majorVersion = readU16(fvar_data, kMajorVersionOffset); + const uint16_t minorVersion = readU16(fvar_data, kMinorVersionOffset); + const uint32_t axisOffset = readU16(fvar_data, kOffsetToAxesArrayOffset); + const uint32_t axisCount = readU16(fvar_data, kAxisCountOffset); + const uint32_t axisSize = readU16(fvar_data, kAxisSizeOffset); + + if (majorVersion != 1 || minorVersion != 0 || axisOffset != 0x10 || axisSize != 0x14) { + return; // Unsupported version. + } + if (fvar_size < axisOffset + axisOffset * axisCount) { + return; // Invalid table size. + } + for (uint32_t i = 0; i < axisCount; ++i) { + size_t axisRecordOffset = axisOffset + i * axisSize; + uint32_t tag = readU32(fvar_data, axisRecordOffset); + axes->insert(tag); + } +} +} // namespace minikin diff --git a/engine/src/flutter/include/minikin/AnalyzeStyle.h b/engine/src/flutter/libs/minikin/FontUtils.h similarity index 75% rename from engine/src/flutter/include/minikin/AnalyzeStyle.h rename to engine/src/flutter/libs/minikin/FontUtils.h index b4cd915108c..fa2051b409b 100644 --- a/engine/src/flutter/include/minikin/AnalyzeStyle.h +++ b/engine/src/flutter/libs/minikin/FontUtils.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Android Open Source Project + * Copyright (C) 2016 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. @@ -14,12 +14,15 @@ * limitations under the License. */ -#ifndef MINIKIN_ANALYZE_STYLE_H -#define MINIKIN_ANALYZE_STYLE_H +#ifndef MINIKIN_FONT_UTILS_H +#define MINIKIN_FONT_UTILS_H + +#include namespace minikin { bool analyzeStyle(const uint8_t* os2_data, size_t os2_size, int* weight, bool* italic); +void analyzeAxes(const uint8_t* fvar_data, size_t fvar_size, std::unordered_set* axes); } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index cced5457373..7b3f60f8f9e 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -27,6 +27,7 @@ LOCAL_TEST_DATA := \ data/Italic.ttf \ data/Ja.ttf \ data/Ko.ttf \ + data/MultiAxis.ttf \ data/NoCmapFormat14.ttf \ data/NoGlyphFont.ttf \ data/Regular.ttf \ diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index c0b6b526b78..02e861c903e 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -121,4 +121,76 @@ TEST(FontCollectionTest, newEmojiTest) { EXPECT_FALSE(collection->hasVariationSelector(0x2642, 0xFE0F)); } +TEST(FontCollectionTest, createWithVariations) { + // This font has 'wdth' and 'wght' axes. + const char kMultiAxisFont[] = kTestFontDir "/MultiAxis.ttf"; + const char kNoAxisFont[] = kTestFontDir "/Regular.ttf"; + + MinikinAutoUnref multiAxisFont(new MinikinFontForTest(kMultiAxisFont)); + MinikinAutoUnref multiAxisFamily(new FontFamily( + std::vector({ Font(multiAxisFont.get(), FontStyle()) }))); + std::vector multiAxisFamilies({multiAxisFamily.get()}); + MinikinAutoUnref multiAxisFc(new FontCollection(multiAxisFamilies)); + + MinikinAutoUnref noAxisFont(new MinikinFontForTest(kNoAxisFont)); + MinikinAutoUnref noAxisFamily(new FontFamily( + std::vector({ Font(noAxisFont.get(), FontStyle()) }))); + std::vector noAxisFamilies({noAxisFamily.get()}); + MinikinAutoUnref noAxisFc(new FontCollection(noAxisFamilies)); + + { + // Do not ceate new instance if none of variations are specified. + EXPECT_EQ(nullptr, + multiAxisFc->createCollectionWithVariation(std::vector())); + EXPECT_EQ(nullptr, + noAxisFc->createCollectionWithVariation(std::vector())); + } + { + // New instance should be used for supported variation. + std::vector variations = { + { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f } + }; + MinikinAutoUnref newFc( + multiAxisFc->createCollectionWithVariation(variations)); + EXPECT_NE(nullptr, newFc.get()); + EXPECT_NE(multiAxisFc.get(), newFc.get()); + + EXPECT_EQ(nullptr, noAxisFc->createCollectionWithVariation(variations)); + } + { + // New instance should be used for supported variation (multiple variations case). + std::vector variations = { + { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, + { MinikinFont::MakeTag('w', 'g', 'h', 't'), 1.0f } + }; + MinikinAutoUnref newFc( + multiAxisFc->createCollectionWithVariation(variations)); + EXPECT_NE(nullptr, newFc.get()); + EXPECT_NE(multiAxisFc.get(), newFc.get()); + + EXPECT_EQ(nullptr, noAxisFc->createCollectionWithVariation(variations)); + } + { + // Do not ceate new instance if none of variations are supported. + std::vector variations = { + { MinikinFont::MakeTag('Z', 'Z', 'Z', 'Z'), 1.0f } + }; + EXPECT_EQ(nullptr, multiAxisFc->createCollectionWithVariation(variations)); + EXPECT_EQ(nullptr, noAxisFc->createCollectionWithVariation(variations)); + } + { + // At least one axis is supported, should create new instance. + std::vector variations = { + { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, + { MinikinFont::MakeTag('Z', 'Z', 'Z', 'Z'), 1.0f } + }; + MinikinAutoUnref newFc( + multiAxisFc->createCollectionWithVariation(variations)); + EXPECT_NE(nullptr, newFc.get()); + EXPECT_NE(multiAxisFc.get(), newFc.get()); + + EXPECT_EQ(nullptr, noAxisFc->createCollectionWithVariation(variations)); + } +} + } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index ddc36e45704..35f387304b6 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -527,4 +527,67 @@ TEST_F(FontFamilyTest, hasVSTableTest) { } } +TEST_F(FontFamilyTest, createFamilyWithVariationTest) { + // This font has 'wdth' and 'wght' axes. + const char kMultiAxisFont[] = kTestFontDir "/MultiAxis.ttf"; + const char kNoAxisFont[] = kTestFontDir "/Regular.ttf"; + + MinikinAutoUnref multiAxisFont(new MinikinFontForTest(kMultiAxisFont)); + MinikinAutoUnref multiAxisFamily(new FontFamily( + std::vector({Font(multiAxisFont.get(), FontStyle())}))); + + MinikinAutoUnref noAxisFont(new MinikinFontForTest(kNoAxisFont)); + MinikinAutoUnref noAxisFamily(new FontFamily( + std::vector({Font(noAxisFont.get(), FontStyle())}))); + + { + // Do not ceate new instance if none of variations are specified. + EXPECT_EQ(nullptr, + multiAxisFamily->createFamilyWithVariation(std::vector())); + EXPECT_EQ(nullptr, + noAxisFamily->createFamilyWithVariation(std::vector())); + } + { + // New instance should be used for supported variation. + std::vector variations = {{MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f}}; + MinikinAutoUnref newFamily( + multiAxisFamily->createFamilyWithVariation(variations)); + EXPECT_NE(nullptr, newFamily.get()); + EXPECT_NE(multiAxisFamily.get(), newFamily.get()); + EXPECT_EQ(nullptr, noAxisFamily->createFamilyWithVariation(variations)); + } + { + // New instance should be used for supported variation. (multiple variations case) + std::vector variations = { + { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, + { MinikinFont::MakeTag('w', 'g', 'h', 't'), 1.0f } + }; + MinikinAutoUnref newFamily( + multiAxisFamily->createFamilyWithVariation(variations)); + EXPECT_NE(nullptr, newFamily.get()); + EXPECT_NE(multiAxisFamily.get(), newFamily.get()); + EXPECT_EQ(nullptr, noAxisFamily->createFamilyWithVariation(variations)); + } + { + // Do not ceate new instance if none of variations are supported. + std::vector variations = { + { MinikinFont::MakeTag('Z', 'Z', 'Z', 'Z'), 1.0f } + }; + EXPECT_EQ(nullptr, multiAxisFamily->createFamilyWithVariation(variations)); + EXPECT_EQ(nullptr, noAxisFamily->createFamilyWithVariation(variations)); + } + { + // At least one axis is supported, should create new instance. + std::vector variations = { + { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, + { MinikinFont::MakeTag('Z', 'Z', 'Z', 'Z'), 1.0f } + }; + MinikinAutoUnref newFamily( + multiAxisFamily->createFamilyWithVariation(variations)); + EXPECT_NE(nullptr, newFamily.get()); + EXPECT_NE(multiAxisFamily.get(), newFamily.get()); + EXPECT_EQ(nullptr, noAxisFamily->createFamilyWithVariation(variations)); + } +} + } // namespace minikin diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.cpp b/engine/src/flutter/tests/util/MinikinFontForTest.cpp index a4132e5178d..f191f07d6e9 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/util/MinikinFontForTest.cpp @@ -34,9 +34,11 @@ namespace minikin { static int uniqueId = 0; // TODO: make thread safe if necessary. -MinikinFontForTest::MinikinFontForTest(const std::string& font_path, int index) : +MinikinFontForTest::MinikinFontForTest(const std::string& font_path, int index, + const std::vector& variations) : MinikinFont(uniqueId++), mFontPath(font_path), + mVariations(variations), mFontIndex(index) { int fd = open(font_path.c_str(), O_RDONLY); LOG_ALWAYS_FATAL_IF(fd == -1); @@ -67,4 +69,9 @@ void MinikinFontForTest::GetBounds(MinikinRect* bounds, uint32_t /* glyph_id */, bounds->mBottom = 10.0f; } +MinikinFont* MinikinFontForTest::createFontWithVariation( + const std::vector& variations) const { + return new MinikinFontForTest(mFontPath, mFontIndex, variations); +} + } // namespace minikin diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.h b/engine/src/flutter/tests/util/MinikinFontForTest.h index ee0eadbe0c2..2a107036eda 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.h +++ b/engine/src/flutter/tests/util/MinikinFontForTest.h @@ -25,7 +25,10 @@ namespace minikin { class MinikinFontForTest : public MinikinFont { public: - MinikinFontForTest(const std::string& font_path, int index); + MinikinFontForTest(const std::string& font_path, int index, + const std::vector& variations); + MinikinFontForTest(const std::string& font_path, int index) + : MinikinFontForTest(font_path, index, std::vector()) {} MinikinFontForTest(const std::string& font_path) : MinikinFontForTest(font_path, 0) {} virtual ~MinikinFontForTest(); @@ -35,15 +38,19 @@ public: const MinikinPaint& paint) const; const std::string& fontPath() const { return mFontPath; } + const std::vector& variations() const { return mVariations; } + const void* GetFontData() const { return mFontData; } size_t GetFontSize() const { return mFontSize; } int GetFontIndex() const { return mFontIndex; } + MinikinFont* createFontWithVariation(const std::vector& variations) const; private: MinikinFontForTest() = delete; MinikinFontForTest(const MinikinFontForTest&) = delete; MinikinFontForTest& operator=(MinikinFontForTest&) = delete; const std::string mFontPath; + const std::vector mVariations; const int mFontIndex; void* mFontData; size_t mFontSize; From 7235e8c11d78d8ade2cb92a3ce6bf631154d7fe6 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 12 Jan 2017 18:33:44 +0900 Subject: [PATCH 222/364] Fix inverse condition of forColorEmoji. We should override the advance function only when the glyph is came from color bitmap. This was introduced by Ia88cb670ca9e0bb352bccef22c5ea3a789bcc1da. Bug: 21705974 Test: ran minikin_tests Change-Id: I3489d75ace8bffdd9035a5986a2641313feef04d --- engine/src/flutter/libs/minikin/Layout.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 2e7ef77e235..98e9fdb07ba 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -304,15 +304,15 @@ hb_font_funcs_t* getHbFontFuncs(bool forColorBitmapFont) { if (*funcs == nullptr) { *funcs = hb_font_funcs_create(); if (forColorBitmapFont) { - // Override the h_advance function since we can't use HarfBuzz's implemenation. It may - // return the wrong value if the font uses hinting aggressively. - hb_font_funcs_set_glyph_h_advance_func(*funcs, harfbuzzGetGlyphHorizontalAdvance, 0, 0); - } else { // Don't override the h_advance function since we use HarfBuzz's implementation for // emoji for performance reasons. // Note that it is technically possible for a TrueType font to have outline and embedded // bitmap at the same time. We ignore modified advances of hinted outline glyphs in that // case. + } else { + // Override the h_advance function since we can't use HarfBuzz's implemenation. It may + // return the wrong value if the font uses hinting aggressively. + hb_font_funcs_set_glyph_h_advance_func(*funcs, harfbuzzGetGlyphHorizontalAdvance, 0, 0); } hb_font_funcs_set_glyph_h_origin_func(*funcs, harfbuzzGetGlyphHorizontalOrigin, 0, 0); hb_font_funcs_make_immutable(*funcs); From defcd9d9c227776396e00daf0b33503ae54d96d7 Mon Sep 17 00:00:00 2001 From: Siyamed Sinir Date: Thu, 12 Jan 2017 19:18:48 +0000 Subject: [PATCH 223/364] Revert "Reduce memory usage of FontCollection." This reverts commit 41ef8b376f4616ba13e13096f7c03a4caa0c695a. Test: Manually tested Bug: 34247671 Change-Id: I0510009b2deac784770f26059681b1980800abc8 --- engine/src/flutter/include/minikin/FontCollection.h | 10 +++++----- engine/src/flutter/libs/minikin/FontCollection.cpp | 13 ++++++------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index f6312dcea59..c9c8520be6b 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -58,8 +58,8 @@ private: static const int kPageMask = (1 << kLogCharsPerPage) - 1; struct Range { - uint8_t start; - uint8_t end; + size_t start; + size_t end; }; FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const; @@ -87,14 +87,14 @@ private: // This vector can't be empty. std::vector mFamilies; - // This vector contains indices into mFamilies. + // This vector contains pointers into mInstances // This vector can't be empty. - std::vector mFamilyVec; + std::vector mFamilyVec; // This vector has pointers to the font family instance which has cmap 14 subtable. std::vector mVSFamilyVec; - // These are offsets into mFamilyVec, one range per page + // These are offsets into mInstanceVec, one range per page std::vector mRanges; }; diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 7ad2f48565a..365d7752b00 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -111,8 +111,6 @@ FontCollection::FontCollection(const vector& typefaces) : nTypefaces = mFamilies.size(); LOG_ALWAYS_FATAL_IF(nTypefaces == 0, "Font collection must have at least one valid typeface"); - LOG_ALWAYS_FATAL_IF(nTypefaces > 254, - "Up to 254 font families can be registered to collection."); size_t nPages = (mMaxChar + kPageMask) >> kLogCharsPerPage; size_t offset = 0; // TODO: Use variation selector map for mRanges construction. @@ -126,11 +124,11 @@ FontCollection::FontCollection(const vector& typefaces) : #ifdef VERBOSE_DEBUG ALOGD("i=%zd: range start = %zd\n", i, offset); #endif - range->start = (uint8_t)offset; + range->start = offset; for (size_t j = 0; j < nTypefaces; j++) { if (lastChar[j] < (i + 1) << kLogCharsPerPage) { FontFamily* family = mFamilies[j]; - mFamilyVec.push_back((uint8_t)j); + mFamilyVec.push_back(family); offset++; uint32_t nextChar = family->getCoverage()->nextSetBit((i + 1) << kLogCharsPerPage); #ifdef VERBOSE_DEBUG @@ -139,7 +137,7 @@ FontCollection::FontCollection(const vector& typefaces) : lastChar[j] = nextChar; } } - range->end = (uint8_t)offset; + range->end = offset; } } @@ -286,10 +284,11 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, return mFamilies[0]; } + const std::vector& familyVec = (vs == 0) ? mFamilyVec : mFamilies; Range range = mRanges[ch >> kLogCharsPerPage]; if (vs != 0) { - range = { 0, (uint8_t)mFamilies.size() }; + range = { 0, mFamilies.size() }; } #ifdef VERBOSE_DEBUG @@ -298,7 +297,7 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, FontFamily* bestFamily = nullptr; uint32_t bestScore = kUnsupportedFontScore; for (size_t i = range.start; i < range.end; i++) { - FontFamily* family = vs == 0 ? mFamilies[mFamilyVec[i]] : mFamilies[i]; + FontFamily* family = familyVec[i]; const uint32_t score = calcFamilyScore(ch, vs, variant, langListId, family); if (score == kFirstFontScore) { // If the first font family supports the given character or variation sequence, always From df0cbf3bc0c9bb40ca0e15b3755530a14b9c842a Mon Sep 17 00:00:00 2001 From: Siyamed Sinir Date: Fri, 20 Jan 2017 01:11:20 +0000 Subject: [PATCH 224/364] Revert "Introduce createCollectionWithVariation." This reverts commit ed8318e4e860e7e542fa5143c399c3d1328bc25e. Bug: 34378805 Change-Id: I22b683f774813724f220b1b8584ab188f3cf4fa7 --- .../minikin/AnalyzeStyle.h} | 9 +-- .../flutter/include/minikin/FontCollection.h | 8 -- .../src/flutter/include/minikin/FontFamily.h | 17 +--- .../src/flutter/include/minikin/MinikinFont.h | 4 - .../src/flutter/libs/minikin/AnalyzeStyle.cpp | 43 +++++++++++ engine/src/flutter/libs/minikin/Android.mk | 2 +- .../flutter/libs/minikin/FontCollection.cpp | 39 ---------- .../src/flutter/libs/minikin/FontFamily.cpp | 67 ++-------------- engine/src/flutter/libs/minikin/FontUtils.cpp | 77 ------------------- engine/src/flutter/tests/unittest/Android.mk | 1 - .../tests/unittest/FontCollectionTest.cpp | 72 ----------------- .../flutter/tests/unittest/FontFamilyTest.cpp | 63 --------------- .../flutter/tests/util/MinikinFontForTest.cpp | 9 +-- .../flutter/tests/util/MinikinFontForTest.h | 9 +-- 14 files changed, 55 insertions(+), 365 deletions(-) rename engine/src/flutter/{libs/minikin/FontUtils.h => include/minikin/AnalyzeStyle.h} (75%) create mode 100644 engine/src/flutter/libs/minikin/AnalyzeStyle.cpp delete mode 100644 engine/src/flutter/libs/minikin/FontUtils.cpp diff --git a/engine/src/flutter/libs/minikin/FontUtils.h b/engine/src/flutter/include/minikin/AnalyzeStyle.h similarity index 75% rename from engine/src/flutter/libs/minikin/FontUtils.h rename to engine/src/flutter/include/minikin/AnalyzeStyle.h index fa2051b409b..b4cd915108c 100644 --- a/engine/src/flutter/libs/minikin/FontUtils.h +++ b/engine/src/flutter/include/minikin/AnalyzeStyle.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 The Android Open Source Project + * Copyright (C) 2013 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. @@ -14,15 +14,12 @@ * limitations under the License. */ -#ifndef MINIKIN_FONT_UTILS_H -#define MINIKIN_FONT_UTILS_H - -#include +#ifndef MINIKIN_ANALYZE_STYLE_H +#define MINIKIN_ANALYZE_STYLE_H namespace minikin { bool analyzeStyle(const uint8_t* os2_data, size_t os2_size, int* weight, bool* italic); -void analyzeAxes(const uint8_t* fvar_data, size_t fvar_size, std::unordered_set* axes); } // namespace minikin diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index eaebcbcf935..f6312dcea59 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -18,7 +18,6 @@ #define MINIKIN_FONT_COLLECTION_H #include -#include #include #include @@ -52,10 +51,6 @@ public: // Get base font with fakery information (fake bold could affect metrics) FakedFont baseFontFaked(FontStyle style); - // Creates new FontCollection based on this collection while applying font variations. Returns - // nullptr if none of variations apply to this collection. - FontCollection* createCollectionWithVariation(const std::vector& variations); - uint32_t getId() const; private: @@ -101,9 +96,6 @@ private: // These are offsets into mFamilyVec, one range per page std::vector mRanges; - - // Set of supported axes in this collection. - std::unordered_set mSupportedAxes; }; } // namespace minikin diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index b848a046308..bdf00e9f7c4 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -19,7 +19,6 @@ #include #include -#include #include #include @@ -99,8 +98,6 @@ struct FakedFont { FontFakery fakery; }; -typedef uint32_t AxisTag; - struct Font { Font(MinikinFont* typeface, FontStyle style); Font(Font&& o); @@ -109,13 +106,6 @@ struct Font { MinikinFont* typeface; FontStyle style; - std::unordered_set supportedAxes; -}; - -struct FontVariation { - FontVariation(AxisTag axisTag, float value) : axisTag(axisTag), value(value) {} - AxisTag axisTag; - float value; }; class FontFamily : public MinikinRefCounted { @@ -139,7 +129,6 @@ public: MinikinFont* getFont(size_t index) const { return mFonts[index].typeface; } FontStyle getStyle(size_t index) const { return mFonts[index].style; } bool isColorEmojiFamily() const; - const std::unordered_set& supportedAxes() const { return mSupportedAxes; } // Get Unicode coverage. const SparseBitSet& getCoverage() const { return mCoverage; } @@ -151,16 +140,12 @@ public: // Returns true if this font family has a variaion sequence table (cmap format 14 subtable). bool hasVSTable() const { return mHasVSTable; } - // Creates new FontFamily based on this family while applying font variations. Returns nullptr - // if none of variations apply to this family. - FontFamily* createFamilyWithVariation(const std::vector& variations) const; - private: void computeCoverage(); + uint32_t mLangId; int mVariant; std::vector mFonts; - std::unordered_set mSupportedAxes; SparseBitSet mCoverage; bool mHasVSTable; diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 57b939788ac..353edd6566e 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -126,10 +126,6 @@ public: return 0; } - virtual MinikinFont* createFontWithVariation(const std::vector&) const { - return nullptr; - } - static uint32_t MakeTag(char c1, char c2, char c3, char c4) { return ((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) | ((uint32_t)c3 << 8) | (uint32_t)c4; diff --git a/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp b/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp new file mode 100644 index 00000000000..333f008f7fd --- /dev/null +++ b/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2013 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 +#include + +#include + +namespace minikin { + +// should we have a single FontAnalyzer class this stuff lives in, to avoid dup? +static int32_t readU16(const uint8_t* data, size_t offset) { + return data[offset] << 8 | data[offset + 1]; +} + +bool analyzeStyle(const uint8_t* os2_data, size_t os2_size, int* weight, bool* italic) { + const size_t kUsWeightClassOffset = 4; + const size_t kFsSelectionOffset = 62; + const uint16_t kItalicFlag = (1 << 0); + if (os2_size < kFsSelectionOffset + 2) { + return false; + } + uint16_t weightClass = readU16(os2_data, kUsWeightClassOffset); + *weight = weightClass / 100; + uint16_t fsSelection = readU16(os2_data, kFsSelectionOffset); + *italic = (fsSelection & kItalicFlag) != 0; + return true; +} + +} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 44abb885325..d6c3df7f621 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -30,12 +30,12 @@ $(UNICODE_EMOJI_H): include $(CLEAR_VARS) minikin_src_files := \ + AnalyzeStyle.cpp \ CmapCoverage.cpp \ FontCollection.cpp \ FontFamily.cpp \ FontLanguage.cpp \ FontLanguageListCache.cpp \ - FontUtils.cpp \ GraphemeBreak.cpp \ HbFontCache.cpp \ Hyphenator.cpp \ diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index ac6f8f336dd..9e9223fd2eb 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -103,9 +103,6 @@ FontCollection::FontCollection(const vector& typefaces) : } mMaxChar = max(mMaxChar, coverage.length()); lastChar.push_back(coverage.nextSetBit(0)); - - const std::unordered_set& supportedAxes = family->supportedAxes(); - mSupportedAxes.insert(supportedAxes.begin(), supportedAxes.end()); } nTypefaces = mFamilies.size(); LOG_ALWAYS_FATAL_IF(nTypefaces == 0, @@ -465,42 +462,6 @@ FakedFont FontCollection::baseFontFaked(FontStyle style) { return mFamilies[0]->getClosestMatch(style); } -FontCollection* FontCollection::createCollectionWithVariation( - const std::vector& variations) { - if (variations.empty() || mSupportedAxes.empty()) { - return nullptr; - } - - bool hasSupportedAxis = false; - for (const FontVariation& variation : variations) { - if (mSupportedAxes.find(variation.axisTag) != mSupportedAxes.end()) { - hasSupportedAxis = true; - break; - } - } - if (!hasSupportedAxis) { - // None of variation axes are supported by this font collection. - return nullptr; - } - - std::vector families; - for (FontFamily* family : mFamilies) { - FontFamily* newFamily = family->createFamilyWithVariation(variations); - if (newFamily) { - families.push_back(newFamily); - } else { - family->Ref(); - families.push_back(family); - } - } - - FontCollection* result = new FontCollection(families); - for (FontFamily* family : families) { - family->Unref(); - } - return result; -} - uint32_t FontCollection::getId() const { return mId; } diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 5a277f78107..164cc7d8ad8 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -28,11 +28,10 @@ #include "FontLanguage.h" #include "FontLanguageListCache.h" -#include "FontUtils.h" #include "HbFontCache.h" #include "MinikinInternal.h" +#include #include -#include #include #include @@ -67,30 +66,19 @@ uint32_t FontStyle::pack(int variant, int weight, bool italic) { Font::Font(MinikinFont* typeface, FontStyle style) : typeface(typeface), style(style) { - android::AutoMutex _l(gMinikinLock); - typeface->RefLocked(); - - const uint32_t fvarTag = MinikinFont::MakeTag('f', 'v', 'a', 'r'); - HbBlob fvarTable(getFontTable(typeface, fvarTag)); - if (fvarTable.size() == 0) { - return; - } - - analyzeAxes(fvarTable.get(), fvarTable.size(), &supportedAxes); + typeface->Ref(); } Font::Font(Font&& o) { typeface = o.typeface; style = o.style; o.typeface = nullptr; - supportedAxes = std::move(o.supportedAxes); } Font::Font(const Font& o) { typeface = o.typeface; typeface->Ref(); style = o.style; - supportedAxes = o.supportedAxes; } Font::~Font() { @@ -186,10 +174,9 @@ void FontFamily::computeCoverage() { } // TODO: Error check? CmapCoverage::getCoverage(mCoverage, cmapTable.get(), cmapTable.size(), &mHasVSTable); - - for (size_t i = 0; i < mFonts.size(); ++i) { - mSupportedAxes.insert(mFonts[i].supportedAxes.begin(), mFonts[i].supportedAxes.end()); - } +#ifdef VERBOSE_DEBUG + ALOGD("font coverage length=%d, first ch=%x\n", mCoverage.length(), mCoverage.nextSetBit(0)); +#endif } bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) const { @@ -209,48 +196,4 @@ bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) const return result; } -FontFamily* FontFamily::createFamilyWithVariation( - const std::vector& variations) const { - if (variations.empty() || mSupportedAxes.empty()) { - return nullptr; - } - - bool hasSupportedAxis = false; - for (const FontVariation& variation : variations) { - if (mSupportedAxes.find(variation.axisTag) != mSupportedAxes.end()) { - hasSupportedAxis = true; - break; - } - } - if (!hasSupportedAxis) { - // None of variation axes are suppored by this family. - return nullptr; - } - - std::vector fonts; - for (const Font& font : mFonts) { - bool supportedVariations = false; - if (!font.supportedAxes.empty()) { - for (const FontVariation& variation : variations) { - if (font.supportedAxes.find(variation.axisTag) != font.supportedAxes.end()) { - supportedVariations = true; - break; - } - } - } - MinikinFont* minikinFont = nullptr; - if (supportedVariations) { - minikinFont = font.typeface->createFontWithVariation(variations); - } - if (minikinFont == nullptr) { - minikinFont = font.typeface; - minikinFont->Ref(); - } - fonts.push_back(Font(minikinFont, font.style)); - minikinFont->Unref(); - } - - return new FontFamily(mLangId, mVariant, std::move(fonts)); -} - } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/FontUtils.cpp b/engine/src/flutter/libs/minikin/FontUtils.cpp deleted file mode 100644 index 56be16d696c..00000000000 --- a/engine/src/flutter/libs/minikin/FontUtils.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2016 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 -#include - -#include "FontUtils.h" - -namespace minikin { - -static uint16_t readU16(const uint8_t* data, size_t offset) { - return data[offset] << 8 | data[offset + 1]; -} - -static uint32_t readU32(const uint8_t* data, size_t offset) { - return ((uint32_t)data[offset]) << 24 | ((uint32_t)data[offset + 1]) << 16 | - ((uint32_t)data[offset + 2]) << 8 | ((uint32_t)data[offset + 3]); -} - -bool analyzeStyle(const uint8_t* os2_data, size_t os2_size, int* weight, bool* italic) { - const size_t kUsWeightClassOffset = 4; - const size_t kFsSelectionOffset = 62; - const uint16_t kItalicFlag = (1 << 0); - if (os2_size < kFsSelectionOffset + 2) { - return false; - } - uint16_t weightClass = readU16(os2_data, kUsWeightClassOffset); - *weight = weightClass / 100; - uint16_t fsSelection = readU16(os2_data, kFsSelectionOffset); - *italic = (fsSelection & kItalicFlag) != 0; - return true; -} - -void analyzeAxes(const uint8_t* fvar_data, size_t fvar_size, std::unordered_set* axes) { - const size_t kMajorVersionOffset = 0; - const size_t kMinorVersionOffset = 2; - const size_t kOffsetToAxesArrayOffset = 4; - const size_t kAxisCountOffset = 8; - const size_t kAxisSizeOffset = 10; - - axes->clear(); - - if (fvar_size < kAxisSizeOffset + 2) { - return; - } - const uint16_t majorVersion = readU16(fvar_data, kMajorVersionOffset); - const uint16_t minorVersion = readU16(fvar_data, kMinorVersionOffset); - const uint32_t axisOffset = readU16(fvar_data, kOffsetToAxesArrayOffset); - const uint32_t axisCount = readU16(fvar_data, kAxisCountOffset); - const uint32_t axisSize = readU16(fvar_data, kAxisSizeOffset); - - if (majorVersion != 1 || minorVersion != 0 || axisOffset != 0x10 || axisSize != 0x14) { - return; // Unsupported version. - } - if (fvar_size < axisOffset + axisOffset * axisCount) { - return; // Invalid table size. - } - for (uint32_t i = 0; i < axisCount; ++i) { - size_t axisRecordOffset = axisOffset + i * axisSize; - uint32_t tag = readU32(fvar_data, axisRecordOffset); - axes->insert(tag); - } -} -} // namespace minikin diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index 7b3f60f8f9e..cced5457373 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -27,7 +27,6 @@ LOCAL_TEST_DATA := \ data/Italic.ttf \ data/Ja.ttf \ data/Ko.ttf \ - data/MultiAxis.ttf \ data/NoCmapFormat14.ttf \ data/NoGlyphFont.ttf \ data/Regular.ttf \ diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index 02e861c903e..c0b6b526b78 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -121,76 +121,4 @@ TEST(FontCollectionTest, newEmojiTest) { EXPECT_FALSE(collection->hasVariationSelector(0x2642, 0xFE0F)); } -TEST(FontCollectionTest, createWithVariations) { - // This font has 'wdth' and 'wght' axes. - const char kMultiAxisFont[] = kTestFontDir "/MultiAxis.ttf"; - const char kNoAxisFont[] = kTestFontDir "/Regular.ttf"; - - MinikinAutoUnref multiAxisFont(new MinikinFontForTest(kMultiAxisFont)); - MinikinAutoUnref multiAxisFamily(new FontFamily( - std::vector({ Font(multiAxisFont.get(), FontStyle()) }))); - std::vector multiAxisFamilies({multiAxisFamily.get()}); - MinikinAutoUnref multiAxisFc(new FontCollection(multiAxisFamilies)); - - MinikinAutoUnref noAxisFont(new MinikinFontForTest(kNoAxisFont)); - MinikinAutoUnref noAxisFamily(new FontFamily( - std::vector({ Font(noAxisFont.get(), FontStyle()) }))); - std::vector noAxisFamilies({noAxisFamily.get()}); - MinikinAutoUnref noAxisFc(new FontCollection(noAxisFamilies)); - - { - // Do not ceate new instance if none of variations are specified. - EXPECT_EQ(nullptr, - multiAxisFc->createCollectionWithVariation(std::vector())); - EXPECT_EQ(nullptr, - noAxisFc->createCollectionWithVariation(std::vector())); - } - { - // New instance should be used for supported variation. - std::vector variations = { - { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f } - }; - MinikinAutoUnref newFc( - multiAxisFc->createCollectionWithVariation(variations)); - EXPECT_NE(nullptr, newFc.get()); - EXPECT_NE(multiAxisFc.get(), newFc.get()); - - EXPECT_EQ(nullptr, noAxisFc->createCollectionWithVariation(variations)); - } - { - // New instance should be used for supported variation (multiple variations case). - std::vector variations = { - { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, - { MinikinFont::MakeTag('w', 'g', 'h', 't'), 1.0f } - }; - MinikinAutoUnref newFc( - multiAxisFc->createCollectionWithVariation(variations)); - EXPECT_NE(nullptr, newFc.get()); - EXPECT_NE(multiAxisFc.get(), newFc.get()); - - EXPECT_EQ(nullptr, noAxisFc->createCollectionWithVariation(variations)); - } - { - // Do not ceate new instance if none of variations are supported. - std::vector variations = { - { MinikinFont::MakeTag('Z', 'Z', 'Z', 'Z'), 1.0f } - }; - EXPECT_EQ(nullptr, multiAxisFc->createCollectionWithVariation(variations)); - EXPECT_EQ(nullptr, noAxisFc->createCollectionWithVariation(variations)); - } - { - // At least one axis is supported, should create new instance. - std::vector variations = { - { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, - { MinikinFont::MakeTag('Z', 'Z', 'Z', 'Z'), 1.0f } - }; - MinikinAutoUnref newFc( - multiAxisFc->createCollectionWithVariation(variations)); - EXPECT_NE(nullptr, newFc.get()); - EXPECT_NE(multiAxisFc.get(), newFc.get()); - - EXPECT_EQ(nullptr, noAxisFc->createCollectionWithVariation(variations)); - } -} - } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 35f387304b6..ddc36e45704 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -527,67 +527,4 @@ TEST_F(FontFamilyTest, hasVSTableTest) { } } -TEST_F(FontFamilyTest, createFamilyWithVariationTest) { - // This font has 'wdth' and 'wght' axes. - const char kMultiAxisFont[] = kTestFontDir "/MultiAxis.ttf"; - const char kNoAxisFont[] = kTestFontDir "/Regular.ttf"; - - MinikinAutoUnref multiAxisFont(new MinikinFontForTest(kMultiAxisFont)); - MinikinAutoUnref multiAxisFamily(new FontFamily( - std::vector({Font(multiAxisFont.get(), FontStyle())}))); - - MinikinAutoUnref noAxisFont(new MinikinFontForTest(kNoAxisFont)); - MinikinAutoUnref noAxisFamily(new FontFamily( - std::vector({Font(noAxisFont.get(), FontStyle())}))); - - { - // Do not ceate new instance if none of variations are specified. - EXPECT_EQ(nullptr, - multiAxisFamily->createFamilyWithVariation(std::vector())); - EXPECT_EQ(nullptr, - noAxisFamily->createFamilyWithVariation(std::vector())); - } - { - // New instance should be used for supported variation. - std::vector variations = {{MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f}}; - MinikinAutoUnref newFamily( - multiAxisFamily->createFamilyWithVariation(variations)); - EXPECT_NE(nullptr, newFamily.get()); - EXPECT_NE(multiAxisFamily.get(), newFamily.get()); - EXPECT_EQ(nullptr, noAxisFamily->createFamilyWithVariation(variations)); - } - { - // New instance should be used for supported variation. (multiple variations case) - std::vector variations = { - { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, - { MinikinFont::MakeTag('w', 'g', 'h', 't'), 1.0f } - }; - MinikinAutoUnref newFamily( - multiAxisFamily->createFamilyWithVariation(variations)); - EXPECT_NE(nullptr, newFamily.get()); - EXPECT_NE(multiAxisFamily.get(), newFamily.get()); - EXPECT_EQ(nullptr, noAxisFamily->createFamilyWithVariation(variations)); - } - { - // Do not ceate new instance if none of variations are supported. - std::vector variations = { - { MinikinFont::MakeTag('Z', 'Z', 'Z', 'Z'), 1.0f } - }; - EXPECT_EQ(nullptr, multiAxisFamily->createFamilyWithVariation(variations)); - EXPECT_EQ(nullptr, noAxisFamily->createFamilyWithVariation(variations)); - } - { - // At least one axis is supported, should create new instance. - std::vector variations = { - { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, - { MinikinFont::MakeTag('Z', 'Z', 'Z', 'Z'), 1.0f } - }; - MinikinAutoUnref newFamily( - multiAxisFamily->createFamilyWithVariation(variations)); - EXPECT_NE(nullptr, newFamily.get()); - EXPECT_NE(multiAxisFamily.get(), newFamily.get()); - EXPECT_EQ(nullptr, noAxisFamily->createFamilyWithVariation(variations)); - } -} - } // namespace minikin diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.cpp b/engine/src/flutter/tests/util/MinikinFontForTest.cpp index f191f07d6e9..a4132e5178d 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/util/MinikinFontForTest.cpp @@ -34,11 +34,9 @@ namespace minikin { static int uniqueId = 0; // TODO: make thread safe if necessary. -MinikinFontForTest::MinikinFontForTest(const std::string& font_path, int index, - const std::vector& variations) : +MinikinFontForTest::MinikinFontForTest(const std::string& font_path, int index) : MinikinFont(uniqueId++), mFontPath(font_path), - mVariations(variations), mFontIndex(index) { int fd = open(font_path.c_str(), O_RDONLY); LOG_ALWAYS_FATAL_IF(fd == -1); @@ -69,9 +67,4 @@ void MinikinFontForTest::GetBounds(MinikinRect* bounds, uint32_t /* glyph_id */, bounds->mBottom = 10.0f; } -MinikinFont* MinikinFontForTest::createFontWithVariation( - const std::vector& variations) const { - return new MinikinFontForTest(mFontPath, mFontIndex, variations); -} - } // namespace minikin diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.h b/engine/src/flutter/tests/util/MinikinFontForTest.h index 2a107036eda..ee0eadbe0c2 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.h +++ b/engine/src/flutter/tests/util/MinikinFontForTest.h @@ -25,10 +25,7 @@ namespace minikin { class MinikinFontForTest : public MinikinFont { public: - MinikinFontForTest(const std::string& font_path, int index, - const std::vector& variations); - MinikinFontForTest(const std::string& font_path, int index) - : MinikinFontForTest(font_path, index, std::vector()) {} + MinikinFontForTest(const std::string& font_path, int index); MinikinFontForTest(const std::string& font_path) : MinikinFontForTest(font_path, 0) {} virtual ~MinikinFontForTest(); @@ -38,19 +35,15 @@ public: const MinikinPaint& paint) const; const std::string& fontPath() const { return mFontPath; } - const std::vector& variations() const { return mVariations; } - const void* GetFontData() const { return mFontData; } size_t GetFontSize() const { return mFontSize; } int GetFontIndex() const { return mFontIndex; } - MinikinFont* createFontWithVariation(const std::vector& variations) const; private: MinikinFontForTest() = delete; MinikinFontForTest(const MinikinFontForTest&) = delete; MinikinFontForTest& operator=(MinikinFontForTest&) = delete; const std::string mFontPath; - const std::vector mVariations; const int mFontIndex; void* mFontData; size_t mFontSize; From 92c0eb1f83a380f4a8f5f7f8e2007dbc0ca433eb Mon Sep 17 00:00:00 2001 From: Siyamed Sinir Date: Fri, 20 Jan 2017 01:11:02 +0000 Subject: [PATCH 225/364] Revert "Remove FontFamily.addFont and make FontFamily immutable." This reverts commit 0470cdb3e41f0ae603f6a3e89efabdc196424652. Bug: 34378805 Change-Id: I8f1ee00b365c8b17c6140e9e286fbea082e31364 --- .../src/flutter/include/minikin/FontFamily.h | 57 ++++----- .../flutter/libs/minikin/FontCollection.cpp | 18 +-- .../src/flutter/libs/minikin/FontFamily.cpp | 113 ++++++++++-------- engine/src/flutter/sample/example.cpp | 8 +- engine/src/flutter/sample/example_skia.cpp | 8 +- .../unittest/FontCollectionItemizeTest.cpp | 46 +++---- .../tests/unittest/FontCollectionTest.cpp | 4 +- .../flutter/tests/unittest/FontFamilyTest.cpp | 22 ++-- .../src/flutter/tests/util/FontTestUtils.cpp | 25 ++-- 9 files changed, 163 insertions(+), 138 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index bdf00e9f7c4..10362c24de1 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -98,61 +98,64 @@ struct FakedFont { FontFakery fakery; }; -struct Font { - Font(MinikinFont* typeface, FontStyle style); - Font(Font&& o); - Font(const Font& o); - ~Font(); - - MinikinFont* typeface; - FontStyle style; -}; - class FontFamily : public MinikinRefCounted { public: - explicit FontFamily(std::vector&& fonts); - FontFamily(int variant, std::vector&& fonts); - FontFamily(uint32_t langId, int variant, std::vector&& fonts); + FontFamily(); + + explicit FontFamily(int variant); + + FontFamily(uint32_t langId, int variant) + : mLangId(langId), + mVariant(variant), + mHasVSTable(false), + mCoverageValid(false) { + } ~FontFamily(); - // TODO: Good to expose FontUtil.h. - static bool analyzeStyle(MinikinFont* typeface, int* weight, bool* italic); + // Add font to family, extracting style information from the font + bool addFont(MinikinFont* typeface); + void addFont(MinikinFont* typeface, FontStyle style); FakedFont getClosestMatch(FontStyle style) const; uint32_t langId() const { return mLangId; } int variant() const { return mVariant; } // API's for enumerating the fonts in a family. These don't guarantee any particular order - size_t getNumFonts() const { return mFonts.size(); } - MinikinFont* getFont(size_t index) const { return mFonts[index].typeface; } - FontStyle getStyle(size_t index) const { return mFonts[index].style; } + size_t getNumFonts() const; + MinikinFont* getFont(size_t index) const; + FontStyle getStyle(size_t index) const; bool isColorEmojiFamily() const; - // Get Unicode coverage. - const SparseBitSet& getCoverage() const { return mCoverage; } + // Get Unicode coverage. Lifetime of returned bitset is same as receiver. May return nullptr on + // error. + const SparseBitSet* getCoverage(); // Returns true if the font has a glyph for the code point and variation selector pair. // Caller should acquire a lock before calling the method. - bool hasGlyph(uint32_t codepoint, uint32_t variationSelector) const; + bool hasGlyph(uint32_t codepoint, uint32_t variationSelector); // Returns true if this font family has a variaion sequence table (cmap format 14 subtable). - bool hasVSTable() const { return mHasVSTable; } + bool hasVSTable() const; private: - void computeCoverage(); + void addFontLocked(MinikinFont* typeface, FontStyle style); + class Font { + public: + Font(MinikinFont* typeface, FontStyle style) : + typeface(typeface), style(style) { } + MinikinFont* typeface; + FontStyle style; + }; uint32_t mLangId; int mVariant; std::vector mFonts; SparseBitSet mCoverage; bool mHasVSTable; - - // Forbid copying and assignment. - FontFamily(const FontFamily&) = delete; - void operator=(const FontFamily&) = delete; + bool mCoverageValid; }; } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 4688520699d..9d26377e6d1 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -96,13 +96,17 @@ FontCollection::FontCollection(const vector& typefaces) : continue; } family->RefLocked(); - const SparseBitSet& coverage = family->getCoverage(); + const SparseBitSet* coverage = family->getCoverage(); + if (coverage == nullptr) { + family->UnrefLocked(); + continue; + } mFamilies.push_back(family); // emplace_back would be better if (family->hasVSTable()) { mVSFamilyVec.push_back(family); } - mMaxChar = max(mMaxChar, coverage.length()); - lastChar.push_back(coverage.nextSetBit(0)); + mMaxChar = max(mMaxChar, coverage->length()); + lastChar.push_back(coverage->nextSetBit(0)); } nTypefaces = mFamilies.size(); LOG_ALWAYS_FATAL_IF(nTypefaces == 0, @@ -126,7 +130,7 @@ FontCollection::FontCollection(const vector& typefaces) : FontFamily* family = mFamilies[j]; mFamilyVec.push_back(family); offset++; - uint32_t nextChar = family->getCoverage().nextSetBit((i + 1) << kLogCharsPerPage); + uint32_t nextChar = family->getCoverage()->nextSetBit((i + 1) << kLogCharsPerPage); #ifdef VERBOSE_DEBUG ALOGD("nextChar = %d (j = %zd)\n", nextChar, j); #endif @@ -193,7 +197,7 @@ uint32_t FontCollection::calcFamilyScore(uint32_t ch, uint32_t vs, int variant, // variation sequence's base character. uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, FontFamily* fontFamily) const { const bool hasVSGlyph = (vs != 0) && fontFamily->hasGlyph(ch, vs); - if (!hasVSGlyph && !fontFamily->getCoverage().get(ch)) { + if (!hasVSGlyph && !fontFamily->getCoverage()->get(ch)) { // The font doesn't support either variation sequence or even the base character. return kUnsupportedFontScore; } @@ -412,7 +416,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty if (lastFamily != nullptr) { if (isStickyWhitelisted(ch)) { // Continue using existing font as long as it has coverage and is whitelisted - shouldContinueRun = lastFamily->getCoverage().get(ch); + shouldContinueRun = lastFamily->getCoverage()->get(ch); } else if (isVariationSelector(ch)) { // Always continue if the character is a variation selector. shouldContinueRun = true; @@ -432,7 +436,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty if (utf16Pos != 0 && ((U_GET_GC_MASK(ch) & U_GC_M_MASK) != 0 || (isEmojiModifier(ch) && isEmojiBase(prevCh))) && - family && family->getCoverage().get(prevCh)) { + family && family->getCoverage()->get(prevCh)) { const size_t prevChLength = U16_LENGTH(prevCh); run->end -= prevChLength; if (run->start == run->end) { diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 164cc7d8ad8..8efa32a937e 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -64,51 +64,45 @@ uint32_t FontStyle::pack(int variant, int weight, bool italic) { return (weight & kWeightMask) | (italic ? kItalicMask : 0) | (variant << kVariantShift); } -Font::Font(MinikinFont* typeface, FontStyle style) - : typeface(typeface), style(style) { - typeface->Ref(); +FontFamily::FontFamily() : FontFamily(0 /* variant */) { } -Font::Font(Font&& o) { - typeface = o.typeface; - style = o.style; - o.typeface = nullptr; -} - -Font::Font(const Font& o) { - typeface = o.typeface; - typeface->Ref(); - style = o.style; -} - -Font::~Font() { - if (typeface == nullptr) { - return; - } - typeface->UnrefLocked(); -} - -FontFamily::FontFamily(std::vector&& fonts) : FontFamily(0 /* variant */, std::move(fonts)) { -} - -FontFamily::FontFamily(int variant, std::vector&& fonts) - : FontFamily(FontLanguageListCache::kEmptyListId, variant, std::move(fonts)) { -} - -FontFamily::FontFamily(uint32_t langId, int variant, std::vector&& fonts) - : mLangId(langId), mVariant(variant), mFonts(std::move(fonts)), mHasVSTable(false) { - computeCoverage(); +FontFamily::FontFamily(int variant) : FontFamily(FontLanguageListCache::kEmptyListId, variant) { } FontFamily::~FontFamily() { + for (size_t i = 0; i < mFonts.size(); i++) { + mFonts[i].typeface->UnrefLocked(); + } } -bool FontFamily::analyzeStyle(MinikinFont* typeface, int* weight, bool* italic) { +bool FontFamily::addFont(MinikinFont* typeface) { android::AutoMutex _l(gMinikinLock); const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2'); HbBlob os2Table(getFontTable(typeface, os2Tag)); if (os2Table.get() == nullptr) return false; - return ::minikin::analyzeStyle(os2Table.get(), os2Table.size(), weight, italic); + int weight; + bool italic; + if (analyzeStyle(os2Table.get(), os2Table.size(), &weight, &italic)) { + //ALOGD("analyzed weight = %d, italic = %s", weight, italic ? "true" : "false"); + FontStyle style(weight, italic); + addFontLocked(typeface, style); + return true; + } else { + ALOGD("failed to analyze style"); + } + return false; +} + +void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { + android::AutoMutex _l(gMinikinLock); + addFontLocked(typeface, style); +} + +void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { + typeface->RefLocked(); + mFonts.push_back(Font(typeface, style)); + mCoverageValid = false; } // Compute a matching metric between two styles - 0 is an exact match @@ -152,6 +146,18 @@ FakedFont FontFamily::getClosestMatch(FontStyle style) const { return result; } +size_t FontFamily::getNumFonts() const { + return mFonts.size(); +} + +MinikinFont* FontFamily::getFont(size_t index) const { + return mFonts[index].typeface; +} + +FontStyle FontFamily::getStyle(size_t index) const { + return mFonts[index].style; +} + bool FontFamily::isColorEmojiFamily() const { const FontLanguages& languageList = FontLanguageListCache::getById(mLangId); for (size_t i = 0; i < languageList.size(); ++i) { @@ -162,24 +168,30 @@ bool FontFamily::isColorEmojiFamily() const { return false; } -void FontFamily::computeCoverage() { - android::AutoMutex _l(gMinikinLock); - const FontStyle defaultStyle; - MinikinFont* typeface = getClosestMatch(defaultStyle).font; - const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); - HbBlob cmapTable(getFontTable(typeface, cmapTag)); - if (cmapTable.get() == nullptr) { - ALOGE("Could not get cmap table size!\n"); - return; - } - // TODO: Error check? - CmapCoverage::getCoverage(mCoverage, cmapTable.get(), cmapTable.size(), &mHasVSTable); +const SparseBitSet* FontFamily::getCoverage() { + if (!mCoverageValid) { + const FontStyle defaultStyle; + MinikinFont* typeface = getClosestMatch(defaultStyle).font; + const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); + HbBlob cmapTable(getFontTable(typeface, cmapTag)); + if (cmapTable.get() == nullptr) { + ALOGE("Could not get cmap table size!\n"); + // Note: This means we will retry on the next call to getCoverage, as we can't store + // the failure. This is fine, as we assume this doesn't really happen in practice. + return nullptr; + } + // TODO: Error check? + CmapCoverage::getCoverage(mCoverage, cmapTable.get(), cmapTable.size(), &mHasVSTable); #ifdef VERBOSE_DEBUG - ALOGD("font coverage length=%d, first ch=%x\n", mCoverage.length(), mCoverage.nextSetBit(0)); + ALOGD("font coverage length=%d, first ch=%x\n", mCoverage.length(), + mCoverage.nextSetBit(0)); #endif + mCoverageValid = true; + } + return &mCoverage; } -bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) const { +bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) { assertMinikinLocked(); if (variationSelector != 0 && !mHasVSTable) { // Early exit if the variation selector is specified but the font doesn't have a cmap format @@ -196,4 +208,9 @@ bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) const return result; } +bool FontFamily::hasVSTable() const { + LOG_ALWAYS_FATAL_IF(!mCoverageValid, "Do not call this method before getCoverage() call"); + return mHasVSTable; +} + } // namespace minikin diff --git a/engine/src/flutter/sample/example.cpp b/engine/src/flutter/sample/example.cpp index 1c9c322d232..a27918ea758 100644 --- a/engine/src/flutter/sample/example.cpp +++ b/engine/src/flutter/sample/example.cpp @@ -45,9 +45,9 @@ FontCollection *makeFontCollection() { "/system/fonts/Roboto-LightItalic.ttf" }; + FontFamily *family = new FontFamily(); FT_Face face; FT_Error error; - std::vector fonts; for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) { const char *fn = fns[i]; printf("adding %s\n", fn); @@ -56,16 +56,16 @@ FontCollection *makeFontCollection() { printf("error loading %s, %d\n", fn, error); } MinikinFont *font = new MinikinFontFreeType(face); - fonts.push_back(Font(font, FontStyle())); + family->addFont(font); } - FontFamily *family = new FontFamily(std::move(fonts)); typefaces.push_back(family); #if 1 + family = new FontFamily(); const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf"; error = FT_New_Face(library, fn, 0, &face); MinikinFont *font = new MinikinFontFreeType(face); - family = new FontFamily(std::vector({ Font(font, FontStyle()) })); + family->addFont(font); typefaces.push_back(family); #endif diff --git a/engine/src/flutter/sample/example_skia.cpp b/engine/src/flutter/sample/example_skia.cpp index 6e6f868051c..b04c8abcbcc 100644 --- a/engine/src/flutter/sample/example_skia.cpp +++ b/engine/src/flutter/sample/example_skia.cpp @@ -54,21 +54,21 @@ FontCollection *makeFontCollection() { "/system/fonts/Roboto-LightItalic.ttf" }; - std::vector fonts; + FontFamily *family = new FontFamily(); for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) { const char *fn = fns[i]; sk_sp skFace = SkTypeface::MakeFromFile(fn); MinikinFont *font = new MinikinFontSkia(std::move(skFace)); - fonts.push_back(Font(font, FontStyle())); + family->addFont(font); } - FontFamily *family = new FontFamily(std::move(fonts)); typefaces.push_back(family); #if 1 + family = new FontFamily(); const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf"; sk_sp skFace = SkTypeface::MakeFromFile(fn); MinikinFont *font = new MinikinFontSkia(std::move(skFace)); - family = new FontFamily(std::vector({ Font(font, FontStyle()) })); + family->addFont(font); typefaces.push_back(family); #endif diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 5c5a5d343cb..52786d0c7e0 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -668,14 +668,14 @@ TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { const std::string kVSTestFont = kTestFontDir "VarioationSelectorTest-Regular.ttf"; std::vector families; + FontFamily* family1 = new FontFamily(VARIANT_DEFAULT); MinikinAutoUnref font(new MinikinFontForTest(kLatinFont)); - FontFamily* family1 = new FontFamily(VARIANT_DEFAULT, - std::vector{ Font(font.get(), FontStyle()) }); + family1->addFont(font.get()); families.push_back(family1); + FontFamily* family2 = new FontFamily(VARIANT_DEFAULT); MinikinAutoUnref font2(new MinikinFontForTest(kVSTestFont)); - FontFamily* family2 = new FontFamily(VARIANT_DEFAULT, - std::vector{ Font(font2.get(), FontStyle()) }); + family2->addFont(font2.get()); families.push_back(family2); FontCollection collection(families); @@ -811,11 +811,11 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { std::vector families; // Prepare first font which doesn't supports U+9AA8 + FontFamily* firstFamily = new FontFamily( + FontStyle::registerLanguageList("und"), 0 /* variant */); MinikinAutoUnref firstFamilyMinikinFont( new MinikinFontForTest(kNoGlyphFont)); - FontFamily* firstFamily = new FontFamily( - FontStyle::registerLanguageList("und"), 0 /* variant */, - std::vector({ Font(firstFamilyMinikinFont.get(), FontStyle()) })); + firstFamily->addFont(firstFamilyMinikinFont.get()); families.push_back(firstFamily); // Prepare font families @@ -824,10 +824,10 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { std::unordered_map fontLangIdxMap; for (size_t i = 0; i < testCase.fontLanguages.size(); ++i) { - MinikinAutoUnref minikin_font(new MinikinFontForTest(kJAFont)); FontFamily* family = new FontFamily( - FontStyle::registerLanguageList(testCase.fontLanguages[i]), 0 /* variant */, - std::vector({ Font(minikin_font.get(), FontStyle()) })); + FontStyle::registerLanguageList(testCase.fontLanguages[i]), 0 /* variant */); + MinikinAutoUnref minikin_font(new MinikinFontForTest(kJAFont)); + family->addFont(minikin_font.get()); families.push_back(family); fontLangIdxMap.insert(std::make_pair(minikin_font.get(), i)); } @@ -1417,12 +1417,13 @@ TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS) { MinikinAutoUnref fontA(new MinikinFontForTest(kZH_HansFont)); MinikinAutoUnref fontB(new MinikinFontForTest(kZH_HansFont)); - MinikinAutoUnref dummyFamily(new FontFamily( - std::vector({ Font(dummyFont.get(), FontStyle()) }))); - MinikinAutoUnref familyA(new FontFamily( - std::vector({ Font(fontA.get(), FontStyle()) }))); - MinikinAutoUnref familyB(new FontFamily( - std::vector({ Font(fontB.get(), FontStyle()) }))); + MinikinAutoUnref dummyFamily(new FontFamily()); + MinikinAutoUnref familyA(new FontFamily()); + MinikinAutoUnref familyB(new FontFamily()); + + dummyFamily->addFont(dummyFont.get()); + familyA->addFont(fontA.get()); + familyB->addFont(fontB.get()); std::vector families = { dummyFamily.get(), familyA.get(), familyB.get() }; @@ -1452,12 +1453,13 @@ TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS2) { MinikinAutoUnref noCmapFormat14Font( new MinikinFontForTest(kNoCmapFormat14Font)); - MinikinAutoUnref dummyFamily(new FontFamily( - std::vector({ Font(dummyFont.get(), FontStyle()) }))); - MinikinAutoUnref hasCmapFormat14Family(new FontFamily( - std::vector({ Font(hasCmapFormat14Font.get(), FontStyle()) }))); - MinikinAutoUnref noCmapFormat14Family(new FontFamily( - std::vector({ Font(noCmapFormat14Font.get(), FontStyle()) }))); + MinikinAutoUnref dummyFamily(new FontFamily()); + MinikinAutoUnref hasCmapFormat14Family(new FontFamily()); + MinikinAutoUnref noCmapFormat14Family(new FontFamily()); + + dummyFamily->addFont(dummyFont.get()); + hasCmapFormat14Family->addFont(hasCmapFormat14Font.get()); + noCmapFormat14Family->addFont(noCmapFormat14Font.get()); std::vector families = { dummyFamily.get(), hasCmapFormat14Family.get(), noCmapFormat14Family.get() }; diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index c0b6b526b78..62d2f022fa3 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -57,9 +57,9 @@ void expectVSGlyphs(const FontCollection* fc, uint32_t codepoint, const std::set } TEST(FontCollectionTest, hasVariationSelectorTest) { + MinikinAutoUnref family(new FontFamily()); MinikinAutoUnref font(new MinikinFontForTest(kVsTestFont)); - MinikinAutoUnref family(new FontFamily( - std::vector({ Font(font.get(), FontStyle()) }))); + family->addFont(font.get()); std::vector families({family.get()}); MinikinAutoUnref fc(new FontCollection(families)); diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index ddc36e45704..44098018929 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -464,10 +464,8 @@ void expectVSGlyphs(FontFamily* family, uint32_t codepoint, const std::set minikinFont(new MinikinFontForTest(kVsTestFont)); - MinikinAutoUnref family( - new FontFamily(std::vector{ - Font(minikinFont.get(), FontStyle()) - })); + MinikinAutoUnref family(new FontFamily); + family->addFont(minikinFont.get()); android::AutoMutex _l(gMinikinLock); @@ -480,23 +478,23 @@ TEST_F(FontFamilyTest, hasVariationSelectorTest) { const uint32_t kVS20 = 0xE0103; const uint32_t kSupportedChar1 = 0x82A6; - EXPECT_TRUE(family->getCoverage().get(kSupportedChar1)); + EXPECT_TRUE(family->getCoverage()->get(kSupportedChar1)); expectVSGlyphs(family.get(), kSupportedChar1, std::set({kVS1, kVS17, kVS18, kVS19})); const uint32_t kSupportedChar2 = 0x845B; - EXPECT_TRUE(family->getCoverage().get(kSupportedChar2)); + EXPECT_TRUE(family->getCoverage()->get(kSupportedChar2)); expectVSGlyphs(family.get(), kSupportedChar2, std::set({kVS2, kVS18, kVS19, kVS20})); const uint32_t kNoVsSupportedChar = 0x537F; - EXPECT_TRUE(family->getCoverage().get(kNoVsSupportedChar)); + EXPECT_TRUE(family->getCoverage()->get(kNoVsSupportedChar)); expectVSGlyphs(family.get(), kNoVsSupportedChar, std::set()); const uint32_t kVsOnlySupportedChar = 0x717D; - EXPECT_FALSE(family->getCoverage().get(kVsOnlySupportedChar)); + EXPECT_FALSE(family->getCoverage()->get(kVsOnlySupportedChar)); expectVSGlyphs(family.get(), kVsOnlySupportedChar, std::set({kVS3, kVS19, kVS20})); const uint32_t kNotSupportedChar = 0x845C; - EXPECT_FALSE(family->getCoverage().get(kNotSupportedChar)); + EXPECT_FALSE(family->getCoverage()->get(kNotSupportedChar)); expectVSGlyphs(family.get(), kNotSupportedChar, std::set()); } @@ -520,9 +518,11 @@ TEST_F(FontFamilyTest, hasVSTableTest) { MinikinAutoUnref minikinFont( new MinikinFontForTest(testCase.fontPath)); - MinikinAutoUnref family(new FontFamily( - std::vector{ Font(minikinFont.get(), FontStyle()) })); + MinikinAutoUnref family(new FontFamily); + family->addFont(minikinFont.get()); android::AutoMutex _l(gMinikinLock); + family->getCoverage(); + EXPECT_EQ(testCase.hasVSTable, family->hasVSTable()); } } diff --git a/engine/src/flutter/tests/util/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp index e29a2fe5344..0c7b2ba032c 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.cpp +++ b/engine/src/flutter/tests/util/FontTestUtils.cpp @@ -48,7 +48,16 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { } } - std::vector fonts; + xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); + FontFamily* family; + if (lang == nullptr) { + family = new FontFamily(variant); + } else { + uint32_t langId = FontStyle::registerLanguageList( + std::string((const char*)lang, xmlStrlen(lang))); + family = new FontFamily(langId, variant); + } + for (xmlNode* fontNode = familyNode->children; fontNode; fontNode = fontNode->next) { if (xmlStrcmp(fontNode->name, (const xmlChar*)"font") != 0) { continue; @@ -71,23 +80,13 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { if (index == nullptr) { MinikinAutoUnref minikinFont(new MinikinFontForTest(fontPath)); - fonts.push_back(Font(minikinFont.get(), FontStyle(weight, italic))); + family->addFont(minikinFont.get(), FontStyle(weight, italic)); } else { MinikinAutoUnref minikinFont(new MinikinFontForTest(fontPath, atoi((const char*)index))); - fonts.push_back(Font(minikinFont.get(), FontStyle(weight, italic))); + family->addFont(minikinFont.get(), FontStyle(weight, italic)); } } - - xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); - FontFamily* family; - if (lang == nullptr) { - family = new FontFamily(variant, std::move(fonts)); - } else { - uint32_t langId = FontStyle::registerLanguageList( - std::string((const char*)lang, xmlStrlen(lang))); - family = new FontFamily(langId, variant, std::move(fonts)); - } families.push_back(family); } xmlFreeDoc(doc); From 0afb39eaedb81d0e9c07b2bd276aa33384519d79 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 29 Dec 2016 00:36:30 +0900 Subject: [PATCH 226/364] Remove FontFamily.addFont and make FontFamily immutable. This is 2nd attempt of 0470cdb3e41f0ae603f6a3e89efabdc196424652 The difference is adding clearElementsEithLock to Font class which is necessary to delete Fonts object outside of minikin. This method should be removed once http://b/28119474 is fixed. Here is original commit message of reverted change. This lays the groundwork for making SparseBitSet serializable. FontFamily.addFont is only used when the FontFamily is constructed. Thus, instead of calling FontFamily.addFont multiple time, passes Font list to the constructor. By this change, FontFamily can be immutable now. By making FontFamily immutable, We can create FontFamily with pre-calculated SparseBitSet. Bug: 34042446 Bug: 28119474 Bug: 34378805 Test: minikin_tests has passed Change-Id: Ice433931196f5ae79a1a7ee0c98020f914aeb5f2 --- .../src/flutter/include/minikin/FontFamily.h | 62 ++++----- .../flutter/libs/minikin/FontCollection.cpp | 18 +-- .../src/flutter/libs/minikin/FontFamily.cpp | 120 ++++++++---------- engine/src/flutter/sample/example.cpp | 8 +- engine/src/flutter/sample/example_skia.cpp | 8 +- .../unittest/FontCollectionItemizeTest.cpp | 46 ++++--- .../tests/unittest/FontCollectionTest.cpp | 4 +- .../flutter/tests/unittest/FontFamilyTest.cpp | 22 ++-- .../src/flutter/tests/util/FontTestUtils.cpp | 25 ++-- 9 files changed, 149 insertions(+), 164 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 10362c24de1..71a63840556 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -98,64 +98,66 @@ struct FakedFont { FontFakery fakery; }; +struct Font { + Font(MinikinFont* typeface, FontStyle style); + Font(Font&& o); + Font(const Font& o); + ~Font(); + + MinikinFont* typeface; + FontStyle style; + + // TODO: remove this weird function. http://b/28119474 + // MinikinFont requres mutex lock for destruction, but the mutex lock is not + // visible from outside of minikin library. + static void clearElementsWithLock(std::vector* fonts); +}; + class FontFamily : public MinikinRefCounted { public: - FontFamily(); - - explicit FontFamily(int variant); - - FontFamily(uint32_t langId, int variant) - : mLangId(langId), - mVariant(variant), - mHasVSTable(false), - mCoverageValid(false) { - } + explicit FontFamily(std::vector&& fonts); + FontFamily(int variant, std::vector&& fonts); + FontFamily(uint32_t langId, int variant, std::vector&& fonts); ~FontFamily(); - // Add font to family, extracting style information from the font - bool addFont(MinikinFont* typeface); + // TODO: Good to expose FontUtil.h. + static bool analyzeStyle(MinikinFont* typeface, int* weight, bool* italic); - void addFont(MinikinFont* typeface, FontStyle style); FakedFont getClosestMatch(FontStyle style) const; uint32_t langId() const { return mLangId; } int variant() const { return mVariant; } // API's for enumerating the fonts in a family. These don't guarantee any particular order - size_t getNumFonts() const; - MinikinFont* getFont(size_t index) const; - FontStyle getStyle(size_t index) const; + size_t getNumFonts() const { return mFonts.size(); } + MinikinFont* getFont(size_t index) const { return mFonts[index].typeface; } + FontStyle getStyle(size_t index) const { return mFonts[index].style; } bool isColorEmojiFamily() const; - // Get Unicode coverage. Lifetime of returned bitset is same as receiver. May return nullptr on - // error. - const SparseBitSet* getCoverage(); + // Get Unicode coverage. + const SparseBitSet& getCoverage() const { return mCoverage; } // Returns true if the font has a glyph for the code point and variation selector pair. // Caller should acquire a lock before calling the method. - bool hasGlyph(uint32_t codepoint, uint32_t variationSelector); + bool hasGlyph(uint32_t codepoint, uint32_t variationSelector) const; // Returns true if this font family has a variaion sequence table (cmap format 14 subtable). - bool hasVSTable() const; + bool hasVSTable() const { return mHasVSTable; } private: - void addFontLocked(MinikinFont* typeface, FontStyle style); + void computeCoverage(); - class Font { - public: - Font(MinikinFont* typeface, FontStyle style) : - typeface(typeface), style(style) { } - MinikinFont* typeface; - FontStyle style; - }; uint32_t mLangId; int mVariant; std::vector mFonts; SparseBitSet mCoverage; bool mHasVSTable; - bool mCoverageValid; + + // Forbid copying and assignment. + FontFamily(const FontFamily&) = delete; + void operator=(const FontFamily&) = delete; }; } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 9d26377e6d1..4688520699d 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -96,17 +96,13 @@ FontCollection::FontCollection(const vector& typefaces) : continue; } family->RefLocked(); - const SparseBitSet* coverage = family->getCoverage(); - if (coverage == nullptr) { - family->UnrefLocked(); - continue; - } + const SparseBitSet& coverage = family->getCoverage(); mFamilies.push_back(family); // emplace_back would be better if (family->hasVSTable()) { mVSFamilyVec.push_back(family); } - mMaxChar = max(mMaxChar, coverage->length()); - lastChar.push_back(coverage->nextSetBit(0)); + mMaxChar = max(mMaxChar, coverage.length()); + lastChar.push_back(coverage.nextSetBit(0)); } nTypefaces = mFamilies.size(); LOG_ALWAYS_FATAL_IF(nTypefaces == 0, @@ -130,7 +126,7 @@ FontCollection::FontCollection(const vector& typefaces) : FontFamily* family = mFamilies[j]; mFamilyVec.push_back(family); offset++; - uint32_t nextChar = family->getCoverage()->nextSetBit((i + 1) << kLogCharsPerPage); + uint32_t nextChar = family->getCoverage().nextSetBit((i + 1) << kLogCharsPerPage); #ifdef VERBOSE_DEBUG ALOGD("nextChar = %d (j = %zd)\n", nextChar, j); #endif @@ -197,7 +193,7 @@ uint32_t FontCollection::calcFamilyScore(uint32_t ch, uint32_t vs, int variant, // variation sequence's base character. uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, FontFamily* fontFamily) const { const bool hasVSGlyph = (vs != 0) && fontFamily->hasGlyph(ch, vs); - if (!hasVSGlyph && !fontFamily->getCoverage()->get(ch)) { + if (!hasVSGlyph && !fontFamily->getCoverage().get(ch)) { // The font doesn't support either variation sequence or even the base character. return kUnsupportedFontScore; } @@ -416,7 +412,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty if (lastFamily != nullptr) { if (isStickyWhitelisted(ch)) { // Continue using existing font as long as it has coverage and is whitelisted - shouldContinueRun = lastFamily->getCoverage()->get(ch); + shouldContinueRun = lastFamily->getCoverage().get(ch); } else if (isVariationSelector(ch)) { // Always continue if the character is a variation selector. shouldContinueRun = true; @@ -436,7 +432,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty if (utf16Pos != 0 && ((U_GET_GC_MASK(ch) & U_GC_M_MASK) != 0 || (isEmojiModifier(ch) && isEmojiBase(prevCh))) && - family && family->getCoverage()->get(prevCh)) { + family && family->getCoverage().get(prevCh)) { const size_t prevChLength = U16_LENGTH(prevCh); run->end -= prevChLength; if (run->start == run->end) { diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 8efa32a937e..619110db8e5 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -64,45 +64,56 @@ uint32_t FontStyle::pack(int variant, int weight, bool italic) { return (weight & kWeightMask) | (italic ? kItalicMask : 0) | (variant << kVariantShift); } -FontFamily::FontFamily() : FontFamily(0 /* variant */) { +Font::Font(MinikinFont* typeface, FontStyle style) + : typeface(typeface), style(style) { + typeface->Ref(); } -FontFamily::FontFamily(int variant) : FontFamily(FontLanguageListCache::kEmptyListId, variant) { +Font::Font(Font&& o) { + typeface = o.typeface; + style = o.style; + o.typeface = nullptr; +} + +Font::Font(const Font& o) { + typeface = o.typeface; + typeface->Ref(); + style = o.style; +} + +Font::~Font() { + if (typeface == nullptr) { + return; + } + typeface->UnrefLocked(); +} + +void Font::clearElementsWithLock(std::vector* fonts) { + android::AutoMutex _l(gMinikinLock); + fonts->clear(); +} + +FontFamily::FontFamily(std::vector&& fonts) : FontFamily(0 /* variant */, std::move(fonts)) { +} + +FontFamily::FontFamily(int variant, std::vector&& fonts) + : FontFamily(FontLanguageListCache::kEmptyListId, variant, std::move(fonts)) { +} + +FontFamily::FontFamily(uint32_t langId, int variant, std::vector&& fonts) + : mLangId(langId), mVariant(variant), mFonts(std::move(fonts)), mHasVSTable(false) { + computeCoverage(); } FontFamily::~FontFamily() { - for (size_t i = 0; i < mFonts.size(); i++) { - mFonts[i].typeface->UnrefLocked(); - } } -bool FontFamily::addFont(MinikinFont* typeface) { +bool FontFamily::analyzeStyle(MinikinFont* typeface, int* weight, bool* italic) { android::AutoMutex _l(gMinikinLock); const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2'); HbBlob os2Table(getFontTable(typeface, os2Tag)); if (os2Table.get() == nullptr) return false; - int weight; - bool italic; - if (analyzeStyle(os2Table.get(), os2Table.size(), &weight, &italic)) { - //ALOGD("analyzed weight = %d, italic = %s", weight, italic ? "true" : "false"); - FontStyle style(weight, italic); - addFontLocked(typeface, style); - return true; - } else { - ALOGD("failed to analyze style"); - } - return false; -} - -void FontFamily::addFont(MinikinFont* typeface, FontStyle style) { - android::AutoMutex _l(gMinikinLock); - addFontLocked(typeface, style); -} - -void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { - typeface->RefLocked(); - mFonts.push_back(Font(typeface, style)); - mCoverageValid = false; + return ::minikin::analyzeStyle(os2Table.get(), os2Table.size(), weight, italic); } // Compute a matching metric between two styles - 0 is an exact match @@ -146,18 +157,6 @@ FakedFont FontFamily::getClosestMatch(FontStyle style) const { return result; } -size_t FontFamily::getNumFonts() const { - return mFonts.size(); -} - -MinikinFont* FontFamily::getFont(size_t index) const { - return mFonts[index].typeface; -} - -FontStyle FontFamily::getStyle(size_t index) const { - return mFonts[index].style; -} - bool FontFamily::isColorEmojiFamily() const { const FontLanguages& languageList = FontLanguageListCache::getById(mLangId); for (size_t i = 0; i < languageList.size(); ++i) { @@ -168,30 +167,24 @@ bool FontFamily::isColorEmojiFamily() const { return false; } -const SparseBitSet* FontFamily::getCoverage() { - if (!mCoverageValid) { - const FontStyle defaultStyle; - MinikinFont* typeface = getClosestMatch(defaultStyle).font; - const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); - HbBlob cmapTable(getFontTable(typeface, cmapTag)); - if (cmapTable.get() == nullptr) { - ALOGE("Could not get cmap table size!\n"); - // Note: This means we will retry on the next call to getCoverage, as we can't store - // the failure. This is fine, as we assume this doesn't really happen in practice. - return nullptr; - } - // TODO: Error check? - CmapCoverage::getCoverage(mCoverage, cmapTable.get(), cmapTable.size(), &mHasVSTable); -#ifdef VERBOSE_DEBUG - ALOGD("font coverage length=%d, first ch=%x\n", mCoverage.length(), - mCoverage.nextSetBit(0)); -#endif - mCoverageValid = true; +void FontFamily::computeCoverage() { + android::AutoMutex _l(gMinikinLock); + const FontStyle defaultStyle; + MinikinFont* typeface = getClosestMatch(defaultStyle).font; + const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); + HbBlob cmapTable(getFontTable(typeface, cmapTag)); + if (cmapTable.get() == nullptr) { + ALOGE("Could not get cmap table size!\n"); + return; } - return &mCoverage; + // TODO: Error check? + CmapCoverage::getCoverage(mCoverage, cmapTable.get(), cmapTable.size(), &mHasVSTable); +#ifdef VERBOSE_DEBUG + ALOGD("font coverage length=%d, first ch=%x\n", mCoverage.length(), mCoverage.nextSetBit(0)); +#endif } -bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) { +bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) const { assertMinikinLocked(); if (variationSelector != 0 && !mHasVSTable) { // Early exit if the variation selector is specified but the font doesn't have a cmap format @@ -208,9 +201,4 @@ bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) { return result; } -bool FontFamily::hasVSTable() const { - LOG_ALWAYS_FATAL_IF(!mCoverageValid, "Do not call this method before getCoverage() call"); - return mHasVSTable; -} - } // namespace minikin diff --git a/engine/src/flutter/sample/example.cpp b/engine/src/flutter/sample/example.cpp index a27918ea758..1c9c322d232 100644 --- a/engine/src/flutter/sample/example.cpp +++ b/engine/src/flutter/sample/example.cpp @@ -45,9 +45,9 @@ FontCollection *makeFontCollection() { "/system/fonts/Roboto-LightItalic.ttf" }; - FontFamily *family = new FontFamily(); FT_Face face; FT_Error error; + std::vector fonts; for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) { const char *fn = fns[i]; printf("adding %s\n", fn); @@ -56,16 +56,16 @@ FontCollection *makeFontCollection() { printf("error loading %s, %d\n", fn, error); } MinikinFont *font = new MinikinFontFreeType(face); - family->addFont(font); + fonts.push_back(Font(font, FontStyle())); } + FontFamily *family = new FontFamily(std::move(fonts)); typefaces.push_back(family); #if 1 - family = new FontFamily(); const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf"; error = FT_New_Face(library, fn, 0, &face); MinikinFont *font = new MinikinFontFreeType(face); - family->addFont(font); + family = new FontFamily(std::vector({ Font(font, FontStyle()) })); typefaces.push_back(family); #endif diff --git a/engine/src/flutter/sample/example_skia.cpp b/engine/src/flutter/sample/example_skia.cpp index b04c8abcbcc..6e6f868051c 100644 --- a/engine/src/flutter/sample/example_skia.cpp +++ b/engine/src/flutter/sample/example_skia.cpp @@ -54,21 +54,21 @@ FontCollection *makeFontCollection() { "/system/fonts/Roboto-LightItalic.ttf" }; - FontFamily *family = new FontFamily(); + std::vector fonts; for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) { const char *fn = fns[i]; sk_sp skFace = SkTypeface::MakeFromFile(fn); MinikinFont *font = new MinikinFontSkia(std::move(skFace)); - family->addFont(font); + fonts.push_back(Font(font, FontStyle())); } + FontFamily *family = new FontFamily(std::move(fonts)); typefaces.push_back(family); #if 1 - family = new FontFamily(); const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf"; sk_sp skFace = SkTypeface::MakeFromFile(fn); MinikinFont *font = new MinikinFontSkia(std::move(skFace)); - family->addFont(font); + family = new FontFamily(std::vector({ Font(font, FontStyle()) })); typefaces.push_back(family); #endif diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 52786d0c7e0..5c5a5d343cb 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -668,14 +668,14 @@ TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { const std::string kVSTestFont = kTestFontDir "VarioationSelectorTest-Regular.ttf"; std::vector families; - FontFamily* family1 = new FontFamily(VARIANT_DEFAULT); MinikinAutoUnref font(new MinikinFontForTest(kLatinFont)); - family1->addFont(font.get()); + FontFamily* family1 = new FontFamily(VARIANT_DEFAULT, + std::vector{ Font(font.get(), FontStyle()) }); families.push_back(family1); - FontFamily* family2 = new FontFamily(VARIANT_DEFAULT); MinikinAutoUnref font2(new MinikinFontForTest(kVSTestFont)); - family2->addFont(font2.get()); + FontFamily* family2 = new FontFamily(VARIANT_DEFAULT, + std::vector{ Font(font2.get(), FontStyle()) }); families.push_back(family2); FontCollection collection(families); @@ -811,11 +811,11 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { std::vector families; // Prepare first font which doesn't supports U+9AA8 - FontFamily* firstFamily = new FontFamily( - FontStyle::registerLanguageList("und"), 0 /* variant */); MinikinAutoUnref firstFamilyMinikinFont( new MinikinFontForTest(kNoGlyphFont)); - firstFamily->addFont(firstFamilyMinikinFont.get()); + FontFamily* firstFamily = new FontFamily( + FontStyle::registerLanguageList("und"), 0 /* variant */, + std::vector({ Font(firstFamilyMinikinFont.get(), FontStyle()) })); families.push_back(firstFamily); // Prepare font families @@ -824,10 +824,10 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { std::unordered_map fontLangIdxMap; for (size_t i = 0; i < testCase.fontLanguages.size(); ++i) { - FontFamily* family = new FontFamily( - FontStyle::registerLanguageList(testCase.fontLanguages[i]), 0 /* variant */); MinikinAutoUnref minikin_font(new MinikinFontForTest(kJAFont)); - family->addFont(minikin_font.get()); + FontFamily* family = new FontFamily( + FontStyle::registerLanguageList(testCase.fontLanguages[i]), 0 /* variant */, + std::vector({ Font(minikin_font.get(), FontStyle()) })); families.push_back(family); fontLangIdxMap.insert(std::make_pair(minikin_font.get(), i)); } @@ -1417,13 +1417,12 @@ TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS) { MinikinAutoUnref fontA(new MinikinFontForTest(kZH_HansFont)); MinikinAutoUnref fontB(new MinikinFontForTest(kZH_HansFont)); - MinikinAutoUnref dummyFamily(new FontFamily()); - MinikinAutoUnref familyA(new FontFamily()); - MinikinAutoUnref familyB(new FontFamily()); - - dummyFamily->addFont(dummyFont.get()); - familyA->addFont(fontA.get()); - familyB->addFont(fontB.get()); + MinikinAutoUnref dummyFamily(new FontFamily( + std::vector({ Font(dummyFont.get(), FontStyle()) }))); + MinikinAutoUnref familyA(new FontFamily( + std::vector({ Font(fontA.get(), FontStyle()) }))); + MinikinAutoUnref familyB(new FontFamily( + std::vector({ Font(fontB.get(), FontStyle()) }))); std::vector families = { dummyFamily.get(), familyA.get(), familyB.get() }; @@ -1453,13 +1452,12 @@ TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS2) { MinikinAutoUnref noCmapFormat14Font( new MinikinFontForTest(kNoCmapFormat14Font)); - MinikinAutoUnref dummyFamily(new FontFamily()); - MinikinAutoUnref hasCmapFormat14Family(new FontFamily()); - MinikinAutoUnref noCmapFormat14Family(new FontFamily()); - - dummyFamily->addFont(dummyFont.get()); - hasCmapFormat14Family->addFont(hasCmapFormat14Font.get()); - noCmapFormat14Family->addFont(noCmapFormat14Font.get()); + MinikinAutoUnref dummyFamily(new FontFamily( + std::vector({ Font(dummyFont.get(), FontStyle()) }))); + MinikinAutoUnref hasCmapFormat14Family(new FontFamily( + std::vector({ Font(hasCmapFormat14Font.get(), FontStyle()) }))); + MinikinAutoUnref noCmapFormat14Family(new FontFamily( + std::vector({ Font(noCmapFormat14Font.get(), FontStyle()) }))); std::vector families = { dummyFamily.get(), hasCmapFormat14Family.get(), noCmapFormat14Family.get() }; diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index 62d2f022fa3..c0b6b526b78 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -57,9 +57,9 @@ void expectVSGlyphs(const FontCollection* fc, uint32_t codepoint, const std::set } TEST(FontCollectionTest, hasVariationSelectorTest) { - MinikinAutoUnref family(new FontFamily()); MinikinAutoUnref font(new MinikinFontForTest(kVsTestFont)); - family->addFont(font.get()); + MinikinAutoUnref family(new FontFamily( + std::vector({ Font(font.get(), FontStyle()) }))); std::vector families({family.get()}); MinikinAutoUnref fc(new FontCollection(families)); diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 44098018929..ddc36e45704 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -464,8 +464,10 @@ void expectVSGlyphs(FontFamily* family, uint32_t codepoint, const std::set minikinFont(new MinikinFontForTest(kVsTestFont)); - MinikinAutoUnref family(new FontFamily); - family->addFont(minikinFont.get()); + MinikinAutoUnref family( + new FontFamily(std::vector{ + Font(minikinFont.get(), FontStyle()) + })); android::AutoMutex _l(gMinikinLock); @@ -478,23 +480,23 @@ TEST_F(FontFamilyTest, hasVariationSelectorTest) { const uint32_t kVS20 = 0xE0103; const uint32_t kSupportedChar1 = 0x82A6; - EXPECT_TRUE(family->getCoverage()->get(kSupportedChar1)); + EXPECT_TRUE(family->getCoverage().get(kSupportedChar1)); expectVSGlyphs(family.get(), kSupportedChar1, std::set({kVS1, kVS17, kVS18, kVS19})); const uint32_t kSupportedChar2 = 0x845B; - EXPECT_TRUE(family->getCoverage()->get(kSupportedChar2)); + EXPECT_TRUE(family->getCoverage().get(kSupportedChar2)); expectVSGlyphs(family.get(), kSupportedChar2, std::set({kVS2, kVS18, kVS19, kVS20})); const uint32_t kNoVsSupportedChar = 0x537F; - EXPECT_TRUE(family->getCoverage()->get(kNoVsSupportedChar)); + EXPECT_TRUE(family->getCoverage().get(kNoVsSupportedChar)); expectVSGlyphs(family.get(), kNoVsSupportedChar, std::set()); const uint32_t kVsOnlySupportedChar = 0x717D; - EXPECT_FALSE(family->getCoverage()->get(kVsOnlySupportedChar)); + EXPECT_FALSE(family->getCoverage().get(kVsOnlySupportedChar)); expectVSGlyphs(family.get(), kVsOnlySupportedChar, std::set({kVS3, kVS19, kVS20})); const uint32_t kNotSupportedChar = 0x845C; - EXPECT_FALSE(family->getCoverage()->get(kNotSupportedChar)); + EXPECT_FALSE(family->getCoverage().get(kNotSupportedChar)); expectVSGlyphs(family.get(), kNotSupportedChar, std::set()); } @@ -518,11 +520,9 @@ TEST_F(FontFamilyTest, hasVSTableTest) { MinikinAutoUnref minikinFont( new MinikinFontForTest(testCase.fontPath)); - MinikinAutoUnref family(new FontFamily); - family->addFont(minikinFont.get()); + MinikinAutoUnref family(new FontFamily( + std::vector{ Font(minikinFont.get(), FontStyle()) })); android::AutoMutex _l(gMinikinLock); - family->getCoverage(); - EXPECT_EQ(testCase.hasVSTable, family->hasVSTable()); } } diff --git a/engine/src/flutter/tests/util/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp index 0c7b2ba032c..e29a2fe5344 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.cpp +++ b/engine/src/flutter/tests/util/FontTestUtils.cpp @@ -48,16 +48,7 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { } } - xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); - FontFamily* family; - if (lang == nullptr) { - family = new FontFamily(variant); - } else { - uint32_t langId = FontStyle::registerLanguageList( - std::string((const char*)lang, xmlStrlen(lang))); - family = new FontFamily(langId, variant); - } - + std::vector fonts; for (xmlNode* fontNode = familyNode->children; fontNode; fontNode = fontNode->next) { if (xmlStrcmp(fontNode->name, (const xmlChar*)"font") != 0) { continue; @@ -80,13 +71,23 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { if (index == nullptr) { MinikinAutoUnref minikinFont(new MinikinFontForTest(fontPath)); - family->addFont(minikinFont.get(), FontStyle(weight, italic)); + fonts.push_back(Font(minikinFont.get(), FontStyle(weight, italic))); } else { MinikinAutoUnref minikinFont(new MinikinFontForTest(fontPath, atoi((const char*)index))); - family->addFont(minikinFont.get(), FontStyle(weight, italic)); + fonts.push_back(Font(minikinFont.get(), FontStyle(weight, italic))); } } + + xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); + FontFamily* family; + if (lang == nullptr) { + family = new FontFamily(variant, std::move(fonts)); + } else { + uint32_t langId = FontStyle::registerLanguageList( + std::string((const char*)lang, xmlStrlen(lang))); + family = new FontFamily(langId, variant, std::move(fonts)); + } families.push_back(family); } xmlFreeDoc(doc); From 77a29ed5ecd924af9afb9cbf1531db2f39a46116 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 22 Nov 2016 18:10:57 +0900 Subject: [PATCH 227/364] Introduce createCollectionWithVariation. This is 2nd attempt of I08e9b74192f8af1d045f1276498fa4e60d73863e. The original CL was reverted due to conflicting with another CL submitted before. Here is the original commit message of reverted change. This lays the groundwork for variation settings support. Since we should regard different variations of a font as different fonts, we need to create new typefaces. To reuse the same instance of MinikinFont, as much as possible, FontFamily::createFamilyWithVariation now reuses an existence instance, while incrementing the reference count. Test: minikin_tests Bug: 33062398 Change-Id: Ib25bf1bb5a5191e15a6523954146521464c91906 --- .../flutter/include/minikin/FontCollection.h | 8 ++ .../src/flutter/include/minikin/FontFamily.h | 17 +++- .../src/flutter/include/minikin/MinikinFont.h | 4 + .../src/flutter/libs/minikin/AnalyzeStyle.cpp | 43 ----------- engine/src/flutter/libs/minikin/Android.mk | 2 +- .../flutter/libs/minikin/FontCollection.cpp | 39 ++++++++++ .../src/flutter/libs/minikin/FontFamily.cpp | 67 ++++++++++++++-- engine/src/flutter/libs/minikin/FontUtils.cpp | 77 +++++++++++++++++++ .../minikin/FontUtils.h} | 9 ++- engine/src/flutter/tests/unittest/Android.mk | 1 + .../tests/unittest/FontCollectionTest.cpp | 72 +++++++++++++++++ .../flutter/tests/unittest/FontFamilyTest.cpp | 63 +++++++++++++++ .../flutter/tests/util/MinikinFontForTest.cpp | 9 ++- .../flutter/tests/util/MinikinFontForTest.h | 9 ++- 14 files changed, 365 insertions(+), 55 deletions(-) delete mode 100644 engine/src/flutter/libs/minikin/AnalyzeStyle.cpp create mode 100644 engine/src/flutter/libs/minikin/FontUtils.cpp rename engine/src/flutter/{include/minikin/AnalyzeStyle.h => libs/minikin/FontUtils.h} (75%) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index c9c8520be6b..42499a04699 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -18,6 +18,7 @@ #define MINIKIN_FONT_COLLECTION_H #include +#include #include #include @@ -51,6 +52,10 @@ public: // Get base font with fakery information (fake bold could affect metrics) FakedFont baseFontFaked(FontStyle style); + // Creates new FontCollection based on this collection while applying font variations. Returns + // nullptr if none of variations apply to this collection. + FontCollection* createCollectionWithVariation(const std::vector& variations); + uint32_t getId() const; private: @@ -96,6 +101,9 @@ private: // These are offsets into mInstanceVec, one range per page std::vector mRanges; + + // Set of supported axes in this collection. + std::unordered_set mSupportedAxes; }; } // namespace minikin diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 71a63840556..9ce8c6537c0 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -98,6 +99,8 @@ struct FakedFont { FontFakery fakery; }; +typedef uint32_t AxisTag; + struct Font { Font(MinikinFont* typeface, FontStyle style); Font(Font&& o); @@ -106,6 +109,7 @@ struct Font { MinikinFont* typeface; FontStyle style; + std::unordered_set supportedAxes; // TODO: remove this weird function. http://b/28119474 // MinikinFont requres mutex lock for destruction, but the mutex lock is not @@ -113,6 +117,12 @@ struct Font { static void clearElementsWithLock(std::vector* fonts); }; +struct FontVariation { + FontVariation(AxisTag axisTag, float value) : axisTag(axisTag), value(value) {} + AxisTag axisTag; + float value; +}; + class FontFamily : public MinikinRefCounted { public: explicit FontFamily(std::vector&& fonts); @@ -134,6 +144,7 @@ public: MinikinFont* getFont(size_t index) const { return mFonts[index].typeface; } FontStyle getStyle(size_t index) const { return mFonts[index].style; } bool isColorEmojiFamily() const; + const std::unordered_set& supportedAxes() const { return mSupportedAxes; } // Get Unicode coverage. const SparseBitSet& getCoverage() const { return mCoverage; } @@ -145,12 +156,16 @@ public: // Returns true if this font family has a variaion sequence table (cmap format 14 subtable). bool hasVSTable() const { return mHasVSTable; } + // Creates new FontFamily based on this family while applying font variations. Returns nullptr + // if none of variations apply to this family. + FontFamily* createFamilyWithVariation(const std::vector& variations) const; + private: void computeCoverage(); - uint32_t mLangId; int mVariant; std::vector mFonts; + std::unordered_set mSupportedAxes; SparseBitSet mCoverage; bool mHasVSTable; diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 353edd6566e..57b939788ac 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -126,6 +126,10 @@ public: return 0; } + virtual MinikinFont* createFontWithVariation(const std::vector&) const { + return nullptr; + } + static uint32_t MakeTag(char c1, char c2, char c3, char c4) { return ((uint32_t)c1 << 24) | ((uint32_t)c2 << 16) | ((uint32_t)c3 << 8) | (uint32_t)c4; diff --git a/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp b/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp deleted file mode 100644 index 333f008f7fd..00000000000 --- a/engine/src/flutter/libs/minikin/AnalyzeStyle.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2013 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 -#include - -#include - -namespace minikin { - -// should we have a single FontAnalyzer class this stuff lives in, to avoid dup? -static int32_t readU16(const uint8_t* data, size_t offset) { - return data[offset] << 8 | data[offset + 1]; -} - -bool analyzeStyle(const uint8_t* os2_data, size_t os2_size, int* weight, bool* italic) { - const size_t kUsWeightClassOffset = 4; - const size_t kFsSelectionOffset = 62; - const uint16_t kItalicFlag = (1 << 0); - if (os2_size < kFsSelectionOffset + 2) { - return false; - } - uint16_t weightClass = readU16(os2_data, kUsWeightClassOffset); - *weight = weightClass / 100; - uint16_t fsSelection = readU16(os2_data, kFsSelectionOffset); - *italic = (fsSelection & kItalicFlag) != 0; - return true; -} - -} // namespace minikin diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index d6c3df7f621..44abb885325 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -30,12 +30,12 @@ $(UNICODE_EMOJI_H): include $(CLEAR_VARS) minikin_src_files := \ - AnalyzeStyle.cpp \ CmapCoverage.cpp \ FontCollection.cpp \ FontFamily.cpp \ FontLanguage.cpp \ FontLanguageListCache.cpp \ + FontUtils.cpp \ GraphemeBreak.cpp \ HbFontCache.cpp \ Hyphenator.cpp \ diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 4688520699d..fbcf1d72b10 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -103,6 +103,9 @@ FontCollection::FontCollection(const vector& typefaces) : } mMaxChar = max(mMaxChar, coverage.length()); lastChar.push_back(coverage.nextSetBit(0)); + + const std::unordered_set& supportedAxes = family->supportedAxes(); + mSupportedAxes.insert(supportedAxes.begin(), supportedAxes.end()); } nTypefaces = mFamilies.size(); LOG_ALWAYS_FATAL_IF(nTypefaces == 0, @@ -461,6 +464,42 @@ FakedFont FontCollection::baseFontFaked(FontStyle style) { return mFamilies[0]->getClosestMatch(style); } +FontCollection* FontCollection::createCollectionWithVariation( + const std::vector& variations) { + if (variations.empty() || mSupportedAxes.empty()) { + return nullptr; + } + + bool hasSupportedAxis = false; + for (const FontVariation& variation : variations) { + if (mSupportedAxes.find(variation.axisTag) != mSupportedAxes.end()) { + hasSupportedAxis = true; + break; + } + } + if (!hasSupportedAxis) { + // None of variation axes are supported by this font collection. + return nullptr; + } + + std::vector families; + for (FontFamily* family : mFamilies) { + FontFamily* newFamily = family->createFamilyWithVariation(variations); + if (newFamily) { + families.push_back(newFamily); + } else { + family->Ref(); + families.push_back(family); + } + } + + FontCollection* result = new FontCollection(families); + for (FontFamily* family : families) { + family->Unref(); + } + return result; +} + uint32_t FontCollection::getId() const { return mId; } diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 619110db8e5..6d44bc395c1 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -28,10 +28,11 @@ #include "FontLanguage.h" #include "FontLanguageListCache.h" +#include "FontUtils.h" #include "HbFontCache.h" #include "MinikinInternal.h" -#include #include +#include #include #include @@ -66,19 +67,30 @@ uint32_t FontStyle::pack(int variant, int weight, bool italic) { Font::Font(MinikinFont* typeface, FontStyle style) : typeface(typeface), style(style) { - typeface->Ref(); + android::AutoMutex _l(gMinikinLock); + typeface->RefLocked(); + + const uint32_t fvarTag = MinikinFont::MakeTag('f', 'v', 'a', 'r'); + HbBlob fvarTable(getFontTable(typeface, fvarTag)); + if (fvarTable.size() == 0) { + return; + } + + analyzeAxes(fvarTable.get(), fvarTable.size(), &supportedAxes); } Font::Font(Font&& o) { typeface = o.typeface; style = o.style; o.typeface = nullptr; + supportedAxes = std::move(o.supportedAxes); } Font::Font(const Font& o) { typeface = o.typeface; typeface->Ref(); style = o.style; + supportedAxes = o.supportedAxes; } Font::~Font() { @@ -179,9 +191,10 @@ void FontFamily::computeCoverage() { } // TODO: Error check? CmapCoverage::getCoverage(mCoverage, cmapTable.get(), cmapTable.size(), &mHasVSTable); -#ifdef VERBOSE_DEBUG - ALOGD("font coverage length=%d, first ch=%x\n", mCoverage.length(), mCoverage.nextSetBit(0)); -#endif + + for (size_t i = 0; i < mFonts.size(); ++i) { + mSupportedAxes.insert(mFonts[i].supportedAxes.begin(), mFonts[i].supportedAxes.end()); + } } bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) const { @@ -201,4 +214,48 @@ bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) const return result; } +FontFamily* FontFamily::createFamilyWithVariation( + const std::vector& variations) const { + if (variations.empty() || mSupportedAxes.empty()) { + return nullptr; + } + + bool hasSupportedAxis = false; + for (const FontVariation& variation : variations) { + if (mSupportedAxes.find(variation.axisTag) != mSupportedAxes.end()) { + hasSupportedAxis = true; + break; + } + } + if (!hasSupportedAxis) { + // None of variation axes are suppored by this family. + return nullptr; + } + + std::vector fonts; + for (const Font& font : mFonts) { + bool supportedVariations = false; + if (!font.supportedAxes.empty()) { + for (const FontVariation& variation : variations) { + if (font.supportedAxes.find(variation.axisTag) != font.supportedAxes.end()) { + supportedVariations = true; + break; + } + } + } + MinikinFont* minikinFont = nullptr; + if (supportedVariations) { + minikinFont = font.typeface->createFontWithVariation(variations); + } + if (minikinFont == nullptr) { + minikinFont = font.typeface; + minikinFont->Ref(); + } + fonts.push_back(Font(minikinFont, font.style)); + minikinFont->Unref(); + } + + return new FontFamily(mLangId, mVariant, std::move(fonts)); +} + } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/FontUtils.cpp b/engine/src/flutter/libs/minikin/FontUtils.cpp new file mode 100644 index 00000000000..c5a32f82e85 --- /dev/null +++ b/engine/src/flutter/libs/minikin/FontUtils.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2017 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 +#include + +#include "FontUtils.h" + +namespace minikin { + +static uint16_t readU16(const uint8_t* data, size_t offset) { + return data[offset] << 8 | data[offset + 1]; +} + +static uint32_t readU32(const uint8_t* data, size_t offset) { + return ((uint32_t)data[offset]) << 24 | ((uint32_t)data[offset + 1]) << 16 | + ((uint32_t)data[offset + 2]) << 8 | ((uint32_t)data[offset + 3]); +} + +bool analyzeStyle(const uint8_t* os2_data, size_t os2_size, int* weight, bool* italic) { + const size_t kUsWeightClassOffset = 4; + const size_t kFsSelectionOffset = 62; + const uint16_t kItalicFlag = (1 << 0); + if (os2_size < kFsSelectionOffset + 2) { + return false; + } + uint16_t weightClass = readU16(os2_data, kUsWeightClassOffset); + *weight = weightClass / 100; + uint16_t fsSelection = readU16(os2_data, kFsSelectionOffset); + *italic = (fsSelection & kItalicFlag) != 0; + return true; +} + +void analyzeAxes(const uint8_t* fvar_data, size_t fvar_size, std::unordered_set* axes) { + const size_t kMajorVersionOffset = 0; + const size_t kMinorVersionOffset = 2; + const size_t kOffsetToAxesArrayOffset = 4; + const size_t kAxisCountOffset = 8; + const size_t kAxisSizeOffset = 10; + + axes->clear(); + + if (fvar_size < kAxisSizeOffset + 2) { + return; + } + const uint16_t majorVersion = readU16(fvar_data, kMajorVersionOffset); + const uint16_t minorVersion = readU16(fvar_data, kMinorVersionOffset); + const uint32_t axisOffset = readU16(fvar_data, kOffsetToAxesArrayOffset); + const uint32_t axisCount = readU16(fvar_data, kAxisCountOffset); + const uint32_t axisSize = readU16(fvar_data, kAxisSizeOffset); + + if (majorVersion != 1 || minorVersion != 0 || axisOffset != 0x10 || axisSize != 0x14) { + return; // Unsupported version. + } + if (fvar_size < axisOffset + axisOffset * axisCount) { + return; // Invalid table size. + } + for (uint32_t i = 0; i < axisCount; ++i) { + size_t axisRecordOffset = axisOffset + i * axisSize; + uint32_t tag = readU32(fvar_data, axisRecordOffset); + axes->insert(tag); + } +} +} // namespace minikin diff --git a/engine/src/flutter/include/minikin/AnalyzeStyle.h b/engine/src/flutter/libs/minikin/FontUtils.h similarity index 75% rename from engine/src/flutter/include/minikin/AnalyzeStyle.h rename to engine/src/flutter/libs/minikin/FontUtils.h index b4cd915108c..d26d5e42a08 100644 --- a/engine/src/flutter/include/minikin/AnalyzeStyle.h +++ b/engine/src/flutter/libs/minikin/FontUtils.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Android Open Source Project + * Copyright (C) 2017 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. @@ -14,12 +14,15 @@ * limitations under the License. */ -#ifndef MINIKIN_ANALYZE_STYLE_H -#define MINIKIN_ANALYZE_STYLE_H +#ifndef MINIKIN_FONT_UTILS_H +#define MINIKIN_FONT_UTILS_H + +#include namespace minikin { bool analyzeStyle(const uint8_t* os2_data, size_t os2_size, int* weight, bool* italic); +void analyzeAxes(const uint8_t* fvar_data, size_t fvar_size, std::unordered_set* axes); } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index cced5457373..7b3f60f8f9e 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -27,6 +27,7 @@ LOCAL_TEST_DATA := \ data/Italic.ttf \ data/Ja.ttf \ data/Ko.ttf \ + data/MultiAxis.ttf \ data/NoCmapFormat14.ttf \ data/NoGlyphFont.ttf \ data/Regular.ttf \ diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index c0b6b526b78..68fe582aa3f 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -121,4 +121,76 @@ TEST(FontCollectionTest, newEmojiTest) { EXPECT_FALSE(collection->hasVariationSelector(0x2642, 0xFE0F)); } +TEST(FontCollectionTest, createWithVariations) { + // This font has 'wdth' and 'wght' axes. + const char kMultiAxisFont[] = kTestFontDir "/MultiAxis.ttf"; + const char kNoAxisFont[] = kTestFontDir "/Regular.ttf"; + + MinikinAutoUnref multiAxisFont(new MinikinFontForTest(kMultiAxisFont)); + MinikinAutoUnref multiAxisFamily(new FontFamily( + std::vector({ Font(multiAxisFont.get(), FontStyle()) }))); + std::vector multiAxisFamilies({multiAxisFamily.get()}); + MinikinAutoUnref multiAxisFc(new FontCollection(multiAxisFamilies)); + + MinikinAutoUnref noAxisFont(new MinikinFontForTest(kNoAxisFont)); + MinikinAutoUnref noAxisFamily(new FontFamily( + std::vector({ Font(noAxisFont.get(), FontStyle()) }))); + std::vector noAxisFamilies({noAxisFamily.get()}); + MinikinAutoUnref noAxisFc(new FontCollection(noAxisFamilies)); + + { + // Do not ceate new instance if none of variations are specified. + EXPECT_EQ(nullptr, + multiAxisFc->createCollectionWithVariation(std::vector())); + EXPECT_EQ(nullptr, + noAxisFc->createCollectionWithVariation(std::vector())); + } + { + // New instance should be used for supported variation. + std::vector variations = { + { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f } + }; + MinikinAutoUnref newFc( + multiAxisFc->createCollectionWithVariation(variations)); + EXPECT_NE(nullptr, newFc.get()); + EXPECT_NE(multiAxisFc.get(), newFc.get()); + + EXPECT_EQ(nullptr, noAxisFc->createCollectionWithVariation(variations)); + } + { + // New instance should be used for supported variation (multiple variations case). + std::vector variations = { + { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, + { MinikinFont::MakeTag('w', 'g', 'h', 't'), 1.0f } + }; + MinikinAutoUnref newFc( + multiAxisFc->createCollectionWithVariation(variations)); + EXPECT_NE(nullptr, newFc.get()); + EXPECT_NE(multiAxisFc.get(), newFc.get()); + + EXPECT_EQ(nullptr, noAxisFc->createCollectionWithVariation(variations)); + } + { + // Do not ceate new instance if none of variations are supported. + std::vector variations = { + { MinikinFont::MakeTag('Z', 'Z', 'Z', 'Z'), 1.0f } + }; + EXPECT_EQ(nullptr, multiAxisFc->createCollectionWithVariation(variations)); + EXPECT_EQ(nullptr, noAxisFc->createCollectionWithVariation(variations)); + } + { + // At least one axis is supported, should create new instance. + std::vector variations = { + { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, + { MinikinFont::MakeTag('Z', 'Z', 'Z', 'Z'), 1.0f } + }; + MinikinAutoUnref newFc( + multiAxisFc->createCollectionWithVariation(variations)); + EXPECT_NE(nullptr, newFc.get()); + EXPECT_NE(multiAxisFc.get(), newFc.get()); + + EXPECT_EQ(nullptr, noAxisFc->createCollectionWithVariation(variations)); + } +} + } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index ddc36e45704..1655760bcfd 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -527,4 +527,67 @@ TEST_F(FontFamilyTest, hasVSTableTest) { } } +TEST_F(FontFamilyTest, createFamilyWithVariationTest) { + // This font has 'wdth' and 'wght' axes. + const char kMultiAxisFont[] = kTestFontDir "/MultiAxis.ttf"; + const char kNoAxisFont[] = kTestFontDir "/Regular.ttf"; + + MinikinAutoUnref multiAxisFont(new MinikinFontForTest(kMultiAxisFont)); + MinikinAutoUnref multiAxisFamily(new FontFamily( + std::vector({Font(multiAxisFont.get(), FontStyle())}))); + + MinikinAutoUnref noAxisFont(new MinikinFontForTest(kNoAxisFont)); + MinikinAutoUnref noAxisFamily(new FontFamily( + std::vector({Font(noAxisFont.get(), FontStyle())}))); + + { + // Do not ceate new instance if none of variations are specified. + EXPECT_EQ(nullptr, + multiAxisFamily->createFamilyWithVariation(std::vector())); + EXPECT_EQ(nullptr, + noAxisFamily->createFamilyWithVariation(std::vector())); + } + { + // New instance should be used for supported variation. + std::vector variations = {{MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f}}; + MinikinAutoUnref newFamily( + multiAxisFamily->createFamilyWithVariation(variations)); + EXPECT_NE(nullptr, newFamily.get()); + EXPECT_NE(multiAxisFamily.get(), newFamily.get()); + EXPECT_EQ(nullptr, noAxisFamily->createFamilyWithVariation(variations)); + } + { + // New instance should be used for supported variation. (multiple variations case) + std::vector variations = { + { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, + { MinikinFont::MakeTag('w', 'g', 'h', 't'), 1.0f } + }; + MinikinAutoUnref newFamily( + multiAxisFamily->createFamilyWithVariation(variations)); + EXPECT_NE(nullptr, newFamily.get()); + EXPECT_NE(multiAxisFamily.get(), newFamily.get()); + EXPECT_EQ(nullptr, noAxisFamily->createFamilyWithVariation(variations)); + } + { + // Do not ceate new instance if none of variations are supported. + std::vector variations = { + { MinikinFont::MakeTag('Z', 'Z', 'Z', 'Z'), 1.0f } + }; + EXPECT_EQ(nullptr, multiAxisFamily->createFamilyWithVariation(variations)); + EXPECT_EQ(nullptr, noAxisFamily->createFamilyWithVariation(variations)); + } + { + // At least one axis is supported, should create new instance. + std::vector variations = { + { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, + { MinikinFont::MakeTag('Z', 'Z', 'Z', 'Z'), 1.0f } + }; + MinikinAutoUnref newFamily( + multiAxisFamily->createFamilyWithVariation(variations)); + EXPECT_NE(nullptr, newFamily.get()); + EXPECT_NE(multiAxisFamily.get(), newFamily.get()); + EXPECT_EQ(nullptr, noAxisFamily->createFamilyWithVariation(variations)); + } +} + } // namespace minikin diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.cpp b/engine/src/flutter/tests/util/MinikinFontForTest.cpp index a4132e5178d..f191f07d6e9 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/util/MinikinFontForTest.cpp @@ -34,9 +34,11 @@ namespace minikin { static int uniqueId = 0; // TODO: make thread safe if necessary. -MinikinFontForTest::MinikinFontForTest(const std::string& font_path, int index) : +MinikinFontForTest::MinikinFontForTest(const std::string& font_path, int index, + const std::vector& variations) : MinikinFont(uniqueId++), mFontPath(font_path), + mVariations(variations), mFontIndex(index) { int fd = open(font_path.c_str(), O_RDONLY); LOG_ALWAYS_FATAL_IF(fd == -1); @@ -67,4 +69,9 @@ void MinikinFontForTest::GetBounds(MinikinRect* bounds, uint32_t /* glyph_id */, bounds->mBottom = 10.0f; } +MinikinFont* MinikinFontForTest::createFontWithVariation( + const std::vector& variations) const { + return new MinikinFontForTest(mFontPath, mFontIndex, variations); +} + } // namespace minikin diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.h b/engine/src/flutter/tests/util/MinikinFontForTest.h index ee0eadbe0c2..2a107036eda 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.h +++ b/engine/src/flutter/tests/util/MinikinFontForTest.h @@ -25,7 +25,10 @@ namespace minikin { class MinikinFontForTest : public MinikinFont { public: - MinikinFontForTest(const std::string& font_path, int index); + MinikinFontForTest(const std::string& font_path, int index, + const std::vector& variations); + MinikinFontForTest(const std::string& font_path, int index) + : MinikinFontForTest(font_path, index, std::vector()) {} MinikinFontForTest(const std::string& font_path) : MinikinFontForTest(font_path, 0) {} virtual ~MinikinFontForTest(); @@ -35,15 +38,19 @@ public: const MinikinPaint& paint) const; const std::string& fontPath() const { return mFontPath; } + const std::vector& variations() const { return mVariations; } + const void* GetFontData() const { return mFontData; } size_t GetFontSize() const { return mFontSize; } int GetFontIndex() const { return mFontIndex; } + MinikinFont* createFontWithVariation(const std::vector& variations) const; private: MinikinFontForTest() = delete; MinikinFontForTest(const MinikinFontForTest&) = delete; MinikinFontForTest& operator=(MinikinFontForTest&) = delete; const std::string mFontPath; + const std::vector mVariations; const int mFontIndex; void* mFontData; size_t mFontSize; From 3c71c47a6a9cb0c50cae13d08ae122c1e21c0d88 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 7 Feb 2017 15:52:25 +0900 Subject: [PATCH 228/364] Update the instruction to run tests. "adb sync data" pushes test data as well as test executables. Test: ran minikin_perftests Test: ran minikin_tests Change-Id: I08219f8abc4b59bd26d8f9155975b65b56a88b7b --- engine/src/flutter/tests/perftests/how_to_run.txt | 3 +-- engine/src/flutter/tests/unittest/how_to_run.txt | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/tests/perftests/how_to_run.txt b/engine/src/flutter/tests/perftests/how_to_run.txt index 3390522c2fd..f55a8ac4efd 100644 --- a/engine/src/flutter/tests/perftests/how_to_run.txt +++ b/engine/src/flutter/tests/perftests/how_to_run.txt @@ -1,4 +1,3 @@ mmm -j8 frameworks/minikin/tests/perftests && -adb push $OUT/data/benchmarktest/minikin_perftests/minikin_perftests \ - /data/benchmarktest/minikin_perftests/minikin_perftests && +adb sync data && adb shell /data/benchmarktest/minikin_perftests/minikin_perftests diff --git a/engine/src/flutter/tests/unittest/how_to_run.txt b/engine/src/flutter/tests/unittest/how_to_run.txt index e94c904becf..20aa5ab31ed 100644 --- a/engine/src/flutter/tests/unittest/how_to_run.txt +++ b/engine/src/flutter/tests/unittest/how_to_run.txt @@ -1,3 +1,3 @@ mmm -j8 frameworks/minikin/tests/unittest && -adb push $OUT/data/nativetest/minikin_tests /data/nativetest/ && +adb sync data && adb shell /data/nativetest/minikin_tests/minikin_tests From 655d2a760d8c8dad590739f237a26a654cabf745 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 2 Feb 2017 17:31:31 +0900 Subject: [PATCH 229/364] Introduce unittests for flag sequence. The Flag sequence is well handled by latest ICU. Just add unit tests for catching regression in future. Test: ran minikin_tests Change-Id: I78d5461de8ff4d002ca06fb5bb81fcd7bc45d95e --- .../tests/unittest/GraphemeBreakTests.cpp | 28 +++++++++++ .../tests/unittest/WordBreakerTests.cpp | 50 ++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp b/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp index d95fa31b1dc..29b1669bd41 100644 --- a/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp +++ b/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp @@ -115,6 +115,34 @@ TEST(GraphemeBreak, rules) { EXPECT_TRUE(IsBreak("U+4E00 | U+4E00")); // CJK ideographs EXPECT_TRUE(IsBreak("'a' | U+1F1FA U+1F1F8")); // Regional indicator pair (flag) EXPECT_TRUE(IsBreak("U+1F1FA U+1F1F8 | 'a'")); // Regional indicator pair (flag) + + // Extended rule for emoji tag sequence. + EXPECT_TRUE(IsBreak("'a' | U+1F3F4 'a'")); + EXPECT_TRUE(IsBreak("'a' U+1F3F4 | 'a'")); + + // Immediate tag_term after tag_base. + EXPECT_TRUE(IsBreak("'a' | U+1F3F4 U+E007F 'a'")); + EXPECT_FALSE(IsBreak("U+1F3F4 | U+E007F")); + EXPECT_TRUE(IsBreak("'a' U+1F3F4 U+E007F | 'a'")); + + // Flag sequence + // U+1F3F4 U+E0067 U+E0062 U+E0073 U+E0063 U+E0074 U+E007F is emoji tag sequence for the flag + // of Scotland. + // U+1F3F4 is WAVING BLACK FLAG. This can be a tag_base character. + // U+E0067 is TAG LATIN SMALL LETTER G. This can be a part of tag_spec. + // U+E0062 is TAG LATIN SMALL LETTER B. This can be a part of tag_spec. + // U+E0073 is TAG LATIN SMALL LETTER S. This can be a part of tag_spec. + // U+E0063 is TAG LATIN SMALL LETTER C. This can be a part of tag_spec. + // U+E0074 is TAG LATIN SMALL LETTER T. This can be a part of tag_spec. + // U+E007F is CANCEL TAG. This is a tag_term character. + EXPECT_TRUE(IsBreak("'a' | U+1F3F4 U+E0067 U+E0062 U+E0073 U+E0063 U+E0074 U+E007F")); + EXPECT_FALSE(IsBreak("U+1F3F4 | U+E0067 U+E0062 U+E0073 U+E0063 U+E0074 U+E007F")); + EXPECT_FALSE(IsBreak("U+1F3F4 U+E0067 | U+E0062 U+E0073 U+E0063 U+E0074 U+E007F")); + EXPECT_FALSE(IsBreak("U+1F3F4 U+E0067 U+E0062 | U+E0073 U+E0063 U+E0074 U+E007F")); + EXPECT_FALSE(IsBreak("U+1F3F4 U+E0067 U+E0062 U+E0073 | U+E0063 U+E0074 U+E007F")); + EXPECT_FALSE(IsBreak("U+1F3F4 U+E0067 U+E0062 U+E0073 U+E0063 | U+E0074 U+E007F")); + EXPECT_FALSE(IsBreak("U+1F3F4 U+E0067 U+E0062 U+E0073 U+E0063 U+E0074 | U+E007F")); + EXPECT_TRUE(IsBreak("U+1F3F4 U+E0067 U+E0062 U+E0073 U+E0063 U+E0074 U+E007F | 'a'")); } TEST(GraphemeBreak, tailoring) { diff --git a/engine/src/flutter/tests/unittest/WordBreakerTests.cpp b/engine/src/flutter/tests/unittest/WordBreakerTests.cpp index c3228aa74b3..dc46c19d24c 100644 --- a/engine/src/flutter/tests/unittest/WordBreakerTests.cpp +++ b/engine/src/flutter/tests/unittest/WordBreakerTests.cpp @@ -137,7 +137,7 @@ TEST_F(WordBreakerTest, emojiWithModifier) { breaker.setLocale(icu::Locale::getEnglish()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); - EXPECT_EQ(4, breaker.next()); // after man + type 6 fitzpatrick modifier + EXPECT_EQ(4, breaker.next()); // after boy + type 1-2 fitzpatrick modifier EXPECT_EQ(0, breaker.wordStart()); EXPECT_EQ(4, breaker.wordEnd()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end @@ -145,6 +145,54 @@ TEST_F(WordBreakerTest, emojiWithModifier) { EXPECT_EQ(8, breaker.wordEnd()); } +TEST_F(WordBreakerTest, flagsSequenceSingleFlag) { + const std::string kFlag = "U+1F3F4"; + const std::string flags = kFlag + " " + kFlag; + + const int kFlagLength = 2; + const size_t BUF_SIZE = kFlagLength * 2; + + uint16_t buf[BUF_SIZE]; + size_t size; + ParseUnicode(buf, BUF_SIZE, flags.c_str(), &size, nullptr); + + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, size); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(kFlagLength, breaker.next()); // end of the first flag + EXPECT_EQ(0, breaker.wordStart()); + EXPECT_EQ(kFlagLength, breaker.wordEnd()); + EXPECT_EQ(static_cast(size), breaker.next()); + EXPECT_EQ(kFlagLength, breaker.wordStart()); + EXPECT_EQ(kFlagLength * 2, breaker.wordEnd()); +} + +TEST_F(WordBreakerTest, flagsSequence) { + // U+1F3F4 U+E0067 U+E0062 U+E0073 U+E0063 U+E0074 U+E007F is emoji tag sequence for the flag + // of Scotland. + const std::string kFlagSequence = "U+1F3F4 U+E0067 U+E0062 U+E0073 U+E0063 U+E0074 U+E007F"; + const std::string flagSequence = kFlagSequence + " " + kFlagSequence; + + const int kFlagLength = 14; + const size_t BUF_SIZE = kFlagLength * 2; + + uint16_t buf[BUF_SIZE]; + size_t size; + ParseUnicode(buf, BUF_SIZE, flagSequence.c_str(), &size, nullptr); + + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, size); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(kFlagLength, breaker.next()); // end of the first flag sequence + EXPECT_EQ(0, breaker.wordStart()); + EXPECT_EQ(kFlagLength, breaker.wordEnd()); + EXPECT_EQ(static_cast(size), breaker.next()); + EXPECT_EQ(kFlagLength, breaker.wordStart()); + EXPECT_EQ(kFlagLength * 2, breaker.wordEnd()); +} + TEST_F(WordBreakerTest, punct) { uint16_t buf[] = {0x00A1, 0x00A1, 'h', 'e', 'l', 'l' ,'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '!'}; From 30b9f327d3554e3f48f0cd2e46b63a0fcd948606 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Mon, 13 Feb 2017 15:33:47 -0800 Subject: [PATCH 230/364] Add U+202F NARROW NO-BREAK SPACE to the sticky white list Mongolian fonts need to shape across U+202F NARROW NO-BREAK SPACE (NNBSP). But if the first font in the fallback chain supports NNBSP, it would break Mongolian shaping since the text would be broken into three font runs. By making NNBSP sticky, we make sure Mongolian text is kept in one font run and is shaped properly. See http://www.unicode.org/L2/L2017/17036-mongolian-suffix.pdf for background. The proposed character in the proposal was not accepted for encoding by the Unicode Techincal Committee, but the document explains in more detail why this change in needed. Bug: 34344220 Test: manual Change-Id: I344a63f383fa5485875603570025eac3c4eb2574 --- engine/src/flutter/libs/minikin/FontCollection.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index fbcf1d72b10..9d0e2c8b381 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -325,19 +325,21 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, return bestFamily; } -const uint32_t NBSP = 0xa0; -const uint32_t ZWJ = 0x200c; -const uint32_t ZWNJ = 0x200d; +const uint32_t NBSP = 0xA0; +const uint32_t ZWJ = 0x200C; +const uint32_t ZWNJ = 0x200D; const uint32_t HYPHEN = 0x2010; const uint32_t NB_HYPHEN = 0x2011; +const uint32_t NNBSP = 0x202F; const uint32_t FEMALE_SIGN = 0x2640; const uint32_t MALE_SIGN = 0x2642; const uint32_t STAFF_OF_AESCULAPIUS = 0x2695; // Characters where we want to continue using existing font run instead of // recomputing the best match in the fallback list. -static const uint32_t stickyWhitelist[] = { '!', ',', '-', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ, - HYPHEN, NB_HYPHEN, FEMALE_SIGN, MALE_SIGN, STAFF_OF_AESCULAPIUS }; +static const uint32_t stickyWhitelist[] = { + '!', ',', '-', '.', ':', ';', '?', NBSP, ZWJ, ZWNJ, + HYPHEN, NB_HYPHEN, NNBSP, FEMALE_SIGN, MALE_SIGN, STAFF_OF_AESCULAPIUS }; static bool isStickyWhitelisted(uint32_t c) { for (size_t i = 0; i < sizeof(stickyWhitelist) / sizeof(stickyWhitelist[0]); i++) { From 480ad4a314a075927a0177846b109effd629753e Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 7 Feb 2017 19:54:08 +0900 Subject: [PATCH 231/364] Pass region code to HarfBuzz. Keep the region code and pass it to HarfBuzz during doing layout. Test: minikin_tests Bug: 30746293 Change-Id: I7c908701ca677238f663c82c597f8615d190e055 --- .../src/flutter/libs/minikin/FontLanguage.cpp | 205 ++++++++++++++---- .../src/flutter/libs/minikin/FontLanguage.h | 30 ++- engine/src/flutter/libs/minikin/Layout.cpp | 3 +- .../flutter/tests/unittest/FontFamilyTest.cpp | 91 +++++++- 4 files changed, 261 insertions(+), 68 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontLanguage.cpp b/engine/src/flutter/libs/minikin/FontLanguage.cpp index c6ddda5ae9f..0897c06ea5d 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguage.cpp @@ -41,60 +41,169 @@ static bool isEmojiSubtag(const char* buf, size_t bufLen, const char* subtag, si buf[subtagLen] == '-' || buf[subtagLen] == '_'); } +// Pack the three letter code into 15 bits and stored to 16 bit integer. The highest bit is 0. +// For the region code, the letters must be all digits in three letter case, so the number of +// possible values are 10. For the language code, the letters must be all small alphabets, so the +// number of possible values are 26. Thus, 5 bits are sufficient for each case and we can pack the +// three letter language code or region code to 15 bits. +// +// In case of two letter code, use fullbit(0x1f) for the first letter instead. +static uint16_t packLanguageOrRegion(const char* c, size_t length, uint8_t twoLetterBase, + uint8_t threeLetterBase) { + if (length == 2) { + return 0x7c00u | // 0x1fu << 10 + (uint16_t)(c[0] - twoLetterBase) << 5 | + (uint16_t)(c[1] - twoLetterBase); + } else { + return ((uint16_t)(c[0] - threeLetterBase) << 10) | + (uint16_t)(c[1] - threeLetterBase) << 5 | + (uint16_t)(c[2] - threeLetterBase); + } +} + +static size_t unpackLanguageOrRegion(uint16_t in, char* out, uint8_t twoLetterBase, + uint8_t threeLetterBase) { + uint8_t first = (in >> 10) & 0x1f; + uint8_t second = (in >> 5) & 0x1f; + uint8_t third = in & 0x1f; + + if (first == 0x1f) { + out[0] = second + twoLetterBase; + out[1] = third + twoLetterBase; + return 2; + } else { + out[0] = first + threeLetterBase; + out[1] = second + threeLetterBase; + out[2] = third + threeLetterBase; + return 3; + } +} + +// Find the next '-' or '_' index from startOffset position. If not found, returns bufferLength. +static size_t nextDelimiterIndex(const char* buffer, size_t bufferLength, size_t startOffset) { + for (size_t i = startOffset; i < bufferLength; ++i) { + if (buffer[i] == '-' || buffer[i] == '_') { + return i; + } + } + return bufferLength; +} + +static inline bool isLowercase(char c) { + return 'a' <= c && c <= 'z'; +} + +static inline bool isUppercase(char c) { + return 'A' <= c && c <= 'Z'; +} + +static inline bool isDigit(char c) { + return '0' <= c && c <= '9'; +} + +// Returns true if the buffer is valid for language code. +static inline bool isValidLanguageCode(const char* buffer, size_t length) { + if (length != 2 && length != 3) return false; + if (!isLowercase(buffer[0])) return false; + if (!isLowercase(buffer[1])) return false; + if (length == 3 && !isLowercase(buffer[2])) return false; + return true; +} + +// Returns true if buffer is valid for script code. The length of buffer must be 4. +static inline bool isValidScriptCode(const char* buffer) { + return isUppercase(buffer[0]) && isLowercase(buffer[1]) && isLowercase(buffer[2]) && + isLowercase(buffer[3]); +} + +// Returns true if the buffer is valid for region code. +static inline bool isValidRegionCode(const char* buffer, size_t length) { + return (length == 2 && isUppercase(buffer[0]) && isUppercase(buffer[1])) || + (length == 3 && isDigit(buffer[0]) && isDigit(buffer[1]) && isDigit(buffer[2])); +} + // Parse BCP 47 language identifier into internal structure FontLanguage::FontLanguage(const char* buf, size_t length) : FontLanguage() { - size_t i; - for (i = 0; i < length; i++) { - char c = buf[i]; - if (c == '-' || c == '_') break; - } - if (i == 2 || i == 3) { // only accept two or three letter language code. - mLanguage = buf[0] | (buf[1] << 8) | ((i == 3) ? (buf[2] << 16) : 0); + size_t firstDelimiterPos = nextDelimiterIndex(buf, length, 0); + if (isValidLanguageCode(buf, firstDelimiterPos)) { + mLanguage = packLanguageOrRegion(buf, firstDelimiterPos, 'a', 'a'); } else { // We don't understand anything other than two-letter or three-letter // language codes, so we skip parsing the rest of the string. - mLanguage = 0ul; return; } - size_t next; - for (i++; i < length; i = next + 1) { - for (next = i; next < length; next++) { - char c = buf[next]; - if (c == '-' || c == '_') break; - } - if (next - i == 4 && 'A' <= buf[i] && buf[i] <= 'Z') { - mScript = SCRIPT_TAG(buf[i], buf[i + 1], buf[i + 2], buf[i + 3]); - } + if (firstDelimiterPos == length) { + mHbLanguage = hb_language_from_string(getString().c_str(), -1); + return; // Language code only. } - mSubScriptBits = scriptToSubScriptBits(mScript); - if (mScript == SCRIPT_TAG('Z', 's', 'y', 'e')) { - mEmojiStyle = EMSTYLE_EMOJI; - } else if (mScript == SCRIPT_TAG('Z', 's', 'y', 'm')) { - mEmojiStyle = EMSTYLE_TEXT; + size_t nextComponentStartPos = firstDelimiterPos + 1; + size_t nextDelimiterPos = nextDelimiterIndex(buf, length, nextComponentStartPos); + size_t componentLength = nextDelimiterPos - nextComponentStartPos; + + if (componentLength == 4) { + // Possibly script code. + const char* p = buf + nextComponentStartPos; + if (isValidScriptCode(p)) { + mScript = SCRIPT_TAG(p[0], p[1], p[2], p[3]); + mSubScriptBits = scriptToSubScriptBits(mScript); + } + + if (nextDelimiterPos == length) { + mHbLanguage = hb_language_from_string(getString().c_str(), -1); + mEmojiStyle = resolveEmojiStyle(buf, length, mScript); + return; // No region code. + } + + nextComponentStartPos = nextDelimiterPos + 1; + nextDelimiterPos = nextDelimiterIndex(buf, length, nextComponentStartPos); + componentLength = nextDelimiterPos - nextComponentStartPos; } + + if (componentLength == 2 || componentLength == 3) { + // Possibly region code. + const char* p = buf + nextComponentStartPos; + if (isValidRegionCode(p, componentLength)) { + mRegion = packLanguageOrRegion(p, componentLength, 'A', '0'); + } + } + + mHbLanguage = hb_language_from_string(getString().c_str(), -1); + mEmojiStyle = resolveEmojiStyle(buf, length, mScript); +} + +// static +FontLanguage::EmojiStyle FontLanguage::resolveEmojiStyle(const char* buf, size_t length, + uint32_t script) { + // First, lookup emoji subtag. // 10 is the length of "-u-em-text", which is the shortest emoji subtag, // unnecessary comparison can be avoided if total length is smaller than 10. const size_t kMinSubtagLength = 10; - if (length < kMinSubtagLength) { - return; + if (length >= kMinSubtagLength) { + static const char kPrefix[] = "-u-em-"; + const char *pos = std::search(buf, buf + length, kPrefix, kPrefix + strlen(kPrefix)); + if (pos != buf + length) { // found + pos += strlen(kPrefix); + const size_t remainingLength = length - (pos - buf); + if (isEmojiSubtag(pos, remainingLength, "emoji", 5)){ + return EMSTYLE_EMOJI; + } else if (isEmojiSubtag(pos, remainingLength, "text", 4)){ + return EMSTYLE_TEXT; + } else if (isEmojiSubtag(pos, remainingLength, "default", 7)){ + return EMSTYLE_DEFAULT; + } + } } - static const char kPrefix[] = "-u-em-"; - const char *pos = std::search(buf, buf + length, kPrefix, kPrefix + strlen(kPrefix)); - if (pos == buf + length) { - return; - } - pos += strlen(kPrefix); - const size_t remainingLength = length - (pos - buf); - if (isEmojiSubtag(pos, remainingLength, "emoji", 5)){ - mEmojiStyle = EMSTYLE_EMOJI; - } else if (isEmojiSubtag(pos, remainingLength, "text", 4)){ - mEmojiStyle = EMSTYLE_TEXT; - } else if (isEmojiSubtag(pos, remainingLength, "default", 7)){ - mEmojiStyle = EMSTYLE_DEFAULT; + // If no emoji subtag was provided, resolve the emoji style from script code. + if (script == SCRIPT_TAG('Z', 's', 'y', 'e')) { + return EMSTYLE_EMOJI; + } else if (script == SCRIPT_TAG('Z', 's', 'y', 'm')) { + return EMSTYLE_TEXT; } + + return EMSTYLE_EMPTY; } //static @@ -140,21 +249,21 @@ uint8_t FontLanguage::scriptToSubScriptBits(uint32_t script) { } std::string FontLanguage::getString() const { - if (mLanguage == 0ul) { + if (isUnsupported()) { return "und"; } char buf[16]; - size_t i = 0; - buf[i++] = mLanguage & 0xFF ; - buf[i++] = (mLanguage >> 8) & 0xFF; - char third_letter = (mLanguage >> 16) & 0xFF; - if (third_letter != 0) buf[i++] = third_letter; + size_t i = unpackLanguageOrRegion(mLanguage, buf, 'a', 'a'); if (mScript != 0) { - buf[i++] = '-'; - buf[i++] = (mScript >> 24) & 0xFFu; - buf[i++] = (mScript >> 16) & 0xFFu; - buf[i++] = (mScript >> 8) & 0xFFu; - buf[i++] = mScript & 0xFFu; + buf[i++] = '-'; + buf[i++] = (mScript >> 24) & 0xFFu; + buf[i++] = (mScript >> 16) & 0xFFu; + buf[i++] = (mScript >> 8) & 0xFFu; + buf[i++] = mScript & 0xFFu; + } + if (mRegion != INVALID_CODE) { + buf[i++] = '-'; + i += unpackLanguageOrRegion(mRegion, buf + i, 'A', '0'); } return std::string(buf, i); } diff --git a/engine/src/flutter/libs/minikin/FontLanguage.h b/engine/src/flutter/libs/minikin/FontLanguage.h index 1bebdfeeb91..6a50b1d4cc8 100644 --- a/engine/src/flutter/libs/minikin/FontLanguage.h +++ b/engine/src/flutter/libs/minikin/FontLanguage.h @@ -27,6 +27,10 @@ namespace minikin { // Due to the limits in font fallback score calculation, we can't use anything more than 12 // languages. const size_t FONT_LANGUAGES_LIMIT = 12; + +// The language or region code is encoded to 15 bits. +const uint16_t INVALID_CODE = 0x7fff; + class FontLanguages; // FontLanguage is a compact representation of a BCP 47 language tag. It @@ -43,7 +47,9 @@ public: // Default constructor creates the unsupported language. FontLanguage() : mScript(0ul), - mLanguage(0ul), + mLanguage(INVALID_CODE), + mRegion(INVALID_CODE), + mHbLanguage(HB_LANGUAGE_INVALID), mSubScriptBits(0ul), mEmojiStyle(EMSTYLE_EMPTY) {} @@ -52,15 +58,17 @@ public: bool operator==(const FontLanguage other) const { return !isUnsupported() && isEqualScript(other) && mLanguage == other.mLanguage && - mEmojiStyle == other.mEmojiStyle; + mRegion == other.mRegion && mEmojiStyle == other.mEmojiStyle; } bool operator!=(const FontLanguage other) const { return !(*this == other); } - bool isUnsupported() const { return mLanguage == 0ul; } + bool isUnsupported() const { return mLanguage == INVALID_CODE; } EmojiStyle getEmojiStyle() const { return mEmojiStyle; } + hb_language_t getHbLanguage() const { return mHbLanguage; } + bool isEqualScript(const FontLanguage& other) const; @@ -76,7 +84,8 @@ public: int calcScoreFor(const FontLanguages& supported) const; uint64_t getIdentifier() const { - return (uint64_t)mScript << 32 | (uint64_t)mEmojiStyle << 24 | (uint64_t)mLanguage; + return ((uint64_t)mLanguage << 49) | ((uint64_t)mScript << 17) | ((uint64_t)mRegion << 2) | + mEmojiStyle; } private: @@ -86,9 +95,16 @@ private: uint32_t mScript; // ISO 639-1 or ISO 639-2 compliant language code. - // The two or three letter language code is packed into 24 bit integer. + // The two- or three-letter language code is packed into a 15 bit integer. // mLanguage = 0 means the FontLanguage is unsupported. - uint32_t mLanguage; + uint16_t mLanguage; + + // ISO 3166-1 or UN M.49 compliant region code. The two-letter or three-digit region code is + // packed into a 15 bit integer. + uint16_t mRegion; + + // The language to be passed HarfBuzz shaper. + hb_language_t mHbLanguage; // For faster comparing, use 7 bits for specific scripts. static const uint8_t kBopomofoFlag = 1u; @@ -104,6 +120,8 @@ private: static uint8_t scriptToSubScriptBits(uint32_t script); + static EmojiStyle resolveEmojiStyle(const char* buf, size_t length, uint32_t script); + // Returns true if the provide subscript bits has the requested subscript bits. // Note that this function returns false if the requested subscript bits are empty. static bool supportsScript(uint8_t providedBits, uint8_t requestedBits); diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 98e9fdb07ba..117f3262363 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -811,8 +811,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t break; } } - hb_buffer_set_language(buffer, - hb_language_from_string(hbLanguage->getString().c_str(), -1)); + hb_buffer_set_language(buffer, hbLanguage->getHbLanguage()); } hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart); if (ctx->paint.hyphenEdit.hasHyphen() && srunend > srunstart) { diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 1655760bcfd..fb917500f07 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -41,6 +41,10 @@ static FontLanguage createFontLanguage(const std::string& input) { return FontLanguageListCache::getById(langId)[0]; } +static FontLanguage createFontLanguageWithoutICUSanitization(const std::string& input) { + return FontLanguage(input.c_str(), input.size()); +} + TEST_F(FontLanguageTest, basicTests) { FontLanguage defaultLang; FontLanguage emptyLang("", 0); @@ -74,19 +78,25 @@ TEST_F(FontLanguageTest, basicTests) { } TEST_F(FontLanguageTest, getStringTest) { - EXPECT_EQ("en-Latn", createFontLanguage("en").getString()); - EXPECT_EQ("en-Latn", createFontLanguage("en-Latn").getString()); + EXPECT_EQ("en-Latn-US", createFontLanguage("en").getString()); + EXPECT_EQ("en-Latn-US", createFontLanguage("en-Latn").getString()); // Capitalized language code or lowercased script should be normalized. - EXPECT_EQ("en-Latn", createFontLanguage("EN-LATN").getString()); - EXPECT_EQ("en-Latn", createFontLanguage("EN-latn").getString()); - EXPECT_EQ("en-Latn", createFontLanguage("en-latn").getString()); + EXPECT_EQ("en-Latn-US", createFontLanguage("EN-LATN").getString()); + EXPECT_EQ("en-Latn-US", createFontLanguage("EN-latn").getString()); + EXPECT_EQ("en-Latn-US", createFontLanguage("en-latn").getString()); // Invalid script should be kept. - EXPECT_EQ("en-Xyzt", createFontLanguage("en-xyzt").getString()); + EXPECT_EQ("en-Xyzt-US", createFontLanguage("en-xyzt").getString()); - EXPECT_EQ("en-Latn", createFontLanguage("en-Latn-US").getString()); - EXPECT_EQ("ja-Jpan", createFontLanguage("ja").getString()); + EXPECT_EQ("en-Latn-US", createFontLanguage("en-Latn-US").getString()); + EXPECT_EQ("ja-Jpan-JP", createFontLanguage("ja").getString()); + EXPECT_EQ("zh-Hant-TW", createFontLanguage("zh-TW").getString()); + EXPECT_EQ("zh-Hant-HK", createFontLanguage("zh-HK").getString()); + EXPECT_EQ("zh-Hant-MO", createFontLanguage("zh-MO").getString()); + EXPECT_EQ("zh-Hans-CN", createFontLanguage("zh").getString()); + EXPECT_EQ("zh-Hans-CN", createFontLanguage("zh-CN").getString()); + EXPECT_EQ("zh-Hans-SG", createFontLanguage("zh-SG").getString()); EXPECT_EQ("und", createFontLanguage("und").getString()); EXPECT_EQ("und", createFontLanguage("UND").getString()); EXPECT_EQ("und", createFontLanguage("Und").getString()); @@ -94,10 +104,44 @@ TEST_F(FontLanguageTest, getStringTest) { EXPECT_EQ("und-Zsye", createFontLanguage("Und-ZSYE").getString()); EXPECT_EQ("und-Zsye", createFontLanguage("Und-zsye").getString()); - EXPECT_EQ("de-Latn", createFontLanguage("de-1901").getString()); + EXPECT_EQ("de-Latn-DE", createFontLanguage("de-1901").getString()); + + EXPECT_EQ("es-Latn-419", createFontLanguage("es-Latn-419").getString()); + + // Emoji subtag is dropped from getString(). + EXPECT_EQ("es-Latn-419", createFontLanguage("es-419-u-em-emoji").getString()); + EXPECT_EQ("es-Latn-419", createFontLanguage("es-Latn-419-u-em-emoji").getString()); // This is not a necessary desired behavior, just known behavior. - EXPECT_EQ("en-Latn", createFontLanguage("und-Abcdefgh").getString()); + EXPECT_EQ("en-Latn-US", createFontLanguage("und-Abcdefgh").getString()); +} + +TEST_F(FontLanguageTest, testReconstruction) { + EXPECT_EQ("en", createFontLanguageWithoutICUSanitization("en").getString()); + EXPECT_EQ("fil", createFontLanguageWithoutICUSanitization("fil").getString()); + EXPECT_EQ("und", createFontLanguageWithoutICUSanitization("und").getString()); + + EXPECT_EQ("en-Latn", createFontLanguageWithoutICUSanitization("en-Latn").getString()); + EXPECT_EQ("fil-Taga", createFontLanguageWithoutICUSanitization("fil-Taga").getString()); + EXPECT_EQ("und-Zsye", createFontLanguageWithoutICUSanitization("und-Zsye").getString()); + + EXPECT_EQ("en-US", createFontLanguageWithoutICUSanitization("en-US").getString()); + EXPECT_EQ("fil-PH", createFontLanguageWithoutICUSanitization("fil-PH").getString()); + EXPECT_EQ("es-419", createFontLanguageWithoutICUSanitization("es-419").getString()); + + EXPECT_EQ("en-Latn-US", createFontLanguageWithoutICUSanitization("en-Latn-US").getString()); + EXPECT_EQ("fil-Taga-PH", createFontLanguageWithoutICUSanitization("fil-Taga-PH").getString()); + EXPECT_EQ("es-Latn-419", createFontLanguageWithoutICUSanitization("es-Latn-419").getString()); + + // Possible minimum/maximum values. + EXPECT_EQ("aa", createFontLanguageWithoutICUSanitization("aa").getString()); + EXPECT_EQ("zz", createFontLanguageWithoutICUSanitization("zz").getString()); + EXPECT_EQ("aa-Aaaa", createFontLanguageWithoutICUSanitization("aa-Aaaa").getString()); + EXPECT_EQ("zz-Zzzz", createFontLanguageWithoutICUSanitization("zz-Zzzz").getString()); + EXPECT_EQ("aaa-Aaaa-AA", createFontLanguageWithoutICUSanitization("aaa-Aaaa-AA").getString()); + EXPECT_EQ("zzz-Zzzz-ZZ", createFontLanguageWithoutICUSanitization("zzz-Zzzz-ZZ").getString()); + EXPECT_EQ("aaa-Aaaa-000", createFontLanguageWithoutICUSanitization("aaa-Aaaa-000").getString()); + EXPECT_EQ("zzz-Zzzz-999", createFontLanguageWithoutICUSanitization("zzz-Zzzz-999").getString()); } TEST_F(FontLanguageTest, ScriptEqualTest) { @@ -247,6 +291,7 @@ TEST_F(FontLanguagesTest, unsupportedLanguageTests) { TEST_F(FontLanguagesTest, repeatedLanguageTests) { FontLanguage english = createFontLanguage("en"); FontLanguage french = createFontLanguage("fr"); + FontLanguage canadianFrench = createFontLanguage("fr-CA"); FontLanguage englishInLatn = createFontLanguage("en-Latn"); ASSERT_TRUE(english == englishInLatn); @@ -254,11 +299,16 @@ TEST_F(FontLanguagesTest, repeatedLanguageTests) { EXPECT_EQ(1u, langs.size()); EXPECT_EQ(english, langs[0]); - // Country codes are ignored. - const FontLanguages& fr = createFontLanguages("fr,fr-CA,fr-FR"); + const FontLanguages& fr = createFontLanguages("fr,fr-FR,fr-Latn-FR"); EXPECT_EQ(1u, fr.size()); EXPECT_EQ(french, fr[0]); + // ICU appends FR to fr. The third language is dropped which is same as the first language. + const FontLanguages& fr2 = createFontLanguages("fr,fr-CA,fr-FR"); + EXPECT_EQ(2u, fr2.size()); + EXPECT_EQ(french, fr2[0]); + EXPECT_EQ(canadianFrench, fr2[1]); + // The order should be kept. const FontLanguages& langs2 = createFontLanguages("en,fr,en-Latn"); EXPECT_EQ(2u, langs2.size()); @@ -266,6 +316,17 @@ TEST_F(FontLanguagesTest, repeatedLanguageTests) { EXPECT_EQ(french, langs2[1]); } +TEST_F(FontLanguagesTest, identifierTest) { + EXPECT_EQ(createFontLanguage("en-Latn-US"), createFontLanguage("en-Latn-US")); + EXPECT_EQ(createFontLanguage("zh-Hans-CN"), createFontLanguage("zh-Hans-CN")); + EXPECT_EQ(createFontLanguage("en-Zsye-US"), createFontLanguage("en-Zsye-US")); + + EXPECT_NE(createFontLanguage("en-Latn-US"), createFontLanguage("en-Latn-GB")); + EXPECT_NE(createFontLanguage("en-Latn-US"), createFontLanguage("en-Zsye-US")); + EXPECT_NE(createFontLanguage("es-Latn-US"), createFontLanguage("en-Latn-US")); + EXPECT_NE(createFontLanguage("zh-Hant-HK"), createFontLanguage("zh-Hant-TW")); +} + TEST_F(FontLanguagesTest, undEmojiTests) { FontLanguage emoji = createFontLanguage("und-Zsye"); EXPECT_EQ(FontLanguage::EMSTYLE_EMOJI, emoji.getEmojiStyle()); @@ -299,9 +360,11 @@ TEST_F(FontLanguagesTest, subtagEmojiTest) { // Strings that contain the county. "und-US-u-em-emoji", "en-US-u-em-emoji", + "es-419-u-em-emoji", "und-Latn-US-u-em-emoji", "en-Zsym-US-u-em-emoji", "en-Zsye-US-u-em-emoji", + "es-Zsye-419-u-em-emoji", }; for (auto subtagEmojiString : subtagEmojiStrings) { @@ -331,9 +394,11 @@ TEST_F(FontLanguagesTest, subtagTextTest) { // Strings that contain the county. "und-US-u-em-text", "en-US-u-em-text", + "es-419-u-em-text", "und-Latn-US-u-em-text", "en-Zsym-US-u-em-text", "en-Zsye-US-u-em-text", + "es-Zsye-419-u-em-text", }; for (auto subtagTextString : subtagTextStrings) { @@ -363,8 +428,10 @@ TEST_F(FontLanguagesTest, subtagDefaultTest) { // Strings that contain the county. "en-US-u-em-default", "en-Latn-US-u-em-default", + "es-Latn-419-u-em-default", "en-Zsym-US-u-em-default", "en-Zsye-US-u-em-default", + "es-Zsye-419-u-em-default", }; for (auto subtagDefaultString : subtagDefaultStrings) { From 3fcf3634db6acb2aec0285dc51e2dba7926ed717 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Mon, 13 Feb 2017 18:32:44 +0900 Subject: [PATCH 232/364] Call hb_font_set_variation if font variations are provided. Test: None Change-Id: I203d9ba7e1a1fcfdb10cd6a711d9a35136cbddd6 --- engine/src/flutter/include/minikin/MinikinFont.h | 2 ++ engine/src/flutter/include/minikin/MinikinFontFreeType.h | 5 +++++ engine/src/flutter/libs/minikin/HbFontCache.cpp | 5 +++++ engine/src/flutter/sample/MinikinSkia.h | 5 ++++- engine/src/flutter/tests/util/MinikinFontForTest.h | 2 +- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 57b939788ac..64bab02a206 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -126,6 +126,8 @@ public: return 0; } + virtual const std::vector& GetAxes() const = 0; + virtual MinikinFont* createFontWithVariation(const std::vector&) const { return nullptr; } diff --git a/engine/src/flutter/include/minikin/MinikinFontFreeType.h b/engine/src/flutter/include/minikin/MinikinFontFreeType.h index 34c3fd92d4c..37333e5f379 100644 --- a/engine/src/flutter/include/minikin/MinikinFontFreeType.h +++ b/engine/src/flutter/include/minikin/MinikinFontFreeType.h @@ -50,6 +50,10 @@ public: const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); + const std::vector& GetAxes() const { + return mAxes; + } + // TODO: provide access to raw data, as an optimization. // Not a virtual method, as the protocol to access rendered @@ -63,6 +67,7 @@ public: private: FT_Face mTypeface; static int32_t sIdCounter; + std::vector mAxes; }; } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index bd59e8f626a..e871b4ef9b4 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -117,6 +117,11 @@ hb_font_t* getHbFontLocked(MinikinFont* minikinFont) { hb_font_set_scale(parent_font, upem, upem); font = hb_font_create_sub_font(parent_font); + std::vector variations; + for (const FontVariation& variation : minikinFont->GetAxes()) { + variations.push_back({variation.axisTag, variation.value}); + } + hb_font_set_variations(font, variations.data(), variations.size()); hb_font_destroy(parent_font); hb_face_destroy(face); fontCache->put(fontId, font); diff --git a/engine/src/flutter/sample/MinikinSkia.h b/engine/src/flutter/sample/MinikinSkia.h index d995f7d2798..8284f5d0f9a 100644 --- a/engine/src/flutter/sample/MinikinSkia.h +++ b/engine/src/flutter/sample/MinikinSkia.h @@ -26,12 +26,15 @@ public: const MinikinPaint& paint) const; const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); + const std::vector& GetAxes() const { + return mAxes; + } SkTypeface *GetSkTypeface(); private: sk_sp mTypeface; - + std::vector mAxes; }; } // namespace minikin diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.h b/engine/src/flutter/tests/util/MinikinFontForTest.h index 2a107036eda..1d0628319bb 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.h +++ b/engine/src/flutter/tests/util/MinikinFontForTest.h @@ -38,11 +38,11 @@ public: const MinikinPaint& paint) const; const std::string& fontPath() const { return mFontPath; } - const std::vector& variations() const { return mVariations; } const void* GetFontData() const { return mFontData; } size_t GetFontSize() const { return mFontSize; } int GetFontIndex() const { return mFontIndex; } + const std::vector& GetAxes() const { return mVariations; } MinikinFont* createFontWithVariation(const std::vector& variations) const; private: MinikinFontForTest() = delete; From 6308ea4c4b4652f061a646d164d5fdc941a25ba2 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 22 Feb 2017 18:48:18 -0800 Subject: [PATCH 233/364] Add exception for Bulgarian to mk_hyb_file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Bulgarian hyphenation patterns contain a line consisting of '0ь0' which has no practical effect on hyphenation. Add an exception in roundtrip testing to make sure we don't fail while comparing our tables with the input data. Test: make -j works and creates .hyb files for bg and cu Change-Id: Ia46b8a45fe522f5194d8105d31b34b0e27528cc9 --- engine/src/flutter/tools/mk_hyb_file.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/engine/src/flutter/tools/mk_hyb_file.py b/engine/src/flutter/tools/mk_hyb_file.py index 978c082b279..a9b8932c95f 100755 --- a/engine/src/flutter/tools/mk_hyb_file.py +++ b/engine/src/flutter/tools/mk_hyb_file.py @@ -539,6 +539,12 @@ def verify_hyb_file(hyb_fn, pat_fn, chr_fn, hyp_fn): patterns = [] exceptions = [] traverse_trie(0, '', trie_data, ch_map, pattern_data, patterns, exceptions) + + # EXCEPTION for Bulgarian (bg), which contains an ineffectual line of <0, U+044C, 0> + if u'\u044c' in patterns: + patterns.remove(u'\u044c') + patterns.append(u'0\u044c0') + assert verify_file_sorted(patterns, pat_fn), 'pattern table not verified' assert verify_file_sorted(exceptions, hyp_fn), 'exception table not verified' From a6198608722f8c2ce49f993adfab39398105c240 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Fri, 10 Feb 2017 14:52:05 +0900 Subject: [PATCH 234/364] Remove MinikinRefCounted and use shared_ptr instead Let's use shared_ptr since manual ref counting can be a bug-prone and using the global mutex inside destructor is not useful for some time. To remove raw pointer manipulation, needed to change Layout constructors. Layout is no longer copyable and need to pass FontCollection to constructor. Bug: 28119474 Test: minikin_tests passed Test: hwui_unit_tests passed Test: No performance regression in minikin_perftest. Change-Id: I8824593206ecba74cbc9731e298f045e1ae442a3 --- .../flutter/include/minikin/FontCollection.h | 48 +-- .../src/flutter/include/minikin/FontFamily.h | 30 +- engine/src/flutter/include/minikin/Layout.h | 37 +- .../src/flutter/include/minikin/LineBreaker.h | 4 +- .../src/flutter/include/minikin/MinikinFont.h | 9 +- .../include/minikin/MinikinRefCounted.h | 59 ---- engine/src/flutter/libs/minikin/Android.mk | 1 - .../flutter/libs/minikin/FontCollection.cpp | 85 ++--- .../src/flutter/libs/minikin/FontFamily.cpp | 63 ++-- .../src/flutter/libs/minikin/HbFontCache.cpp | 2 +- engine/src/flutter/libs/minikin/HbFontCache.h | 2 +- engine/src/flutter/libs/minikin/Layout.cpp | 53 ++- .../src/flutter/libs/minikin/LineBreaker.cpp | 2 +- .../src/flutter/libs/minikin/MinikinFont.cpp | 2 + .../flutter/libs/minikin/MinikinInternal.cpp | 2 +- .../flutter/libs/minikin/MinikinInternal.h | 2 +- .../libs/minikin/MinikinRefCounted.cpp | 35 -- engine/src/flutter/sample/MinikinSkia.cpp | 5 +- engine/src/flutter/sample/MinikinSkia.h | 4 +- engine/src/flutter/sample/example.cpp | 17 +- engine/src/flutter/sample/example_skia.cpp | 19 +- .../tests/perftests/FontCollection.cpp | 7 +- .../unittest/FontCollectionItemizeTest.cpp | 327 +++++++++--------- .../tests/unittest/FontCollectionTest.cpp | 40 +-- .../flutter/tests/unittest/FontFamilyTest.cpp | 35 +- .../tests/unittest/HbFontCacheTest.cpp | 10 +- .../src/flutter/tests/unittest/LayoutTest.cpp | 36 +- .../src/flutter/tests/util/FontTestUtils.cpp | 25 +- .../flutter/tests/util/MinikinFontForTest.cpp | 4 +- .../flutter/tests/util/MinikinFontForTest.h | 3 +- .../src/flutter/tests/util/UnicodeUtils.cpp | 11 + engine/src/flutter/tests/util/UnicodeUtils.h | 3 + 32 files changed, 443 insertions(+), 539 deletions(-) delete mode 100644 engine/src/flutter/include/minikin/MinikinRefCounted.h delete mode 100644 engine/src/flutter/libs/minikin/MinikinRefCounted.cpp diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 42499a04699..23645387997 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -17,20 +17,19 @@ #ifndef MINIKIN_FONT_COLLECTION_H #define MINIKIN_FONT_COLLECTION_H -#include +#include #include +#include -#include #include #include namespace minikin { -class FontCollection : public MinikinRefCounted { +class FontCollection { public: - explicit FontCollection(const std::vector& typefaces); - - ~FontCollection(); + explicit FontCollection(const std::vector>& typefaces); + explicit FontCollection(std::shared_ptr&& typeface); struct Run { FakedFont fakedFont; @@ -46,15 +45,13 @@ public: // selector pair, or invalid variation selector is passed. bool hasVariationSelector(uint32_t baseCodepoint, uint32_t variationSelector) const; - // Get the base font for the given style, useful for font-wide metrics. - MinikinFont* baseFont(FontStyle style); - // Get base font with fakery information (fake bold could affect metrics) FakedFont baseFontFaked(FontStyle style); // Creates new FontCollection based on this collection while applying font variations. Returns // nullptr if none of variations apply to this collection. - FontCollection* createCollectionWithVariation(const std::vector& variations); + std::shared_ptr + createCollectionWithVariation(const std::vector& variations); uint32_t getId() const; @@ -67,12 +64,17 @@ private: size_t end; }; - FontFamily* getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const; + // Initialize the FontCollection. + void init(const std::vector>& typefaces); + + const std::shared_ptr& getFamilyForChar(uint32_t ch, uint32_t vs, + uint32_t langListId, int variant) const; uint32_t calcFamilyScore(uint32_t ch, uint32_t vs, int variant, uint32_t langListId, - FontFamily* fontFamily) const; + const std::shared_ptr& fontFamily) const; - uint32_t calcCoverageScore(uint32_t ch, uint32_t vs, FontFamily* fontFamily) const; + uint32_t calcCoverageScore(uint32_t ch, uint32_t vs, + const std::shared_ptr& fontFamily) const; static uint32_t calcLanguageMatchingScore(uint32_t userLangListId, const FontFamily& fontFamily); @@ -88,19 +90,19 @@ private: // Highest UTF-32 code point that can be mapped uint32_t mMaxChar; - // This vector has ownership of the bitsets and typeface objects. + // This vector has pointers to the all font family instances in this collection. // This vector can't be empty. - std::vector mFamilies; + std::vector> mFamilies; - // This vector contains pointers into mInstances - // This vector can't be empty. - std::vector mFamilyVec; - - // This vector has pointers to the font family instance which has cmap 14 subtable. - std::vector mVSFamilyVec; - - // These are offsets into mInstanceVec, one range per page + // Following two vectors are pre-calculated tables for resolving coverage faster. + // For example, to iterate over all fonts which support Unicode code point U+XXYYZZ, + // iterate font families from mFamilyVec[mRanges[0xXXYY].start] to + // mFamilyVec[mRange[0xXXYY].end] instead of whole mFamilies. std::vector mRanges; + std::vector> mFamilyVec; + + // This vector has pointers to the font family instances which have cmap 14 subtables. + std::vector> mVSFamilyVec; // Set of supported axes in this collection. std::unordered_set mSupportedAxes; diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 9ce8c6537c0..c7018a6f8c0 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -17,14 +17,15 @@ #ifndef MINIKIN_FONT_FAMILY_H #define MINIKIN_FONT_FAMILY_H -#include +#include #include #include +#include + #include #include -#include #include namespace minikin { @@ -102,19 +103,17 @@ struct FakedFont { typedef uint32_t AxisTag; struct Font { - Font(MinikinFont* typeface, FontStyle style); + Font(const std::shared_ptr& typeface, FontStyle style); + Font(std::shared_ptr&& typeface, FontStyle style); Font(Font&& o); Font(const Font& o); - ~Font(); - MinikinFont* typeface; + std::shared_ptr typeface; FontStyle style; std::unordered_set supportedAxes; - // TODO: remove this weird function. http://b/28119474 - // MinikinFont requres mutex lock for destruction, but the mutex lock is not - // visible from outside of minikin library. - static void clearElementsWithLock(std::vector* fonts); +private: + void loadAxes(); }; struct FontVariation { @@ -123,7 +122,7 @@ struct FontVariation { float value; }; -class FontFamily : public MinikinRefCounted { +class FontFamily { public: explicit FontFamily(std::vector&& fonts); FontFamily(int variant, std::vector&& fonts); @@ -132,8 +131,8 @@ public: ~FontFamily(); // TODO: Good to expose FontUtil.h. - static bool analyzeStyle(MinikinFont* typeface, int* weight, bool* italic); - + static bool analyzeStyle(const std::shared_ptr& typeface, int* weight, + bool* italic); FakedFont getClosestMatch(FontStyle style) const; uint32_t langId() const { return mLangId; } @@ -141,7 +140,9 @@ public: // API's for enumerating the fonts in a family. These don't guarantee any particular order size_t getNumFonts() const { return mFonts.size(); } - MinikinFont* getFont(size_t index) const { return mFonts[index].typeface; } + const std::shared_ptr& getFont(size_t index) const { + return mFonts[index].typeface; + } FontStyle getStyle(size_t index) const { return mFonts[index].style; } bool isColorEmojiFamily() const; const std::unordered_set& supportedAxes() const { return mSupportedAxes; } @@ -158,7 +159,8 @@ public: // Creates new FontFamily based on this family while applying font variations. Returns nullptr // if none of variations apply to this family. - FontFamily* createFamilyWithVariation(const std::vector& variations) const; + std::shared_ptr createFamilyWithVariation( + const std::vector& variations) const; private: void computeCoverage(); diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 625e05c433c..e9849c382c3 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -19,6 +19,7 @@ #include +#include #include #include @@ -71,37 +72,34 @@ enum { // Lifecycle and threading assumptions for Layout: // The object is assumed to be owned by a single thread; multiple threads // may not mutate it at the same time. -// The lifetime of the FontCollection set through setFontCollection must -// extend through the lifetime of the Layout object. class Layout { public: - Layout() : mGlyphs(), mAdvances(), mCollection(0), mFaces(), mAdvance(0), mBounds() { + Layout(const std::shared_ptr& collection) + : mGlyphs(), mAdvances(), mCollection(collection), mFaces(), mAdvance(0), mBounds() { mBounds.setEmpty(); } - // Clears layout, ready to be used again - void reset(); + Layout(Layout&& layout) = default; + + // Forbid copying and assignment. + Layout(const Layout&) = delete; + void operator=(const Layout&) = delete; void dump() const; - void setFontCollection(const FontCollection* collection); void doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint); static float measureText(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint, - const FontCollection* collection, float* advances); + const std::shared_ptr& collection, float* advances); void draw(minikin::Bitmap*, int x0, int y0, float size) const; - // Deprecated. Nont needed. Remove when callers are removed. - static void init(); - // public accessors size_t nGlyphs() const; - // Does not bump reference; ownership is still layout - MinikinFont *getFont(int i) const; + const MinikinFont* getFont(int i) const; FontFakery getFakery(int i) const; unsigned int getGlyphId(int i) const; float getX(int i) const; @@ -117,7 +115,7 @@ public: // start and count are the parameters to doLayout float getCharAdvance(size_t i) const { return mAdvances[i]; } - void getBounds(MinikinRect* rect); + void getBounds(MinikinRect* rect) const; // Purge all caches, useful in low memory conditions static void purgeCaches(); @@ -126,19 +124,22 @@ private: friend class LayoutCacheKey; // Find a face in the mFaces vector, or create a new entry - int findFace(FakedFont face, LayoutContext* ctx); + int findFace(const FakedFont& face, LayoutContext* ctx); + + // Clears layout, ready to be used again + void reset(); // Lay out a single bidi run // When layout is not null, layout info will be stored in the object. // When advances is not null, measurement results will be stored in the array. static float doLayoutRunCached(const uint16_t* buf, size_t runStart, size_t runLength, size_t bufSize, bool isRtl, LayoutContext* ctx, size_t dstStart, - const FontCollection* collection, Layout* layout, float* advances); + const std::shared_ptr& collection, Layout* layout, float* advances); // Lay out a single word static float doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - bool isRtl, LayoutContext* ctx, size_t bufStart, const FontCollection* collection, - Layout* layout, float* advances); + bool isRtl, LayoutContext* ctx, size_t bufStart, + const std::shared_ptr& collection, Layout* layout, float* advances); // Lay out a single bidi run void doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, @@ -150,7 +151,7 @@ private: std::vector mGlyphs; std::vector mAdvances; - const FontCollection* mCollection; + std::shared_ptr mCollection; std::vector mFaces; float mAdvance; MinikinRect mBounds; diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index 75e54b05f1b..e93953666be 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -159,8 +159,8 @@ class LineBreaker { // Minikin to do the shaping of the strings. The main thing that would need to be changed // is having some kind of callback (or virtual class, or maybe even template), which could // easily be instantiated with Minikin's Layout. Future work for when needed. - float addStyleRun(MinikinPaint* paint, const FontCollection* typeface, FontStyle style, - size_t start, size_t end, bool isRtl); + float addStyleRun(MinikinPaint* paint, const std::shared_ptr& typeface, + FontStyle style, size_t start, size_t end, bool isRtl); void addReplacement(size_t start, size_t end, float width); diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 64bab02a206..1d5ebb774a8 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -18,8 +18,8 @@ #define MINIKIN_FONT_H #include +#include -#include #include // An abstraction for platform fonts, allowing Minikin to be used with @@ -45,7 +45,7 @@ class MinikinFont; // Possibly move into own .h file? // Note: if you add a field here, either add it to LayoutCacheKey or to skipCache() struct MinikinPaint { - MinikinPaint() : font(0), size(0), scaleX(0), skewX(0), letterSpacing(0), wordSpacing(0), + MinikinPaint() : font(nullptr), size(0), scaleX(0), skewX(0), letterSpacing(0), wordSpacing(0), paintFlags(0), fakery(), hyphenEdit(), fontFeatureSettings() { } bool skipCache() const { @@ -98,7 +98,7 @@ class MinikinFontFreeType; // Callback for freeing data typedef void (*MinikinDestroyFunc) (void* data); -class MinikinFont : public MinikinRefCounted { +class MinikinFont { public: explicit MinikinFont(int32_t uniqueId) : mUniqueId(uniqueId) {} @@ -128,7 +128,8 @@ public: virtual const std::vector& GetAxes() const = 0; - virtual MinikinFont* createFontWithVariation(const std::vector&) const { + virtual std::shared_ptr createFontWithVariation( + const std::vector&) const { return nullptr; } diff --git a/engine/src/flutter/include/minikin/MinikinRefCounted.h b/engine/src/flutter/include/minikin/MinikinRefCounted.h deleted file mode 100644 index 960b6cc46da..00000000000 --- a/engine/src/flutter/include/minikin/MinikinRefCounted.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2014 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. - */ - -// Base class for reference counted objects in Minikin - -#ifndef MINIKIN_REF_COUNTED_H -#define MINIKIN_REF_COUNTED_H - -namespace minikin { - -class MinikinRefCounted { -public: - void RefLocked() { mRefcount_++; } - void UnrefLocked() { if (--mRefcount_ == 0) { delete this; } } - - // These refcount operations take the global lock. - void Ref(); - void Unref(); - - MinikinRefCounted() : mRefcount_(1) { } - - virtual ~MinikinRefCounted() { }; -private: - int mRefcount_; -}; - -// An RAII container for reference counted objects. -// Note: this is only suitable for clients which are _not_ holding the global lock. -template -class MinikinAutoUnref { -public: - explicit MinikinAutoUnref(T* obj) : mObj(obj) { - } - ~MinikinAutoUnref() { - mObj->Unref(); - } - T& operator*() const { return *mObj; } - T* operator->() const { return mObj; } - T* get() const { return mObj; } -private: - T* mObj; -}; - -} // namespace minikin - -#endif // MINIKIN_REF_COUNTED_H diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 44abb885325..603638e754d 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -44,7 +44,6 @@ minikin_src_files := \ LineBreaker.cpp \ Measurement.cpp \ MinikinInternal.cpp \ - MinikinRefCounted.cpp \ MinikinFont.cpp \ MinikinFontFreeType.cpp \ SparseBitSet.cpp \ diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 9d0e2c8b381..c351c3a58dc 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -79,8 +79,18 @@ static bool isEmojiStyleVSBase(uint32_t cp) { uint32_t FontCollection::sNextId = 0; -FontCollection::FontCollection(const vector& typefaces) : +FontCollection::FontCollection(std::shared_ptr&& typeface) : mMaxChar(0) { + std::vector> typefaces; + typefaces.push_back(typeface); + init(typefaces); +} + +FontCollection::FontCollection(const vector>& typefaces) : mMaxChar(0) { + init(typefaces); +} + +void FontCollection::init(const vector>& typefaces) { android::AutoMutex _l(gMinikinLock); mId = sNextId++; vector lastChar; @@ -90,12 +100,10 @@ FontCollection::FontCollection(const vector& typefaces) : #endif const FontStyle defaultStyle; for (size_t i = 0; i < nTypefaces; i++) { - FontFamily* family = typefaces[i]; - MinikinFont* typeface = family->getClosestMatch(defaultStyle).font; - if (typeface == NULL) { + const std::shared_ptr& family = typefaces[i]; + if (family->getClosestMatch(defaultStyle).font == nullptr) { continue; } - family->RefLocked(); const SparseBitSet& coverage = family->getCoverage(); mFamilies.push_back(family); // emplace_back would be better if (family->hasVSTable()) { @@ -126,7 +134,7 @@ FontCollection::FontCollection(const vector& typefaces) : range->start = offset; for (size_t j = 0; j < nTypefaces; j++) { if (lastChar[j] < (i + 1) << kLogCharsPerPage) { - FontFamily* family = mFamilies[j]; + const std::shared_ptr& family = mFamilies[j]; mFamilyVec.push_back(family); offset++; uint32_t nextChar = family->getCoverage().nextSetBit((i + 1) << kLogCharsPerPage); @@ -140,12 +148,6 @@ FontCollection::FontCollection(const vector& typefaces) : } } -FontCollection::~FontCollection() { - for (size_t i = 0; i < mFamilies.size(); i++) { - mFamilies[i]->UnrefLocked(); - } -} - // Special scores for the font fallback. const uint32_t kUnsupportedFontScore = 0; const uint32_t kFirstFontScore = UINT32_MAX; @@ -167,7 +169,7 @@ const uint32_t kFirstFontScore = UINT32_MAX; // - kFirstFontScore: When the font is the first font family in the collection and it supports the // given character or variation sequence. uint32_t FontCollection::calcFamilyScore(uint32_t ch, uint32_t vs, int variant, uint32_t langListId, - FontFamily* fontFamily) const { + const std::shared_ptr& fontFamily) const { const uint32_t coverageScore = calcCoverageScore(ch, vs, fontFamily); if (coverageScore == kFirstFontScore || coverageScore == kUnsupportedFontScore) { @@ -194,7 +196,8 @@ uint32_t FontCollection::calcFamilyScore(uint32_t ch, uint32_t vs, int variant, // - Returns 2 if the vs is a text variation selector (U+FE0E) and if the font is not an emoji font. // - Returns 1 if the variation selector is not specified or if the font family only supports the // variation sequence's base character. -uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, FontFamily* fontFamily) const { +uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, + const std::shared_ptr& fontFamily) const { const bool hasVSGlyph = (vs != 0) && fontFamily->hasGlyph(ch, vs); if (!hasVSGlyph && !fontFamily->getCoverage().get(ch)) { // The font doesn't support either variation sequence or even the base character. @@ -277,13 +280,13 @@ uint32_t FontCollection::calcVariantMatchingScore(int variant, const FontFamily& // 2. Calculate a score for the font family. See comments in calcFamilyScore for the detail. // 3. Highest score wins, with ties resolved to the first font. // This method never returns nullptr. -FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, +const std::shared_ptr& FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, uint32_t langListId, int variant) const { if (ch >= mMaxChar) { return mFamilies[0]; } - const std::vector& familyVec = (vs == 0) ? mFamilyVec : mFamilies; + const std::vector>& familyVec = (vs == 0) ? mFamilyVec : mFamilies; Range range = mRanges[ch >> kLogCharsPerPage]; if (vs != 0) { @@ -293,10 +296,10 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, #ifdef VERBOSE_DEBUG ALOGD("querying range %zd:%zd\n", range.start, range.end); #endif - FontFamily* bestFamily = nullptr; + int bestFamilyIndex = -1; uint32_t bestScore = kUnsupportedFontScore; for (size_t i = range.start; i < range.end; i++) { - FontFamily* family = familyVec[i]; + const std::shared_ptr& family = familyVec[i]; const uint32_t score = calcFamilyScore(ch, vs, variant, langListId, family); if (score == kFirstFontScore) { // If the first font family supports the given character or variation sequence, always @@ -305,10 +308,10 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, } if (score > bestScore) { bestScore = score; - bestFamily = family; + bestFamilyIndex = i; } } - if (bestFamily == nullptr) { + if (bestFamilyIndex == -1) { UErrorCode errorCode = U_ZERO_ERROR; const UNormalizer2* normalizer = unorm2_getNFDInstance(&errorCode); if (U_SUCCESS(errorCode)) { @@ -320,9 +323,9 @@ FontFamily* FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, return getFamilyForChar(ch, vs, langListId, variant); } } - bestFamily = mFamilies[0]; + return mFamilies[0]; } - return bestFamily; + return familyVec[bestFamilyIndex]; } const uint32_t NBSP = 0xA0; @@ -375,7 +378,7 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, if (isEmojiStyleVSBase(baseCodepoint) && variationSelector == TEXT_STYLE_VS) { for (size_t i = 0; i < mFamilies.size(); ++i) { if (!mFamilies[i]->isColorEmojiFamily() && variationSelector == TEXT_STYLE_VS && - mFamilies[i]->hasGlyph(baseCodepoint, 0)) { + mFamilies[i]->hasGlyph(baseCodepoint, 0)) { return true; } } @@ -388,7 +391,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty vector* result) const { const uint32_t langListId = style.getLanguageListId(); int variant = style.getVariant(); - FontFamily* lastFamily = NULL; + const FontFamily* lastFamily = nullptr; Run* run = NULL; if (string_size == 0) { @@ -425,9 +428,9 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } if (!shouldContinueRun) { - FontFamily* family = getFamilyForChar(ch, isVariationSelector(nextCh) ? nextCh : 0, - langListId, variant); - if (utf16Pos == 0 || family != lastFamily) { + const std::shared_ptr& family = getFamilyForChar( + ch, isVariationSelector(nextCh) ? nextCh : 0, langListId, variant); + if (utf16Pos == 0 || family.get() != lastFamily) { size_t start = utf16Pos; // Workaround for combining marks and emoji modifiers until we implement // per-cluster font selection: if a combining mark or an emoji modifier is found in @@ -437,7 +440,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty if (utf16Pos != 0 && ((U_GET_GC_MASK(ch) & U_GC_M_MASK) != 0 || (isEmojiModifier(ch) && isEmojiBase(prevCh))) && - family && family->getCoverage().get(prevCh)) { + family != nullptr && family->getCoverage().get(prevCh)) { const size_t prevChLength = U16_LENGTH(prevCh); run->end -= prevChLength; if (run->start == run->end) { @@ -445,12 +448,9 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } start -= prevChLength; } - Run dummy; - result->push_back(dummy); + result->push_back({family->getClosestMatch(style), static_cast(start), 0}); run = &result->back(); - run->fakedFont = family->getClosestMatch(style); - lastFamily = family; - run->start = start; + lastFamily = family.get(); } } prevCh = ch; @@ -458,15 +458,11 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty } while (nextCh != kEndOfString); } -MinikinFont* FontCollection::baseFont(FontStyle style) { - return baseFontFaked(style).font; -} - FakedFont FontCollection::baseFontFaked(FontStyle style) { return mFamilies[0]->getClosestMatch(style); } -FontCollection* FontCollection::createCollectionWithVariation( +std::shared_ptr FontCollection::createCollectionWithVariation( const std::vector& variations) { if (variations.empty() || mSupportedAxes.empty()) { return nullptr; @@ -484,22 +480,17 @@ FontCollection* FontCollection::createCollectionWithVariation( return nullptr; } - std::vector families; - for (FontFamily* family : mFamilies) { - FontFamily* newFamily = family->createFamilyWithVariation(variations); + std::vector > families; + for (const std::shared_ptr& family : mFamilies) { + std::shared_ptr newFamily = family->createFamilyWithVariation(variations); if (newFamily) { families.push_back(newFamily); } else { - family->Ref(); families.push_back(family); } } - FontCollection* result = new FontCollection(families); - for (FontFamily* family : families) { - family->Unref(); - } - return result; + return std::shared_ptr(new FontCollection(families)); } uint32_t FontCollection::getId() const { diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 6d44bc395c1..d0a0138ef2d 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -65,13 +65,20 @@ uint32_t FontStyle::pack(int variant, int weight, bool italic) { return (weight & kWeightMask) | (italic ? kItalicMask : 0) | (variant << kVariantShift); } -Font::Font(MinikinFont* typeface, FontStyle style) +Font::Font(const std::shared_ptr& typeface, FontStyle style) : typeface(typeface), style(style) { - android::AutoMutex _l(gMinikinLock); - typeface->RefLocked(); + loadAxes(); +} +Font::Font(std::shared_ptr&& typeface, FontStyle style) + : typeface(typeface), style(style) { + loadAxes(); +} + +void Font::loadAxes() { + android::AutoMutex _l(gMinikinLock); const uint32_t fvarTag = MinikinFont::MakeTag('f', 'v', 'a', 'r'); - HbBlob fvarTable(getFontTable(typeface, fvarTag)); + HbBlob fvarTable(getFontTable(typeface.get(), fvarTag)); if (fvarTable.size() == 0) { return; } @@ -80,7 +87,7 @@ Font::Font(MinikinFont* typeface, FontStyle style) } Font::Font(Font&& o) { - typeface = o.typeface; + typeface = std::move(o.typeface); style = o.style; o.typeface = nullptr; supportedAxes = std::move(o.supportedAxes); @@ -88,23 +95,11 @@ Font::Font(Font&& o) { Font::Font(const Font& o) { typeface = o.typeface; - typeface->Ref(); style = o.style; supportedAxes = o.supportedAxes; } -Font::~Font() { - if (typeface == nullptr) { - return; - } - typeface->UnrefLocked(); -} - -void Font::clearElementsWithLock(std::vector* fonts) { - android::AutoMutex _l(gMinikinLock); - fonts->clear(); -} - +// static FontFamily::FontFamily(std::vector&& fonts) : FontFamily(0 /* variant */, std::move(fonts)) { } @@ -120,10 +115,11 @@ FontFamily::FontFamily(uint32_t langId, int variant, std::vector&& fonts) FontFamily::~FontFamily() { } -bool FontFamily::analyzeStyle(MinikinFont* typeface, int* weight, bool* italic) { +bool FontFamily::analyzeStyle(const std::shared_ptr& typeface, int* weight, + bool* italic) { android::AutoMutex _l(gMinikinLock); const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2'); - HbBlob os2Table(getFontTable(typeface, os2Tag)); + HbBlob os2Table(getFontTable(typeface.get(), os2Tag)); if (os2Table.get() == nullptr) return false; return ::minikin::analyzeStyle(os2Table.get(), os2Table.size(), weight, italic); } @@ -149,7 +145,7 @@ static FontFakery computeFakery(FontStyle wanted, FontStyle actual) { } FakedFont FontFamily::getClosestMatch(FontStyle style) const { - const Font* bestFont = NULL; + const Font* bestFont = nullptr; int bestMatch = 0; for (size_t i = 0; i < mFonts.size(); i++) { const Font& font = mFonts[i]; @@ -159,14 +155,10 @@ FakedFont FontFamily::getClosestMatch(FontStyle style) const { bestMatch = match; } } - FakedFont result; - if (bestFont == NULL) { - result.font = NULL; - } else { - result.font = bestFont->typeface; - result.fakery = computeFakery(style, bestFont->style); + if (bestFont != nullptr) { + return FakedFont{ bestFont->typeface.get(), computeFakery(style, bestFont->style) }; } - return result; + return FakedFont{ nullptr, FontFakery() }; } bool FontFamily::isColorEmojiFamily() const { @@ -182,7 +174,7 @@ bool FontFamily::isColorEmojiFamily() const { void FontFamily::computeCoverage() { android::AutoMutex _l(gMinikinLock); const FontStyle defaultStyle; - MinikinFont* typeface = getClosestMatch(defaultStyle).font; + const MinikinFont* typeface = getClosestMatch(defaultStyle).font; const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); HbBlob cmapTable(getFontTable(typeface, cmapTag)); if (cmapTable.get() == nullptr) { @@ -206,15 +198,14 @@ bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) const } const FontStyle defaultStyle; - MinikinFont* minikinFont = getClosestMatch(defaultStyle).font; - hb_font_t* font = getHbFontLocked(minikinFont); + hb_font_t* font = getHbFontLocked(getClosestMatch(defaultStyle).font); uint32_t unusedGlyph; bool result = hb_font_get_glyph(font, codepoint, variationSelector, &unusedGlyph); hb_font_destroy(font); return result; } -FontFamily* FontFamily::createFamilyWithVariation( +std::shared_ptr FontFamily::createFamilyWithVariation( const std::vector& variations) const { if (variations.empty() || mSupportedAxes.empty()) { return nullptr; @@ -243,19 +234,17 @@ FontFamily* FontFamily::createFamilyWithVariation( } } } - MinikinFont* minikinFont = nullptr; + std::shared_ptr minikinFont; if (supportedVariations) { minikinFont = font.typeface->createFontWithVariation(variations); } if (minikinFont == nullptr) { minikinFont = font.typeface; - minikinFont->Ref(); } - fonts.push_back(Font(minikinFont, font.style)); - minikinFont->Unref(); + fonts.push_back(Font(std::move(minikinFont), font.style)); } - return new FontFamily(mLangId, mVariant, std::move(fonts)); + return std::shared_ptr(new FontFamily(mLangId, mVariant, std::move(fonts))); } } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index e871b4ef9b4..af3d783bc84 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -84,7 +84,7 @@ void purgeHbFontLocked(const MinikinFont* minikinFont) { // Returns a new reference to a hb_font_t object, caller is // responsible for calling hb_font_destroy() on it. -hb_font_t* getHbFontLocked(MinikinFont* minikinFont) { +hb_font_t* getHbFontLocked(const MinikinFont* minikinFont) { assertMinikinLocked(); // TODO: get rid of nullFaceFont static hb_font_t* nullFaceFont = nullptr; diff --git a/engine/src/flutter/libs/minikin/HbFontCache.h b/engine/src/flutter/libs/minikin/HbFontCache.h index fba685aeb27..59969e287e0 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.h +++ b/engine/src/flutter/libs/minikin/HbFontCache.h @@ -24,7 +24,7 @@ class MinikinFont; void purgeHbFontCacheLocked(); void purgeHbFontLocked(const MinikinFont* minikinFont); -hb_font_t* getHbFontLocked(MinikinFont* minikinFont); +hb_font_t* getHbFontLocked(const MinikinFont* minikinFont); } // namespace minikin #endif // MINIKIN_HBFONT_CACHE_H diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 117f3262363..6b28f57a331 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -104,8 +104,9 @@ struct LayoutContext { class LayoutCacheKey { public: - LayoutCacheKey(const FontCollection* collection, const MinikinPaint& paint, FontStyle style, - const uint16_t* chars, size_t start, size_t count, size_t nchars, bool dir) + LayoutCacheKey(const std::shared_ptr& collection, const MinikinPaint& paint, + FontStyle style, const uint16_t* chars, size_t start, size_t count, size_t nchars, + bool dir) : mChars(chars), mNchars(nchars), mStart(start), mCount(count), mId(collection->getId()), mStyle(style), mSize(paint.size), mScaleX(paint.scaleX), mSkewX(paint.skewX), @@ -129,8 +130,7 @@ public: mChars = NULL; } - void doLayout(Layout* layout, LayoutContext* ctx, const FontCollection* collection) const { - layout->setFontCollection(collection); + void doLayout(Layout* layout, LayoutContext* ctx) const { layout->mAdvances.resize(mCount, 0); ctx->clearHbFonts(); layout->doLayoutRun(mChars, mStart, mCount, mNchars, mIsRtl, ctx); @@ -167,12 +167,13 @@ public: mCache.clear(); } - Layout* get(LayoutCacheKey& key, LayoutContext* ctx, const FontCollection* collection) { + Layout* get(LayoutCacheKey& key, LayoutContext* ctx, + const std::shared_ptr& collection) { Layout* layout = mCache.get(key); if (layout == NULL) { key.copyText(); - layout = new Layout(); - key.doLayout(layout, ctx, collection); + layout = new Layout(collection); + key.doLayout(layout, ctx); mCache.put(key, layout); } return layout; @@ -262,10 +263,6 @@ void MinikinRect::join(const MinikinRect& r) { } } -// Deprecated. Remove when callers are removed. -void Layout::init() { -} - void Layout::reset() { mGlyphs.clear(); mFaces.clear(); @@ -274,15 +271,10 @@ void Layout::reset() { mAdvance = 0; } -void Layout::setFontCollection(const FontCollection* collection) { - mCollection = collection; -} - static hb_position_t harfbuzzGetGlyphHorizontalAdvance(hb_font_t* /* hbFont */, void* fontData, hb_codepoint_t glyph, void* /* userData */) { MinikinPaint* paint = reinterpret_cast(fontData); - MinikinFont* font = paint->font; - float advance = font->GetHorizontalAdvance(glyph, *paint); + float advance = paint->font->GetHorizontalAdvance(glyph, *paint); return 256 * advance + 0.5; } @@ -343,7 +335,7 @@ void Layout::dump() const { } } -int Layout::findFace(FakedFont face, LayoutContext* ctx) { +int Layout::findFace(const FakedFont& face, LayoutContext* ctx) { unsigned int ix; for (ix = 0; ix < mFaces.size(); ix++) { if (mFaces[ix].font == face.font) { @@ -610,7 +602,7 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu float Layout::measureText(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint, - const FontCollection* collection, float* advances) { + const std::shared_ptr& collection, float* advances) { android::AutoMutex _l(gMinikinLock); LayoutContext ctx; @@ -629,8 +621,8 @@ float Layout::measureText(const uint16_t* buf, size_t start, size_t count, size_ } float Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - bool isRtl, LayoutContext* ctx, size_t dstStart, const FontCollection* collection, - Layout* layout, float* advances) { + bool isRtl, LayoutContext* ctx, size_t dstStart, + const std::shared_ptr& collection, Layout* layout, float* advances) { HyphenEdit hyphen = ctx->paint.hyphenEdit; float advance = 0; if (!isRtl) { @@ -668,8 +660,8 @@ float Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, } float Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - bool isRtl, LayoutContext* ctx, size_t bufStart, const FontCollection* collection, - Layout* layout, float* advances) { + bool isRtl, LayoutContext* ctx, size_t bufStart, + const std::shared_ptr& collection, Layout* layout, float* advances) { LayoutCache& cache = LayoutEngine::getInstance().layoutCache; LayoutCacheKey key(collection, ctx->paint, ctx->style, buf, start, count, bufSize, isRtl); @@ -677,8 +669,8 @@ float Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size float advance; if (ctx->paint.skipCache()) { - Layout layoutForWord; - key.doLayout(&layoutForWord, ctx, collection); + Layout layoutForWord(collection); + key.doLayout(&layoutForWord, ctx); if (layout) { layout->appendLayout(&layoutForWord, bufStart, wordSpacing); } @@ -732,9 +724,6 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t hb_buffer_t* buffer = LayoutEngine::getInstance().hbBuffer; vector items; mCollection->itemize(buf + start, count, ctx->style, &items); - if (isRtl) { - std::reverse(items.begin(), items.end()); - } vector features; // Disable default-on non-required ligature features if letter-spacing @@ -756,7 +745,9 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t float x = mAdvance; float y = 0; - for (size_t run_ix = 0; run_ix < items.size(); run_ix++) { + for (int run_ix = isRtl ? items.size() - 1 : 0; + isRtl ? run_ix >= 0 : run_ix < static_cast(items.size()); + isRtl ? --run_ix : ++run_ix) { FontCollection::Run &run = items[run_ix]; if (run.fakedFont.font == NULL) { ALOGE("no font for run starting u+%04x length %d", buf[run.start], run.end - run.start); @@ -967,7 +958,7 @@ size_t Layout::nGlyphs() const { return mGlyphs.size(); } -MinikinFont* Layout::getFont(int i) const { +const MinikinFont* Layout::getFont(int i) const { const LayoutGlyph& glyph = mGlyphs[i]; return mFaces[glyph.font_ix].font; } @@ -1000,7 +991,7 @@ void Layout::getAdvances(float* advances) { memcpy(advances, &mAdvances[0], mAdvances.size() * sizeof(float)); } -void Layout::getBounds(MinikinRect* bounds) { +void Layout::getBounds(MinikinRect* bounds) const { bounds->set(mBounds); } diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index c21e6384c33..3965cbd4c84 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -129,7 +129,7 @@ static bool isLineBreakingHyphen(uint16_t c) { // width buffer. // This method finds the candidate word breaks (using the ICU break iterator) and sends them // to addCandidate. -float LineBreaker::addStyleRun(MinikinPaint* paint, const FontCollection* typeface, +float LineBreaker::addStyleRun(MinikinPaint* paint, const std::shared_ptr& typeface, FontStyle style, size_t start, size_t end, bool isRtl) { float width = 0.0f; int bidiFlags = isRtl ? kBidi_Force_RTL : kBidi_Force_LTR; diff --git a/engine/src/flutter/libs/minikin/MinikinFont.cpp b/engine/src/flutter/libs/minikin/MinikinFont.cpp index 8aee01de7ed..6bf6a4ae3b7 100644 --- a/engine/src/flutter/libs/minikin/MinikinFont.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFont.cpp @@ -16,10 +16,12 @@ #include #include "HbFontCache.h" +#include "MinikinInternal.h" namespace minikin { MinikinFont::~MinikinFont() { + android::AutoMutex _l(gMinikinLock); purgeHbFontLocked(this); } diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index a98fc19e4cd..e766dce992d 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -85,7 +85,7 @@ bool isEmojiBase(uint32_t c) { } } -hb_blob_t* getFontTable(MinikinFont* minikinFont, uint32_t tag) { +hb_blob_t* getFontTable(const MinikinFont* minikinFont, uint32_t tag) { assertMinikinLocked(); hb_font_t* font = getHbFontLocked(minikinFont); hb_face_t* face = hb_font_get_face(font); diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.h b/engine/src/flutter/libs/minikin/MinikinInternal.h index 9557d827df1..365f20cc0df 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.h +++ b/engine/src/flutter/libs/minikin/MinikinInternal.h @@ -45,7 +45,7 @@ bool isEmojiBase(uint32_t c); // Returns true if c is emoji modifier. bool isEmojiModifier(uint32_t c); -hb_blob_t* getFontTable(MinikinFont* minikinFont, uint32_t tag); +hb_blob_t* getFontTable(const MinikinFont* minikinFont, uint32_t tag); // An RAII wrapper for hb_blob_t class HbBlob { diff --git a/engine/src/flutter/libs/minikin/MinikinRefCounted.cpp b/engine/src/flutter/libs/minikin/MinikinRefCounted.cpp deleted file mode 100644 index 6914a012f84..00000000000 --- a/engine/src/flutter/libs/minikin/MinikinRefCounted.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2014 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. - */ - -// Base class for reference counted objects in Minikin - -#include "MinikinInternal.h" - -#include - -namespace minikin { - -void MinikinRefCounted::Ref() { - android::AutoMutex _l(gMinikinLock); - this->RefLocked(); -} - -void MinikinRefCounted::Unref() { - android::AutoMutex _l(gMinikinLock); - this->UnrefLocked(); -} - -} // namespace minikin diff --git a/engine/src/flutter/sample/MinikinSkia.cpp b/engine/src/flutter/sample/MinikinSkia.cpp index ec1e9da78c2..1ba7cccb417 100644 --- a/engine/src/flutter/sample/MinikinSkia.cpp +++ b/engine/src/flutter/sample/MinikinSkia.cpp @@ -44,7 +44,8 @@ void MinikinFontSkia::GetBounds(MinikinRect* bounds, uint32_t glyph_id, bounds->mBottom = skBounds.fBottom; } -const void* MinikinFontSkia::GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) { +const void* MinikinFontSkia::GetTable(uint32_t tag, size_t* size, + MinikinDestroyFunc* destroy) const { // we don't have a buffer to the font data, copy to own buffer const size_t tableSize = mTypeface->getTableSize(tag); *size = tableSize; @@ -60,7 +61,7 @@ const void* MinikinFontSkia::GetTable(uint32_t tag, size_t* size, MinikinDestroy return buf; } -SkTypeface *MinikinFontSkia::GetSkTypeface() { +SkTypeface *MinikinFontSkia::GetSkTypeface() const { return mTypeface.get(); } diff --git a/engine/src/flutter/sample/MinikinSkia.h b/engine/src/flutter/sample/MinikinSkia.h index 8284f5d0f9a..5ebf1b61617 100644 --- a/engine/src/flutter/sample/MinikinSkia.h +++ b/engine/src/flutter/sample/MinikinSkia.h @@ -25,12 +25,12 @@ public: void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint& paint) const; - const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); const std::vector& GetAxes() const { return mAxes; } + const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) const; - SkTypeface *GetSkTypeface(); + SkTypeface *GetSkTypeface() const; private: sk_sp mTypeface; diff --git a/engine/src/flutter/sample/example.cpp b/engine/src/flutter/sample/example.cpp index 1c9c322d232..3df09050030 100644 --- a/engine/src/flutter/sample/example.cpp +++ b/engine/src/flutter/sample/example.cpp @@ -33,7 +33,7 @@ using namespace minikin; FT_Library library; // TODO: this should not be a global FontCollection *makeFontCollection() { - vectortypefaces; + vector>typefaces; const char *fns[] = { "/system/fonts/Roboto-Regular.ttf", "/system/fonts/Roboto-Italic.ttf", @@ -55,17 +55,17 @@ FontCollection *makeFontCollection() { if (error != 0) { printf("error loading %s, %d\n", fn, error); } - MinikinFont *font = new MinikinFontFreeType(face); + std::shared_ptr font(new MinikinFontFreeType(face)); fonts.push_back(Font(font, FontStyle())); } - FontFamily *family = new FontFamily(std::move(fonts)); + std::shared_ptr family(new FontFamily(std::move(fonts))); typefaces.push_back(family); #if 1 const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf"; error = FT_New_Face(library, fn, 0, &face); - MinikinFont *font = new MinikinFontFreeType(face); - family = new FontFamily(std::vector({ Font(font, FontStyle()) })); + std::shared_ptr font(new MinikinFontFreeType(face)); + family.reset(new FontFamily(std::vector({ Font(font, FontStyle()) }))); typefaces.push_back(family); #endif @@ -77,11 +77,8 @@ int runMinikinTest() { if (error) { return -1; } - Layout::init(); - - FontCollection *collection = makeFontCollection(); - Layout layout; - layout.setFontCollection(collection); + std::shared_ptr collection(makeFontCollection()); + Layout layout(collection); const char *text = "fine world \xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa5\x87"; int bidiFlags = 0; FontStyle fontStyle; diff --git a/engine/src/flutter/sample/example_skia.cpp b/engine/src/flutter/sample/example_skia.cpp index 6e6f868051c..6fa788b9e77 100644 --- a/engine/src/flutter/sample/example_skia.cpp +++ b/engine/src/flutter/sample/example_skia.cpp @@ -42,7 +42,7 @@ namespace minikin { FT_Library library; // TODO: this should not be a global FontCollection *makeFontCollection() { - vectortypefaces; + vector> typefaces; const char *fns[] = { "/system/fonts/Roboto-Regular.ttf", "/system/fonts/Roboto-Italic.ttf", @@ -58,20 +58,19 @@ FontCollection *makeFontCollection() { for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) { const char *fn = fns[i]; sk_sp skFace = SkTypeface::MakeFromFile(fn); - MinikinFont *font = new MinikinFontSkia(std::move(skFace)); + std::shared_ptr font(new MinikinFontSkia(std::move(skFace))); fonts.push_back(Font(font, FontStyle())); } - FontFamily *family = new FontFamily(std::move(fonts)); + std::shared_ptr family(new FontFamily(std::move(fonts))); typefaces.push_back(family); #if 1 const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf"; sk_sp skFace = SkTypeface::MakeFromFile(fn); - MinikinFont *font = new MinikinFontSkia(std::move(skFace)); - family = new FontFamily(std::vector({ Font(font, FontStyle()) })); + std::shared_ptr font(new MinikinFontSkia(std::move(skFace))); + family.reset(new FontFamily(std::vector({ Font(font, FontStyle()) }))); typefaces.push_back(family); #endif - return new FontCollection(typefaces); } @@ -87,7 +86,7 @@ void drawToSkia(SkCanvas *canvas, SkPaint *paint, Layout *layout, float x, float paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); for (size_t i = 0; i < nGlyphs; i++) { - MinikinFontSkia *mfs = static_cast(layout->getFont(i)); + const MinikinFontSkia *mfs = static_cast(layout->getFont(i)); skFace = mfs->GetSkTypeface(); glyphs[i] = layout->getGlyphId(i); pos[i].fX = x + layout->getX(i); @@ -110,11 +109,9 @@ int runMinikinTest() { if (error) { return -1; } - Layout::init(); - FontCollection *collection = makeFontCollection(); - Layout layout; - layout.setFontCollection(collection); + std::shared_ptr collection(makeFontCollection()); + Layout layout(collection); const char *text = "fine world \xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa5\x87"; int bidiFlags = 0; FontStyle fontStyle(7); diff --git a/engine/src/flutter/tests/perftests/FontCollection.cpp b/engine/src/flutter/tests/perftests/FontCollection.cpp index a54607d1833..6f9d636ca30 100644 --- a/engine/src/flutter/tests/perftests/FontCollection.cpp +++ b/engine/src/flutter/tests/perftests/FontCollection.cpp @@ -15,7 +15,8 @@ */ #include -#include +#include + #include #include #include @@ -27,7 +28,7 @@ const char* SYSTEM_FONT_PATH = "/system/fonts/"; const char* SYSTEM_FONT_XML = "/system/etc/fonts.xml"; static void BM_FontCollection_hasVariationSelector(benchmark::State& state) { - MinikinAutoUnref collection( + std::shared_ptr collection( getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); uint32_t baseCp = state.range(0); @@ -63,7 +64,7 @@ struct ItemizeTestCases { }; static void BM_FontCollection_itemize(benchmark::State& state) { - MinikinAutoUnref collection( + std::shared_ptr collection( getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); size_t testIndex = state.range(0); diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 5c5a5d343cb..aa142cccdcd 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -16,6 +16,8 @@ #include +#include + #include "FontLanguageListCache.h" #include "FontLanguage.h" #include "FontTestUtils.h" @@ -50,7 +52,7 @@ const char kNoCmapFormat14Font[] = kTestFontDir "VarioationSelectorTest-Regular typedef ICUTestBase FontCollectionItemizeTest; // Utility function for calling itemize function. -void itemize(FontCollection* collection, const char* str, FontStyle style, +void itemize(const std::shared_ptr& collection, const char* str, FontStyle style, std::vector* result) { const size_t BUF_SIZE = 256; uint16_t buf[BUF_SIZE]; @@ -75,7 +77,7 @@ const FontLanguages& registerAndGetFontLanguages(const std::string& lang_string) } TEST_F(FontCollectionItemizeTest, itemize_latin) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; const FontStyle kRegularStyle = FontStyle(); @@ -83,7 +85,7 @@ TEST_F(FontCollectionItemizeTest, itemize_latin) { const FontStyle kBoldStyle = FontStyle(7, false); const FontStyle kBoldItalicStyle = FontStyle(7, true); - itemize(collection.get(), "'a' 'b' 'c' 'd' 'e'", kRegularStyle, &runs); + itemize(collection, "'a' 'b' 'c' 'd' 'e'", kRegularStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); @@ -91,7 +93,7 @@ TEST_F(FontCollectionItemizeTest, itemize_latin) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); - itemize(collection.get(), "'a' 'b' 'c' 'd' 'e'", kItalicStyle, &runs); + itemize(collection, "'a' 'b' 'c' 'd' 'e'", kItalicStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); @@ -99,7 +101,7 @@ TEST_F(FontCollectionItemizeTest, itemize_latin) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); - itemize(collection.get(), "'a' 'b' 'c' 'd' 'e'", kBoldStyle, &runs); + itemize(collection, "'a' 'b' 'c' 'd' 'e'", kBoldStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); @@ -107,7 +109,7 @@ TEST_F(FontCollectionItemizeTest, itemize_latin) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); - itemize(collection.get(), "'a' 'b' 'c' 'd' 'e'", kBoldItalicStyle, &runs); + itemize(collection, "'a' 'b' 'c' 'd' 'e'", kBoldItalicStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); @@ -117,7 +119,7 @@ TEST_F(FontCollectionItemizeTest, itemize_latin) { // Continue if the specific characters (e.g. hyphen, comma, etc.) is // followed. - itemize(collection.get(), "'a' ',' '-' 'd' '!'", kRegularStyle, &runs); + itemize(collection, "'a' ',' '-' 'd' '!'", kRegularStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); @@ -125,7 +127,7 @@ TEST_F(FontCollectionItemizeTest, itemize_latin) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); - itemize(collection.get(), "'a' ',' '-' 'd' '!'", kRegularStyle, &runs); + itemize(collection, "'a' ',' '-' 'd' '!'", kRegularStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); @@ -135,7 +137,7 @@ TEST_F(FontCollectionItemizeTest, itemize_latin) { // U+0301(COMBINING ACUTE ACCENT) must be in the same run with preceding // chars if the font supports it. - itemize(collection.get(), "'a' U+0301", kRegularStyle, &runs); + itemize(collection, "'a' U+0301", kRegularStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -145,10 +147,10 @@ TEST_F(FontCollectionItemizeTest, itemize_latin) { } TEST_F(FontCollectionItemizeTest, itemize_emoji) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; - itemize(collection.get(), "U+1F469 U+1F467", FontStyle(), &runs); + itemize(collection, "U+1F469 U+1F467", FontStyle(), &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); @@ -158,7 +160,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emoji) { // U+20E3(COMBINING ENCLOSING KEYCAP) must be in the same run with preceding // character if the font supports. - itemize(collection.get(), "'0' U+20E3", FontStyle(), &runs); + itemize(collection, "'0' U+20E3", FontStyle(), &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -166,7 +168,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emoji) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); - itemize(collection.get(), "U+1F470 U+20E3", FontStyle(), &runs); + itemize(collection, "U+1F470 U+20E3", FontStyle(), &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); @@ -174,7 +176,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emoji) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeBold()); EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); - itemize(collection.get(), "U+242EE U+1F470 U+20E3", FontStyle(), &runs); + itemize(collection, "U+242EE U+1F470 U+20E3", FontStyle(), &runs); ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -190,7 +192,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emoji) { // Currently there is no fonts which has a glyph for 'a' + U+20E3, so they // are splitted into two. - itemize(collection.get(), "'a' U+20E3", FontStyle(), &runs); + itemize(collection, "'a' U+20E3", FontStyle(), &runs); ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); @@ -206,7 +208,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emoji) { } TEST_F(FontCollectionItemizeTest, itemize_non_latin) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; FontStyle kJAStyle = FontStyle(FontStyle::registerLanguageList("ja_JP")); @@ -214,7 +216,7 @@ TEST_F(FontCollectionItemizeTest, itemize_non_latin) { FontStyle kZH_HansStyle = FontStyle(FontStyle::registerLanguageList("zh_Hans")); // All Japanese Hiragana characters. - itemize(collection.get(), "U+3042 U+3044 U+3046 U+3048 U+304A", kUSStyle, &runs); + itemize(collection, "U+3042 U+3044 U+3046 U+3048 U+304A", kUSStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); @@ -223,7 +225,7 @@ TEST_F(FontCollectionItemizeTest, itemize_non_latin) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); // All Korean Hangul characters. - itemize(collection.get(), "U+B300 U+D55C U+BBFC U+AD6D", kUSStyle, &runs); + itemize(collection, "U+B300 U+D55C U+BBFC U+AD6D", kUSStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); @@ -233,7 +235,7 @@ TEST_F(FontCollectionItemizeTest, itemize_non_latin) { // All Han characters ja, zh-Hans font having. // Japanese font should be selected if the specified language is Japanese. - itemize(collection.get(), "U+81ED U+82B1 U+5FCD", kJAStyle, &runs); + itemize(collection, "U+81ED U+82B1 U+5FCD", kJAStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); @@ -243,7 +245,7 @@ TEST_F(FontCollectionItemizeTest, itemize_non_latin) { // Simplified Chinese font should be selected if the specified language is Simplified // Chinese. - itemize(collection.get(), "U+81ED U+82B1 U+5FCD", kZH_HansStyle, &runs); + itemize(collection, "U+81ED U+82B1 U+5FCD", kZH_HansStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); @@ -253,7 +255,7 @@ TEST_F(FontCollectionItemizeTest, itemize_non_latin) { // Fallbacks to other fonts if there is no glyph in the specified language's // font. There is no character U+4F60 in Japanese. - itemize(collection.get(), "U+81ED U+4F60 U+5FCD", kJAStyle, &runs); + itemize(collection, "U+81ED U+4F60 U+5FCD", kJAStyle, &runs); ASSERT_EQ(3U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); @@ -274,7 +276,7 @@ TEST_F(FontCollectionItemizeTest, itemize_non_latin) { EXPECT_FALSE(runs[2].fakedFont.fakery.isFakeItalic()); // Tone mark. - itemize(collection.get(), "U+4444 U+302D", FontStyle(), &runs); + itemize(collection, "U+4444 U+302D", FontStyle(), &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -285,7 +287,7 @@ TEST_F(FontCollectionItemizeTest, itemize_non_latin) { // Both zh-Hant and ja fonts support U+242EE, but zh-Hans doesn't. // Here, ja and zh-Hant font should have the same score but ja should be selected since it is // listed before zh-Hant. - itemize(collection.get(), "U+242EE", kZH_HansStyle, &runs); + itemize(collection, "U+242EE", kZH_HansStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -295,12 +297,12 @@ TEST_F(FontCollectionItemizeTest, itemize_non_latin) { } TEST_F(FontCollectionItemizeTest, itemize_mixed) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; FontStyle kUSStyle = FontStyle(FontStyle::registerLanguageList("en_US")); - itemize(collection.get(), "'a' U+4F60 'b' U+4F60 'c'", kUSStyle, &runs); + itemize(collection, "'a' U+4F60 'b' U+4F60 'c'", kUSStyle, &runs); ASSERT_EQ(5U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); @@ -334,7 +336,7 @@ TEST_F(FontCollectionItemizeTest, itemize_mixed) { } TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; // A glyph for U+4FAE is provided by both Japanese font and Simplified @@ -346,19 +348,19 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { // U+4FAE is available in both zh_Hans and ja font, but U+4FAE,U+FE00 is // only available in ja font. - itemize(collection.get(), "U+4FAE", kZH_HansStyle, &runs); + itemize(collection, "U+4FAE", kZH_HansStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); - itemize(collection.get(), "U+4FAE U+FE00", kZH_HansStyle, &runs); + itemize(collection, "U+4FAE U+FE00", kZH_HansStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); EXPECT_EQ(kJAFont, getFontPath(runs[0])); - itemize(collection.get(), "U+4FAE U+4FAE U+FE00", kZH_HansStyle, &runs); + itemize(collection, "U+4FAE U+4FAE U+FE00", kZH_HansStyle, &runs); ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); @@ -367,7 +369,7 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { EXPECT_EQ(3, runs[1].end); EXPECT_EQ(kJAFont, getFontPath(runs[1])); - itemize(collection.get(), "U+4FAE U+4FAE U+FE00 U+4FAE", kZH_HansStyle, &runs); + itemize(collection, "U+4FAE U+4FAE U+FE00 U+4FAE", kZH_HansStyle, &runs); ASSERT_EQ(3U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); @@ -380,14 +382,14 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { EXPECT_EQ(kZH_HansFont, getFontPath(runs[2])); // Validation selector after validation selector. - itemize(collection.get(), "U+4FAE U+FE00 U+FE00", kZH_HansStyle, &runs); + itemize(collection, "U+4FAE U+FE00 U+FE00", kZH_HansStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); EXPECT_EQ(kJAFont, getFontPath(runs[1])); // No font supports U+242EE U+FE0E. - itemize(collection.get(), "U+4FAE U+FE0E", kZH_HansStyle, &runs); + itemize(collection, "U+4FAE U+FE0E", kZH_HansStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -396,19 +398,19 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { // Surrogate pairs handling. // U+242EE is available in ja font and zh_Hant font. // U+242EE U+FE00 is available only in ja font. - itemize(collection.get(), "U+242EE", kZH_HantStyle, &runs); + itemize(collection, "U+242EE", kZH_HantStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); - itemize(collection.get(), "U+242EE U+FE00", kZH_HantStyle, &runs); + itemize(collection, "U+242EE U+FE00", kZH_HantStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); EXPECT_EQ(kJAFont, getFontPath(runs[0])); - itemize(collection.get(), "U+242EE U+242EE U+FE00", kZH_HantStyle, &runs); + itemize(collection, "U+242EE U+242EE U+FE00", kZH_HantStyle, &runs); ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -417,7 +419,7 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { EXPECT_EQ(5, runs[1].end); EXPECT_EQ(kJAFont, getFontPath(runs[1])); - itemize(collection.get(), "U+242EE U+242EE U+FE00 U+242EE", kZH_HantStyle, &runs); + itemize(collection, "U+242EE U+242EE U+FE00 U+242EE", kZH_HantStyle, &runs); ASSERT_EQ(3U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -430,27 +432,27 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { EXPECT_EQ(kZH_HantFont, getFontPath(runs[2])); // Validation selector after validation selector. - itemize(collection.get(), "U+242EE U+FE00 U+FE00", kZH_HansStyle, &runs); + itemize(collection, "U+242EE U+FE00 U+FE00", kZH_HansStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); EXPECT_EQ(kJAFont, getFontPath(runs[0])); // No font supports U+242EE U+FE0E - itemize(collection.get(), "U+242EE U+FE0E", kZH_HantStyle, &runs); + itemize(collection, "U+242EE U+FE0E", kZH_HantStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); // Isolated variation selector supplement. - itemize(collection.get(), "U+FE00", FontStyle(), &runs); + itemize(collection, "U+FE00", FontStyle(), &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); - itemize(collection.get(), "U+FE00", kZH_HantStyle, &runs); + itemize(collection, "U+FE00", kZH_HantStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); @@ -458,14 +460,14 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { // First font family (Regular.ttf) supports U+203C but doesn't support U+203C U+FE0F. // Emoji.ttf font supports U+203C U+FE0F. Emoji.ttf should be selected. - itemize(collection.get(), "U+203C U+FE0F", kZH_HantStyle, &runs); + itemize(collection, "U+203C U+FE0F", kZH_HantStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); EXPECT_EQ(kEmojiFont, getFontPath(runs[0])); // First font family (Regular.ttf) supports U+203C U+FE0E. - itemize(collection.get(), "U+203C U+FE0E", kZH_HantStyle, &runs); + itemize(collection, "U+203C U+FE0E", kZH_HantStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -473,7 +475,7 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelector) { } TEST_F(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; // A glyph for U+845B is provided by both Japanese font and Simplified @@ -485,19 +487,19 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { // U+845B is available in both zh_Hans and ja font, but U+845B,U+E0100 is // only available in ja font. - itemize(collection.get(), "U+845B", kZH_HansStyle, &runs); + itemize(collection, "U+845B", kZH_HansStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); EXPECT_EQ(kZH_HansFont, getFontPath(runs[0])); - itemize(collection.get(), "U+845B U+E0100", kZH_HansStyle, &runs); + itemize(collection, "U+845B U+E0100", kZH_HansStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); EXPECT_EQ(kJAFont, getFontPath(runs[0])); - itemize(collection.get(), "U+845B U+845B U+E0100", kZH_HansStyle, &runs); + itemize(collection, "U+845B U+845B U+E0100", kZH_HansStyle, &runs); ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); @@ -506,7 +508,7 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { EXPECT_EQ(4, runs[1].end); EXPECT_EQ(kJAFont, getFontPath(runs[1])); - itemize(collection.get(), "U+845B U+845B U+E0100 U+845B", kZH_HansStyle, &runs); + itemize(collection, "U+845B U+845B U+E0100 U+845B", kZH_HansStyle, &runs); ASSERT_EQ(3U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); @@ -519,14 +521,14 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { EXPECT_EQ(kZH_HansFont, getFontPath(runs[2])); // Validation selector after validation selector. - itemize(collection.get(), "U+845B U+E0100 U+E0100", kZH_HansStyle, &runs); + itemize(collection, "U+845B U+E0100 U+E0100", kZH_HansStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); EXPECT_EQ(kJAFont, getFontPath(runs[0])); // No font supports U+845B U+E01E0. - itemize(collection.get(), "U+845B U+E01E0", kZH_HansStyle, &runs); + itemize(collection, "U+845B U+E01E0", kZH_HansStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); @@ -536,19 +538,19 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { // Surrogate pairs handling. // U+242EE is available in ja font and zh_Hant font. // U+242EE U+E0100 is available only in ja font. - itemize(collection.get(), "U+242EE", kZH_HantStyle, &runs); + itemize(collection, "U+242EE", kZH_HantStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); - itemize(collection.get(), "U+242EE U+E0101", kZH_HantStyle, &runs); + itemize(collection, "U+242EE U+E0101", kZH_HantStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); EXPECT_EQ(kJAFont, getFontPath(runs[0])); - itemize(collection.get(), "U+242EE U+242EE U+E0101", kZH_HantStyle, &runs); + itemize(collection, "U+242EE U+242EE U+E0101", kZH_HantStyle, &runs); ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -557,7 +559,7 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { EXPECT_EQ(6, runs[1].end); EXPECT_EQ(kJAFont, getFontPath(runs[1])); - itemize(collection.get(), "U+242EE U+242EE U+E0101 U+242EE", kZH_HantStyle, &runs); + itemize(collection, "U+242EE U+242EE U+E0101 U+242EE", kZH_HantStyle, &runs); ASSERT_EQ(3U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -570,27 +572,27 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { EXPECT_EQ(kZH_HantFont, getFontPath(runs[2])); // Validation selector after validation selector. - itemize(collection.get(), "U+242EE U+E0100 U+E0100", kZH_HantStyle, &runs); + itemize(collection, "U+242EE U+E0100 U+E0100", kZH_HantStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(6, runs[0].end); EXPECT_EQ(kJAFont, getFontPath(runs[0])); // No font supports U+242EE U+E01E0. - itemize(collection.get(), "U+242EE U+E01E0", kZH_HantStyle, &runs); + itemize(collection, "U+242EE U+E01E0", kZH_HantStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); EXPECT_EQ(kZH_HantFont, getFontPath(runs[0])); // Isolated variation selector supplement. - itemize(collection.get(), "U+E0100", FontStyle(), &runs); + itemize(collection, "U+E0100", FontStyle(), &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); EXPECT_TRUE(runs[0].fakedFont.font == nullptr || kLatinFont == getFontPath(runs[0])); - itemize(collection.get(), "U+E0100", kZH_HantStyle, &runs); + itemize(collection, "U+E0100", kZH_HantStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -598,31 +600,31 @@ TEST_F(FontCollectionItemizeTest, itemize_variationSelectorSupplement) { } TEST_F(FontCollectionItemizeTest, itemize_no_crash) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; // Broken Surrogate pairs. Check only not crashing. - itemize(collection.get(), "'a' U+D83D 'a'", FontStyle(), &runs); - itemize(collection.get(), "'a' U+DC69 'a'", FontStyle(), &runs); - itemize(collection.get(), "'a' U+D83D U+D83D 'a'", FontStyle(), &runs); - itemize(collection.get(), "'a' U+DC69 U+DC69 'a'", FontStyle(), &runs); + itemize(collection, "'a' U+D83D 'a'", FontStyle(), &runs); + itemize(collection, "'a' U+DC69 'a'", FontStyle(), &runs); + itemize(collection, "'a' U+D83D U+D83D 'a'", FontStyle(), &runs); + itemize(collection, "'a' U+DC69 U+DC69 'a'", FontStyle(), &runs); // Isolated variation selector. Check only not crashing. - itemize(collection.get(), "U+FE00 U+FE00", FontStyle(), &runs); - itemize(collection.get(), "U+E0100 U+E0100", FontStyle(), &runs); - itemize(collection.get(), "U+FE00 U+E0100", FontStyle(), &runs); - itemize(collection.get(), "U+E0100 U+FE00", FontStyle(), &runs); + itemize(collection, "U+FE00 U+FE00", FontStyle(), &runs); + itemize(collection, "U+E0100 U+E0100", FontStyle(), &runs); + itemize(collection, "U+FE00 U+E0100", FontStyle(), &runs); + itemize(collection, "U+E0100 U+FE00", FontStyle(), &runs); // Tone mark only. Check only not crashing. - itemize(collection.get(), "U+302D", FontStyle(), &runs); - itemize(collection.get(), "U+302D U+302D", FontStyle(), &runs); + itemize(collection, "U+302D", FontStyle(), &runs); + itemize(collection, "U+302D U+302D", FontStyle(), &runs); // Tone mark and variation selector mixed. Check only not crashing. - itemize(collection.get(), "U+FE00 U+302D U+E0100", FontStyle(), &runs); + itemize(collection, "U+FE00 U+302D U+E0100", FontStyle(), &runs); } TEST_F(FontCollectionItemizeTest, itemize_fakery) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kItemizeFontXml)); std::vector runs; FontStyle kJABoldStyle = FontStyle(FontStyle::registerLanguageList("ja_JP"), 0, 7, false); @@ -634,7 +636,7 @@ TEST_F(FontCollectionItemizeTest, itemize_fakery) { // the differences between desired and actual font style. // All Japanese Hiragana characters. - itemize(collection.get(), "U+3042 U+3044 U+3046 U+3048 U+304A", kJABoldStyle, &runs); + itemize(collection, "U+3042 U+3044 U+3046 U+3048 U+304A", kJABoldStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); @@ -643,7 +645,7 @@ TEST_F(FontCollectionItemizeTest, itemize_fakery) { EXPECT_FALSE(runs[0].fakedFont.fakery.isFakeItalic()); // All Japanese Hiragana characters. - itemize(collection.get(), "U+3042 U+3044 U+3046 U+3048 U+304A", kJAItalicStyle, &runs); + itemize(collection, "U+3042 U+3044 U+3046 U+3048 U+304A", kJAItalicStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); @@ -652,7 +654,7 @@ TEST_F(FontCollectionItemizeTest, itemize_fakery) { EXPECT_TRUE(runs[0].fakedFont.fakery.isFakeItalic()); // All Japanese Hiragana characters. - itemize(collection.get(), "U+3042 U+3044 U+3046 U+3048 U+304A", kJABoldItalicStyle, &runs); + itemize(collection, "U+3042 U+3044 U+3046 U+3048 U+304A", kJABoldItalicStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); @@ -667,29 +669,26 @@ TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { // point. const std::string kVSTestFont = kTestFontDir "VarioationSelectorTest-Regular.ttf"; - std::vector families; - MinikinAutoUnref font(new MinikinFontForTest(kLatinFont)); - FontFamily* family1 = new FontFamily(VARIANT_DEFAULT, - std::vector{ Font(font.get(), FontStyle()) }); + std::vector> families; + std::shared_ptr font(new MinikinFontForTest(kLatinFont)); + std::shared_ptr family1(new FontFamily(VARIANT_DEFAULT, + std::vector{ Font(font, FontStyle()) })); families.push_back(family1); - MinikinAutoUnref font2(new MinikinFontForTest(kVSTestFont)); - FontFamily* family2 = new FontFamily(VARIANT_DEFAULT, - std::vector{ Font(font2.get(), FontStyle()) }); + std::shared_ptr font2(new MinikinFontForTest(kVSTestFont)); + std::shared_ptr family2(new FontFamily(VARIANT_DEFAULT, + std::vector{ Font(font2, FontStyle()) })); families.push_back(family2); - FontCollection collection(families); + std::shared_ptr collection(new FontCollection(families)); std::vector runs; - itemize(&collection, "U+717D U+FE02", FontStyle(), &runs); + itemize(collection, "U+717D U+FE02", FontStyle(), &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); EXPECT_EQ(kVSTestFont, getFontPath(runs[0])); - - family1->Unref(); - family2->Unref(); } TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { @@ -808,14 +807,14 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { SCOPED_TRACE("Test of user preferred languages: \"" + testCase.userPreferredLanguages + "\" with font languages: " + fontLanguagesStr); - std::vector families; + std::vector> families; // Prepare first font which doesn't supports U+9AA8 - MinikinAutoUnref firstFamilyMinikinFont( + std::shared_ptr firstFamilyMinikinFont( new MinikinFontForTest(kNoGlyphFont)); - FontFamily* firstFamily = new FontFamily( + std::shared_ptr firstFamily(new FontFamily( FontStyle::registerLanguageList("und"), 0 /* variant */, - std::vector({ Font(firstFamilyMinikinFont.get(), FontStyle()) })); + std::vector({ Font(firstFamilyMinikinFont, FontStyle()) }))); families.push_back(firstFamily); // Prepare font families @@ -824,23 +823,19 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageScore) { std::unordered_map fontLangIdxMap; for (size_t i = 0; i < testCase.fontLanguages.size(); ++i) { - MinikinAutoUnref minikin_font(new MinikinFontForTest(kJAFont)); - FontFamily* family = new FontFamily( + std::shared_ptr minikin_font(new MinikinFontForTest(kJAFont)); + std::shared_ptr family(new FontFamily( FontStyle::registerLanguageList(testCase.fontLanguages[i]), 0 /* variant */, - std::vector({ Font(minikin_font.get(), FontStyle()) })); + std::vector({ Font(minikin_font, FontStyle()) }))); families.push_back(family); fontLangIdxMap.insert(std::make_pair(minikin_font.get(), i)); } - MinikinAutoUnref collection(new FontCollection(families)); - for (auto family : families) { - family->Unref(); - } - + std::shared_ptr collection(new FontCollection(families)); // Do itemize const FontStyle style = FontStyle( FontStyle::registerLanguageList(testCase.userPreferredLanguages)); std::vector runs; - itemize(collection.get(), "U+9AA8", style, &runs); + itemize(collection, "U+9AA8", style, &runs); ASSERT_EQ(1U, runs.size()); ASSERT_NE(nullptr, runs[0].fakedFont.font); @@ -1146,7 +1141,7 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageAndCoverage) { { "U+1F469", "zh-Hant,ja-Jpan,zh-Hans", kEmojiFont }, }; - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kItemizeFontXml)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kItemizeFontXml)); for (auto testCase : testCases) { SCOPED_TRACE("Test for \"" + testCase.testString + "\" with languages " + @@ -1155,21 +1150,21 @@ TEST_F(FontCollectionItemizeTest, itemize_LanguageAndCoverage) { std::vector runs; const FontStyle style = FontStyle(FontStyle::registerLanguageList(testCase.requestedLanguages)); - itemize(collection.get(), testCase.testString.c_str(), style, &runs); + itemize(collection, testCase.testString.c_str(), style, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(testCase.expectedFont, getFontPath(runs[0])); } } TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); std::vector runs; const FontStyle kDefaultFontStyle; // U+00A9 is a text default emoji which is only available in TextEmojiFont.ttf. // TextEmojiFont.ttf should be selected. - itemize(collection.get(), "U+00A9 U+FE0E", kDefaultFontStyle, &runs); + itemize(collection, "U+00A9 U+FE0E", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1177,7 +1172,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { // U+00A9 is a text default emoji which is only available in ColorEmojiFont.ttf. // ColorEmojiFont.ttf should be selected. - itemize(collection.get(), "U+00AE U+FE0E", kDefaultFontStyle, &runs); + itemize(collection, "U+00AE U+FE0E", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1186,7 +1181,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { // U+203C is a text default emoji which is available in both TextEmojiFont.ttf and // ColorEmojiFont.ttf. TextEmojiFont.ttf should be selected. - itemize(collection.get(), "U+203C U+FE0E", kDefaultFontStyle, &runs); + itemize(collection, "U+203C U+FE0E", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1194,7 +1189,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { // U+2049 is a text default emoji which is not available either TextEmojiFont.ttf or // ColorEmojiFont.ttf. No font should be selected. - itemize(collection.get(), "U+2049 U+FE0E", kDefaultFontStyle, &runs); + itemize(collection, "U+2049 U+FE0E", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1202,7 +1197,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { // U+231A is a emoji default emoji which is available only in TextEmojifFont. // TextEmojiFont.ttf sohuld be selected. - itemize(collection.get(), "U+231A U+FE0E", kDefaultFontStyle, &runs); + itemize(collection, "U+231A U+FE0E", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1210,7 +1205,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { // U+231B is a emoji default emoji which is available only in ColorEmojiFont.ttf. // ColorEmojiFont.ttf should be selected. - itemize(collection.get(), "U+231B U+FE0E", kDefaultFontStyle, &runs); + itemize(collection, "U+231B U+FE0E", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1220,7 +1215,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { // U+23E9 is a emoji default emoji which is available in both TextEmojiFont.ttf and // ColorEmojiFont.ttf. TextEmojiFont.ttf should be selected even if U+23E9 is emoji default // emoji since U+FE0E is appended. - itemize(collection.get(), "U+23E9 U+FE0E", kDefaultFontStyle, &runs); + itemize(collection, "U+23E9 U+FE0E", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1228,7 +1223,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { // U+23EA is a emoji default emoji but which is not available in either TextEmojiFont.ttf or // ColorEmojiFont.ttf. No font should be selected. - itemize(collection.get(), "U+23EA U+FE0E", kDefaultFontStyle, &runs); + itemize(collection, "U+23EA U+FE0E", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1236,7 +1231,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { // U+26FA U+FE0E is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. - itemize(collection.get(), "U+26FA U+FE0E", kDefaultFontStyle, &runs); + itemize(collection, "U+26FA U+FE0E", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1244,14 +1239,14 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0E) { } TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); std::vector runs; const FontStyle kDefaultFontStyle; // U+00A9 is a text default emoji which is available only in TextEmojiFont.ttf. // TextEmojiFont.ttf shoudl be selected. - itemize(collection.get(), "U+00A9 U+FE0F", kDefaultFontStyle, &runs); + itemize(collection, "U+00A9 U+FE0F", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1260,7 +1255,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { // U+00AE is a text default emoji which is available only in ColorEmojiFont.ttf. // ColorEmojiFont.ttf should be selected. - itemize(collection.get(), "U+00AE U+FE0F", kDefaultFontStyle, &runs); + itemize(collection, "U+00AE U+FE0F", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1269,7 +1264,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { // U+203C is a text default emoji which is available in both TextEmojiFont.ttf and // ColorEmojiFont.ttf. ColorEmojiFont.ttf should be selected even if U+203C is a text default // emoji since U+FF0F is appended. - itemize(collection.get(), "U+203C U+FE0F", kDefaultFontStyle, &runs); + itemize(collection, "U+203C U+FE0F", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1277,7 +1272,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { // U+2049 is a text default emoji which is not available in either TextEmojiFont.ttf or // ColorEmojiFont.ttf. No font should be selected. - itemize(collection.get(), "U+2049 U+FE0F", kDefaultFontStyle, &runs); + itemize(collection, "U+2049 U+FE0F", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1285,7 +1280,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { // U+231A is a emoji default emoji which is available only in TextEmojiFont.ttf. // TextEmojiFont.ttf should be selected. - itemize(collection.get(), "U+231A U+FE0F", kDefaultFontStyle, &runs); + itemize(collection, "U+231A U+FE0F", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1294,7 +1289,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { // U+231B is a emoji default emoji which is available only in ColorEmojiFont.ttf. // ColorEmojiFont.ttf should be selected. - itemize(collection.get(), "U+231B U+FE0F", kDefaultFontStyle, &runs); + itemize(collection, "U+231B U+FE0F", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1302,7 +1297,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { // U+23E9 is a emoji default emoji which is available in both TextEmojiFont.ttf and // ColorEmojiFont.ttf. ColorEmojiFont.ttf should be selected. - itemize(collection.get(), "U+23E9 U+FE0F", kDefaultFontStyle, &runs); + itemize(collection, "U+23E9 U+FE0F", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1310,7 +1305,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { // U+23EA is a emoji default emoji which is not available in either TextEmojiFont.ttf or // ColorEmojiFont.ttf. No font should be selected. - itemize(collection.get(), "U+23EA U+FE0F", kDefaultFontStyle, &runs); + itemize(collection, "U+23EA U+FE0F", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1318,7 +1313,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { // U+26F9 U+FE0F is specified but ColorTextMixedEmojiFont has a variation sequence U+26F9 U+FE0F // in its cmap, so ColorTextMixedEmojiFont should be selected instaed of ColorEmojiFont. - itemize(collection.get(), "U+26F9 U+FE0F", kDefaultFontStyle, &runs); + itemize(collection, "U+26F9 U+FE0F", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1326,27 +1321,27 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_withFE0F) { } TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_with_skinTone) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); std::vector runs; const FontStyle kDefaultFontStyle; // TextEmoji font is selected since it is listed before ColorEmoji font. - itemize(collection.get(), "U+261D", kDefaultFontStyle, &runs); + itemize(collection, "U+261D", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(1, runs[0].end); EXPECT_EQ(kTextEmojiFont, getFontPath(runs[0])); // If skin tone is specified, it should be colored. - itemize(collection.get(), "U+261D U+1F3FD", kDefaultFontStyle, &runs); + itemize(collection, "U+261D U+1F3FD", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(3, runs[0].end); EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); // Still color font is selected if an emoji variation selector is specified. - itemize(collection.get(), "U+261D U+FE0F U+1F3FD", kDefaultFontStyle, &runs); + itemize(collection, "U+261D U+FE0F U+1F3FD", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); @@ -1354,7 +1349,7 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_with_skinTone) { // Text font should be selected if a text variation selector is specified and skin tone is // rendered by itself. - itemize(collection.get(), "U+261D U+FE0E U+1F3FD", kDefaultFontStyle, &runs); + itemize(collection, "U+261D U+FE0E U+1F3FD", kDefaultFontStyle, &runs); ASSERT_EQ(2U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); @@ -1365,19 +1360,19 @@ TEST_F(FontCollectionItemizeTest, itemize_emojiSelection_with_skinTone) { } TEST_F(FontCollectionItemizeTest, itemize_PrivateUseArea) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); std::vector runs; const FontStyle kDefaultFontStyle; // Should not set nullptr to the result run. (Issue 26808815) - itemize(collection.get(), "U+FEE10", kDefaultFontStyle, &runs); + itemize(collection, "U+FEE10", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(2, runs[0].end); EXPECT_EQ(kNoGlyphFont, getFontPath(runs[0])); - itemize(collection.get(), "U+FEE40 U+FE4C5", kDefaultFontStyle, &runs); + itemize(collection, "U+FEE40 U+FE4C5", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); @@ -1385,24 +1380,24 @@ TEST_F(FontCollectionItemizeTest, itemize_PrivateUseArea) { } TEST_F(FontCollectionItemizeTest, itemize_genderBalancedEmoji) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); std::vector runs; const FontStyle kDefaultFontStyle; - itemize(collection.get(), "U+1F469 U+200D U+1F373", kDefaultFontStyle, &runs); + itemize(collection, "U+1F469 U+200D U+1F373", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); - itemize(collection.get(), "U+1F469 U+200D U+2695 U+FE0F", kDefaultFontStyle, &runs); + itemize(collection, "U+1F469 U+200D U+2695 U+FE0F", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(5, runs[0].end); EXPECT_EQ(kColorEmojiFont, getFontPath(runs[0])); - itemize(collection.get(), "U+1F469 U+200D U+2695", kDefaultFontStyle, &runs); + itemize(collection, "U+1F469 U+200D U+2695", kDefaultFontStyle, &runs); ASSERT_EQ(1U, runs.size()); EXPECT_EQ(0, runs[0].start); EXPECT_EQ(4, runs[0].end); @@ -1413,32 +1408,32 @@ TEST_F(FontCollectionItemizeTest, itemize_genderBalancedEmoji) { TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS) { const FontStyle kDefaultFontStyle; - MinikinAutoUnref dummyFont(new MinikinFontForTest(kNoGlyphFont)); - MinikinAutoUnref fontA(new MinikinFontForTest(kZH_HansFont)); - MinikinAutoUnref fontB(new MinikinFontForTest(kZH_HansFont)); + std::shared_ptr dummyFont(new MinikinFontForTest(kNoGlyphFont)); + std::shared_ptr fontA(new MinikinFontForTest(kZH_HansFont)); + std::shared_ptr fontB(new MinikinFontForTest(kZH_HansFont)); - MinikinAutoUnref dummyFamily(new FontFamily( - std::vector({ Font(dummyFont.get(), FontStyle()) }))); - MinikinAutoUnref familyA(new FontFamily( - std::vector({ Font(fontA.get(), FontStyle()) }))); - MinikinAutoUnref familyB(new FontFamily( - std::vector({ Font(fontB.get(), FontStyle()) }))); + std::shared_ptr dummyFamily(new FontFamily( + std::vector({ Font(dummyFont, FontStyle()) }))); + std::shared_ptr familyA(new FontFamily( + std::vector({ Font(fontA, FontStyle()) }))); + std::shared_ptr familyB(new FontFamily( + std::vector({ Font(fontB, FontStyle()) }))); - std::vector families = - { dummyFamily.get(), familyA.get(), familyB.get() }; - std::vector reversedFamilies = - { dummyFamily.get(), familyB.get(), familyA.get() }; + std::vector> families = + { dummyFamily, familyA, familyB }; + std::vector> reversedFamilies = + { dummyFamily, familyB, familyA }; - MinikinAutoUnref collection(new FontCollection(families)); - MinikinAutoUnref reversedCollection(new FontCollection(reversedFamilies)); + std::shared_ptr collection(new FontCollection(families)); + std::shared_ptr reversedCollection(new FontCollection(reversedFamilies)); // Both fontA/fontB support U+35A8 but don't support U+35A8 U+E0100. The first font should be // selected. std::vector runs; - itemize(collection.get(), "U+35A8 U+E0100", kDefaultFontStyle, &runs); + itemize(collection, "U+35A8 U+E0100", kDefaultFontStyle, &runs); EXPECT_EQ(fontA.get(), runs[0].fakedFont.font); - itemize(reversedCollection.get(), "U+35A8 U+E0100", kDefaultFontStyle, &runs); + itemize(reversedCollection, "U+35A8 U+E0100", kDefaultFontStyle, &runs); EXPECT_EQ(fontB.get(), runs[0].fakedFont.font); } @@ -1446,34 +1441,34 @@ TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS) { TEST_F(FontCollectionItemizeTest, itemizeShouldKeepOrderForVS2) { const FontStyle kDefaultFontStyle; - MinikinAutoUnref dummyFont(new MinikinFontForTest(kNoGlyphFont)); - MinikinAutoUnref hasCmapFormat14Font( + std::shared_ptr dummyFont(new MinikinFontForTest(kNoGlyphFont)); + std::shared_ptr hasCmapFormat14Font( new MinikinFontForTest(kHasCmapFormat14Font)); - MinikinAutoUnref noCmapFormat14Font( + std::shared_ptr noCmapFormat14Font( new MinikinFontForTest(kNoCmapFormat14Font)); - MinikinAutoUnref dummyFamily(new FontFamily( - std::vector({ Font(dummyFont.get(), FontStyle()) }))); - MinikinAutoUnref hasCmapFormat14Family(new FontFamily( - std::vector({ Font(hasCmapFormat14Font.get(), FontStyle()) }))); - MinikinAutoUnref noCmapFormat14Family(new FontFamily( - std::vector({ Font(noCmapFormat14Font.get(), FontStyle()) }))); + std::shared_ptr dummyFamily(new FontFamily( + std::vector({ Font(dummyFont, FontStyle()) }))); + std::shared_ptr hasCmapFormat14Family(new FontFamily( + std::vector({ Font(hasCmapFormat14Font, FontStyle()) }))); + std::shared_ptr noCmapFormat14Family(new FontFamily( + std::vector({ Font(noCmapFormat14Font, FontStyle()) }))); - std::vector families = - { dummyFamily.get(), hasCmapFormat14Family.get(), noCmapFormat14Family.get() }; - std::vector reversedFamilies = - { dummyFamily.get(), noCmapFormat14Family.get(), hasCmapFormat14Family.get() }; + std::vector> families = + { dummyFamily, hasCmapFormat14Family, noCmapFormat14Family }; + std::vector> reversedFamilies = + { dummyFamily, noCmapFormat14Family, hasCmapFormat14Family }; - MinikinAutoUnref collection(new FontCollection(families)); - MinikinAutoUnref reversedCollection(new FontCollection(reversedFamilies)); + std::shared_ptr collection(new FontCollection(families)); + std::shared_ptr reversedCollection(new FontCollection(reversedFamilies)); // Both hasCmapFormat14Font/noCmapFormat14Font support U+5380 but don't support U+5380 U+E0100. // The first font should be selected. std::vector runs; - itemize(collection.get(), "U+5380 U+E0100", kDefaultFontStyle, &runs); + itemize(collection, "U+5380 U+E0100", kDefaultFontStyle, &runs); EXPECT_EQ(hasCmapFormat14Font.get(), runs[0].fakedFont.font); - itemize(reversedCollection.get(), "U+5380 U+E0100", kDefaultFontStyle, &runs); + itemize(reversedCollection, "U+5380 U+E0100", kDefaultFontStyle, &runs); EXPECT_EQ(noCmapFormat14Font.get(), runs[0].fakedFont.font); } diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index 68fe582aa3f..100e2069752 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -57,11 +57,11 @@ void expectVSGlyphs(const FontCollection* fc, uint32_t codepoint, const std::set } TEST(FontCollectionTest, hasVariationSelectorTest) { - MinikinAutoUnref font(new MinikinFontForTest(kVsTestFont)); - MinikinAutoUnref family(new FontFamily( - std::vector({ Font(font.get(), FontStyle()) }))); - std::vector families({family.get()}); - MinikinAutoUnref fc(new FontCollection(families)); + std::shared_ptr font(new MinikinFontForTest(kVsTestFont)); + std::shared_ptr family(new FontFamily( + std::vector({ Font(font, FontStyle()) }))); + std::vector> families({ family }); + std::shared_ptr fc(new FontCollection(families)); EXPECT_FALSE(fc->hasVariationSelector(0x82A6, 0)); expectVSGlyphs(fc.get(), 0x82A6, std::set({0xFE00, 0xE0100, 0xE0101, 0xE0102})); @@ -79,7 +79,7 @@ TEST(FontCollectionTest, hasVariationSelectorTest) { const char kEmojiXmlFile[] = kTestFontDir "emoji.xml"; TEST(FontCollectionTest, hasVariationSelectorTest_emoji) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); // Both text/color font have cmap format 14 subtable entry for VS15/VS16 respectively. EXPECT_TRUE(collection->hasVariationSelector(0x2623, 0xFE0E)); @@ -109,7 +109,7 @@ TEST(FontCollectionTest, hasVariationSelectorTest_emoji) { } TEST(FontCollectionTest, newEmojiTest) { - MinikinAutoUnref collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); + std::shared_ptr collection(getFontCollection(kTestFontDir, kEmojiXmlFile)); // U+2695, U+2640, U+2642 are not in emoji catrgory in Unicode 9 but they are now in emoji // category. Should return true even if U+FE0E was appended. @@ -126,17 +126,17 @@ TEST(FontCollectionTest, createWithVariations) { const char kMultiAxisFont[] = kTestFontDir "/MultiAxis.ttf"; const char kNoAxisFont[] = kTestFontDir "/Regular.ttf"; - MinikinAutoUnref multiAxisFont(new MinikinFontForTest(kMultiAxisFont)); - MinikinAutoUnref multiAxisFamily(new FontFamily( - std::vector({ Font(multiAxisFont.get(), FontStyle()) }))); - std::vector multiAxisFamilies({multiAxisFamily.get()}); - MinikinAutoUnref multiAxisFc(new FontCollection(multiAxisFamilies)); + std::shared_ptr multiAxisFont(new MinikinFontForTest(kMultiAxisFont)); + std::shared_ptr multiAxisFamily(new FontFamily( + std::vector({ Font(multiAxisFont, FontStyle()) }))); + std::vector> multiAxisFamilies({multiAxisFamily}); + std::shared_ptr multiAxisFc(new FontCollection(multiAxisFamilies)); - MinikinAutoUnref noAxisFont(new MinikinFontForTest(kNoAxisFont)); - MinikinAutoUnref noAxisFamily(new FontFamily( - std::vector({ Font(noAxisFont.get(), FontStyle()) }))); - std::vector noAxisFamilies({noAxisFamily.get()}); - MinikinAutoUnref noAxisFc(new FontCollection(noAxisFamilies)); + std::shared_ptr noAxisFont(new MinikinFontForTest(kNoAxisFont)); + std::shared_ptr noAxisFamily(new FontFamily( + std::vector({ Font(noAxisFont, FontStyle()) }))); + std::vector> noAxisFamilies({noAxisFamily}); + std::shared_ptr noAxisFc(new FontCollection(noAxisFamilies)); { // Do not ceate new instance if none of variations are specified. @@ -150,7 +150,7 @@ TEST(FontCollectionTest, createWithVariations) { std::vector variations = { { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f } }; - MinikinAutoUnref newFc( + std::shared_ptr newFc( multiAxisFc->createCollectionWithVariation(variations)); EXPECT_NE(nullptr, newFc.get()); EXPECT_NE(multiAxisFc.get(), newFc.get()); @@ -163,7 +163,7 @@ TEST(FontCollectionTest, createWithVariations) { { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, { MinikinFont::MakeTag('w', 'g', 'h', 't'), 1.0f } }; - MinikinAutoUnref newFc( + std::shared_ptr newFc( multiAxisFc->createCollectionWithVariation(variations)); EXPECT_NE(nullptr, newFc.get()); EXPECT_NE(multiAxisFc.get(), newFc.get()); @@ -184,7 +184,7 @@ TEST(FontCollectionTest, createWithVariations) { { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, { MinikinFont::MakeTag('Z', 'Z', 'Z', 'Z'), 1.0f } }; - MinikinAutoUnref newFc( + std::shared_ptr newFc( multiAxisFc->createCollectionWithVariation(variations)); EXPECT_NE(nullptr, newFc.get()); EXPECT_NE(multiAxisFc.get(), newFc.get()); diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index fb917500f07..5285f2642b4 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -529,12 +529,9 @@ void expectVSGlyphs(FontFamily* family, uint32_t codepoint, const std::set - minikinFont(new MinikinFontForTest(kVsTestFont)); - MinikinAutoUnref family( - new FontFamily(std::vector{ - Font(minikinFont.get(), FontStyle()) - })); + std::shared_ptr minikinFont(new MinikinFontForTest(kVsTestFont)); + std::shared_ptr family( + new FontFamily(std::vector{ Font(minikinFont, FontStyle()) })); android::AutoMutex _l(gMinikinLock); @@ -585,10 +582,10 @@ TEST_F(FontFamilyTest, hasVSTableTest) { "Font " + testCase.fontPath + " should have a variation sequence table." : "Font " + testCase.fontPath + " shouldn't have a variation sequence table."); - MinikinAutoUnref minikinFont( + std::shared_ptr minikinFont( new MinikinFontForTest(testCase.fontPath)); - MinikinAutoUnref family(new FontFamily( - std::vector{ Font(minikinFont.get(), FontStyle()) })); + std::shared_ptr family(new FontFamily( + std::vector{ Font(minikinFont, FontStyle()) })); android::AutoMutex _l(gMinikinLock); EXPECT_EQ(testCase.hasVSTable, family->hasVSTable()); } @@ -599,13 +596,15 @@ TEST_F(FontFamilyTest, createFamilyWithVariationTest) { const char kMultiAxisFont[] = kTestFontDir "/MultiAxis.ttf"; const char kNoAxisFont[] = kTestFontDir "/Regular.ttf"; - MinikinAutoUnref multiAxisFont(new MinikinFontForTest(kMultiAxisFont)); - MinikinAutoUnref multiAxisFamily(new FontFamily( - std::vector({Font(multiAxisFont.get(), FontStyle())}))); + std::shared_ptr multiAxisFont(new MinikinFontForTest(kMultiAxisFont)); + std::shared_ptr multiAxisFamily( + std::shared_ptr(new FontFamily( + std::vector({Font(multiAxisFont, FontStyle())})))); - MinikinAutoUnref noAxisFont(new MinikinFontForTest(kNoAxisFont)); - MinikinAutoUnref noAxisFamily(new FontFamily( - std::vector({Font(noAxisFont.get(), FontStyle())}))); + std::shared_ptr noAxisFont(new MinikinFontForTest(kNoAxisFont)); + std::shared_ptr noAxisFamily( + std::shared_ptr(new FontFamily( + std::vector({Font(noAxisFont, FontStyle())})))); { // Do not ceate new instance if none of variations are specified. @@ -617,7 +616,7 @@ TEST_F(FontFamilyTest, createFamilyWithVariationTest) { { // New instance should be used for supported variation. std::vector variations = {{MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f}}; - MinikinAutoUnref newFamily( + std::shared_ptr newFamily( multiAxisFamily->createFamilyWithVariation(variations)); EXPECT_NE(nullptr, newFamily.get()); EXPECT_NE(multiAxisFamily.get(), newFamily.get()); @@ -629,7 +628,7 @@ TEST_F(FontFamilyTest, createFamilyWithVariationTest) { { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, { MinikinFont::MakeTag('w', 'g', 'h', 't'), 1.0f } }; - MinikinAutoUnref newFamily( + std::shared_ptr newFamily( multiAxisFamily->createFamilyWithVariation(variations)); EXPECT_NE(nullptr, newFamily.get()); EXPECT_NE(multiAxisFamily.get(), newFamily.get()); @@ -649,7 +648,7 @@ TEST_F(FontFamilyTest, createFamilyWithVariationTest) { { MinikinFont::MakeTag('w', 'd', 't', 'h'), 1.0f }, { MinikinFont::MakeTag('Z', 'Z', 'Z', 'Z'), 1.0f } }; - MinikinAutoUnref newFamily( + std::shared_ptr newFamily( multiAxisFamily->createFamilyWithVariation(variations)); EXPECT_NE(nullptr, newFamily.get()); EXPECT_NE(multiAxisFamily.get(), newFamily.get()); diff --git a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp index 9a7e63fb2c0..a5581a27b88 100644 --- a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp @@ -20,6 +20,8 @@ #include #include +#include + #include #include "MinikinInternal.h" @@ -37,13 +39,13 @@ public: }; TEST_F(HbFontCacheTest, getHbFontLockedTest) { - MinikinAutoUnref fontA( + std::shared_ptr fontA( new MinikinFontForTest(kTestFontDir "Regular.ttf")); - MinikinAutoUnref fontB( + std::shared_ptr fontB( new MinikinFontForTest(kTestFontDir "Bold.ttf")); - MinikinAutoUnref fontC( + std::shared_ptr fontC( new MinikinFontForTest(kTestFontDir "BoldItalic.ttf")); android::AutoMutex _l(gMinikinLock); @@ -65,7 +67,7 @@ TEST_F(HbFontCacheTest, getHbFontLockedTest) { } TEST_F(HbFontCacheTest, purgeCacheTest) { - MinikinAutoUnref minikinFont( + std::shared_ptr minikinFont( new MinikinFontForTest(kTestFontDir "Regular.ttf")); android::AutoMutex _l(gMinikinLock); diff --git a/engine/src/flutter/tests/unittest/LayoutTest.cpp b/engine/src/flutter/tests/unittest/LayoutTest.cpp index c023625b16f..4a849aa3ebc 100644 --- a/engine/src/flutter/tests/unittest/LayoutTest.cpp +++ b/engine/src/flutter/tests/unittest/LayoutTest.cpp @@ -53,14 +53,14 @@ protected: virtual ~LayoutTest() {} virtual void SetUp() override { - mCollection = getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML); + mCollection = std::shared_ptr( + getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); } virtual void TearDown() override { - mCollection->Unref(); } - FontCollection* mCollection; + std::shared_ptr mCollection; }; TEST_F(LayoutTest, doLayoutTest) { @@ -70,8 +70,7 @@ TEST_F(LayoutTest, doLayoutTest) { float advances[kMaxAdvanceLength]; std::vector expectedValues; - Layout layout; - layout.setFontCollection(mCollection); + Layout layout(mCollection); std::vector text; // The mock implementation returns 10.0f advance and 0,0-10x10 bounds for all glyph. @@ -157,8 +156,7 @@ TEST_F(LayoutTest, doLayoutTest_wordSpacing) { std::vector expectedValues; std::vector text; - Layout layout; - layout.setFontCollection(mCollection); + Layout layout(mCollection); paint.wordSpacing = 5.0f; @@ -252,8 +250,7 @@ TEST_F(LayoutTest, doLayoutTest_negativeWordSpacing) { float advances[kMaxAdvanceLength]; std::vector expectedValues; - Layout layout; - layout.setFontCollection(mCollection); + Layout layout(mCollection); std::vector text; // Negative word spacing also should work. @@ -338,6 +335,27 @@ TEST_F(LayoutTest, doLayoutTest_negativeWordSpacing) { } } +TEST_F(LayoutTest, doLayoutTest_rtlTest) { + MinikinPaint paint; + + std::vector text = parseUnicodeString("'a' 'b' U+3042 U+3043 'c' 'd'"); + + Layout ltrLayout(mCollection); + ltrLayout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + + Layout rtlLayout(mCollection); + rtlLayout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_RTL, FontStyle(), paint); + + ASSERT_EQ(ltrLayout.nGlyphs(), rtlLayout.nGlyphs()); + ASSERT_EQ(6u, ltrLayout.nGlyphs()); + + size_t nGlyphs = ltrLayout.nGlyphs(); + for (size_t i = 0; i < nGlyphs; ++i) { + EXPECT_EQ(ltrLayout.getFont(i), rtlLayout.getFont(nGlyphs - i - 1)); + EXPECT_EQ(ltrLayout.getGlyphId(i), rtlLayout.getGlyphId(nGlyphs - i - 1)); + } +} + // TODO: Add more test cases, e.g. measure text, letter spacing. } // namespace minikin diff --git a/engine/src/flutter/tests/util/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp index e29a2fe5344..27a693e16dc 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.cpp +++ b/engine/src/flutter/tests/util/FontTestUtils.cpp @@ -32,7 +32,7 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { xmlDoc* doc = xmlReadFile(fontXml, NULL, 0); xmlNode* familySet = xmlDocGetRootElement(doc); - std::vector families; + std::vector> families; for (xmlNode* familyNode = familySet->children; familyNode; familyNode = familyNode->next) { if (xmlStrcmp(familyNode->name, (const xmlChar*)"family") != 0) { continue; @@ -69,34 +69,29 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { } if (index == nullptr) { - MinikinAutoUnref - minikinFont(new MinikinFontForTest(fontPath)); - fonts.push_back(Font(minikinFont.get(), FontStyle(weight, italic))); + std::shared_ptr minikinFont(new MinikinFontForTest(fontPath)); + fonts.push_back(Font(minikinFont, FontStyle(weight, italic))); } else { - MinikinAutoUnref - minikinFont(new MinikinFontForTest(fontPath, atoi((const char*)index))); - fonts.push_back(Font(minikinFont.get(), FontStyle(weight, italic))); + std::shared_ptr minikinFont( + new MinikinFontForTest(fontPath, atoi((const char*)index))); + fonts.push_back(Font(minikinFont, FontStyle(weight, italic))); } } xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); - FontFamily* family; + std::shared_ptr family; if (lang == nullptr) { - family = new FontFamily(variant, std::move(fonts)); + family.reset(new FontFamily(variant, std::move(fonts))); } else { uint32_t langId = FontStyle::registerLanguageList( std::string((const char*)lang, xmlStrlen(lang))); - family = new FontFamily(langId, variant, std::move(fonts)); + family.reset(new FontFamily(langId, variant, std::move(fonts))); } families.push_back(family); } xmlFreeDoc(doc); - FontCollection* collection = new FontCollection(families); - for (size_t i = 0; i < families.size(); ++i) { - families[i]->Unref(); - } - return collection; + return new FontCollection(families); } } // namespace minikin diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.cpp b/engine/src/flutter/tests/util/MinikinFontForTest.cpp index f191f07d6e9..723e86ac2d2 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.cpp +++ b/engine/src/flutter/tests/util/MinikinFontForTest.cpp @@ -69,9 +69,9 @@ void MinikinFontForTest::GetBounds(MinikinRect* bounds, uint32_t /* glyph_id */, bounds->mBottom = 10.0f; } -MinikinFont* MinikinFontForTest::createFontWithVariation( +std::shared_ptr MinikinFontForTest::createFontWithVariation( const std::vector& variations) const { - return new MinikinFontForTest(mFontPath, mFontIndex, variations); + return std::shared_ptr(new MinikinFontForTest(mFontPath, mFontIndex, variations)); } } // namespace minikin diff --git a/engine/src/flutter/tests/util/MinikinFontForTest.h b/engine/src/flutter/tests/util/MinikinFontForTest.h index 1d0628319bb..6e230e1d319 100644 --- a/engine/src/flutter/tests/util/MinikinFontForTest.h +++ b/engine/src/flutter/tests/util/MinikinFontForTest.h @@ -43,7 +43,8 @@ public: size_t GetFontSize() const { return mFontSize; } int GetFontIndex() const { return mFontIndex; } const std::vector& GetAxes() const { return mVariations; } - MinikinFont* createFontWithVariation(const std::vector& variations) const; + std::shared_ptr createFontWithVariation( + const std::vector& variations) const; private: MinikinFontForTest() = delete; MinikinFontForTest(const MinikinFontForTest&) = delete; diff --git a/engine/src/flutter/tests/util/UnicodeUtils.cpp b/engine/src/flutter/tests/util/UnicodeUtils.cpp index 2f811daec25..e66ff934893 100644 --- a/engine/src/flutter/tests/util/UnicodeUtils.cpp +++ b/engine/src/flutter/tests/util/UnicodeUtils.cpp @@ -88,6 +88,17 @@ void ParseUnicode(uint16_t* buf, size_t buf_size, const char* src, size_t* resul LOG_ALWAYS_FATAL_IF(!seen_offset && offset != nullptr); } +std::vector parseUnicodeStringWithOffset(const std::string& in, size_t* offset) { + std::unique_ptr buffer(new uint16_t[in.size()]); + size_t result_size = 0; + ParseUnicode(buffer.get(), in.size(), in.c_str(), &result_size, offset); + return std::vector(buffer.get(), buffer.get() + result_size); +} + +std::vector parseUnicodeString(const std::string& in) { + return parseUnicodeStringWithOffset(in, nullptr); +} + std::vector utf8ToUtf16(const std::string& text) { std::vector result; int32_t i = 0; diff --git a/engine/src/flutter/tests/util/UnicodeUtils.h b/engine/src/flutter/tests/util/UnicodeUtils.h index 571be7a31ef..6ce2fcbd90e 100644 --- a/engine/src/flutter/tests/util/UnicodeUtils.h +++ b/engine/src/flutter/tests/util/UnicodeUtils.h @@ -19,6 +19,9 @@ namespace minikin { void ParseUnicode(uint16_t* buf, size_t buf_size, const char* src, size_t* result_size, size_t* offset); +std::vector parseUnicodeStringWithOffset(const std::string& in, size_t* offset); +std::vector parseUnicodeString(const std::string& in); + // Converts UTF-8 to UTF-16. std::vector utf8ToUtf16(const std::string& text); From 131392748fe6b4d14a4dcbf3f5c79e56b2f0f142 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 22 Feb 2017 18:48:18 -0800 Subject: [PATCH 235/364] Add exception for Bulgarian to mk_hyb_file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Bulgarian hyphenation patterns contain a line consisting of '0ь0' which has no practical effect on hyphenation. Add an exception in roundtrip testing to make sure we don't fail while comparing our tables with the input data. Test: make -j works and creates .hyb files for bg and cu Change-Id: Ia46b8a45fe522f5194d8105d31b34b0e27528cc9 (cherry picked from commit 6308ea4c4b4652f061a646d164d5fdc941a25ba2) --- engine/src/flutter/tools/mk_hyb_file.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/engine/src/flutter/tools/mk_hyb_file.py b/engine/src/flutter/tools/mk_hyb_file.py index 978c082b279..a9b8932c95f 100755 --- a/engine/src/flutter/tools/mk_hyb_file.py +++ b/engine/src/flutter/tools/mk_hyb_file.py @@ -539,6 +539,12 @@ def verify_hyb_file(hyb_fn, pat_fn, chr_fn, hyp_fn): patterns = [] exceptions = [] traverse_trie(0, '', trie_data, ch_map, pattern_data, patterns, exceptions) + + # EXCEPTION for Bulgarian (bg), which contains an ineffectual line of <0, U+044C, 0> + if u'\u044c' in patterns: + patterns.remove(u'\u044c') + patterns.append(u'0\u044c0') + assert verify_file_sorted(patterns, pat_fn), 'pattern table not verified' assert verify_file_sorted(exceptions, hyp_fn), 'exception table not verified' From 319073941ed7f9523960872fd1b73d615f3ce52b Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Fri, 17 Feb 2017 18:55:02 -0800 Subject: [PATCH 236/364] Correct hyphenation for various complex cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds better support for Arabic script languages, Armenian, Catalan, Hebrew, Kannada, Malayalam, Polish, Tamil, and Telugu by adding various hyphenation types and edits appropriate for the locales. For Arabic script languages, soft hyphens act transparently with regard to joining: If a line is broken at a soft hyphen where the two characters around the soft hyphen were joining each other before, they will continue to appear joining if the line is broken at the soft hyphen and a hyphen glyph is inserted. This is needed for Central Asian languages such as Uighur. For Armenian, U+058A ARMENIAN HYPHEN is used for line breaks caused by either automatic hyphenation or soft hyphens. For Catalan, nonstandard line breaks are implemented for "l·l", which hyphenates as "l-/l". For Polish, when there is a line break at a hyphen, the hyphen is repeated at the next line. For the South Indic languages, when breaks happen due to soft breaks or automatic hyphenation, no visible hyphen is inserted, although a penalty is added. For Hebrew, support for using U+05BE HEBREW PUNCTUATION MAQAF has been implemented, but it's turned off pending confirmation of desirability. Also, hard hyphens, which previously had no penalty added for breaking the line after them, now have the same penalty as an automatic or soft break, with the difference that no hyphen is inserted when they break. Finally, some bugs have been fixed with hyphenating multiscript and multi-font words. Bug: 19950445 Bug: 19955011 Bug: 25623243 Bug: 26154469 Bug: 26154471 Bug: 33387871 Bug: 33560754 Bug: 33752592 Bug: 33754204 Test: Unit tests added, plus thorough manual testing Change-Id: Iaccf776ce8d1d434ee8b1c534ff3659d80fdc338 --- engine/src/flutter/app/HyphTool.cpp | 8 +- .../src/flutter/include/minikin/Hyphenator.h | 124 ++++++- .../src/flutter/include/minikin/LineBreaker.h | 9 +- .../src/flutter/include/minikin/MinikinFont.h | 14 +- .../flutter/libs/minikin/FontCollection.cpp | 7 +- .../src/flutter/libs/minikin/Hyphenator.cpp | 244 +++++++++++-- engine/src/flutter/libs/minikin/Layout.cpp | 219 ++++++++++-- .../src/flutter/libs/minikin/LineBreaker.cpp | 74 ++-- .../src/flutter/libs/minikin/WordBreaker.cpp | 4 +- .../flutter/tests/perftests/Hyphenator.cpp | 9 +- engine/src/flutter/tests/unittest/Android.mk | 2 + .../flutter/tests/unittest/HyphenatorTest.cpp | 335 ++++++++++++++++++ .../src/flutter/tests/unittest/LayoutTest.cpp | 47 +++ .../tests/unittest/WordBreakerTests.cpp | 49 ++- 14 files changed, 985 insertions(+), 160 deletions(-) create mode 100644 engine/src/flutter/tests/unittest/HyphenatorTest.cpp diff --git a/engine/src/flutter/app/HyphTool.cpp b/engine/src/flutter/app/HyphTool.cpp index 88245fea33d..cdb1466f409 100644 --- a/engine/src/flutter/app/HyphTool.cpp +++ b/engine/src/flutter/app/HyphTool.cpp @@ -2,11 +2,13 @@ #include #include +#include "unicode/locid.h" #include "utils/Log.h" #include #include +using minikin::HyphenationType; using minikin::Hyphenator; Hyphenator* loadHybFile(const char* fn) { @@ -35,7 +37,7 @@ Hyphenator* loadHybFile(const char* fn) { int main(int argc, char** argv) { Hyphenator* hyph = loadHybFile("/tmp/en.hyb"); // should also be configurable - std::vector result; + std::vector result; std::vector word; if (argc < 2) { fprintf(stderr, "usage: hyphtool word\n"); @@ -51,9 +53,9 @@ int main(int argc, char** argv) { // ASCII (or possibly ISO Latin 1), but kinda painful to do utf conversion :( word.push_back(c); } - hyph->hyphenate(&result, word.data(), word.size()); + hyph->hyphenate(&result, word.data(), word.size(), icu::Locale::getUS()); for (size_t i = 0; i < len; i++) { - if (result[i] != 0) { + if (result[i] != HyphenationType::DONT_BREAK) { printf("-"); } printf("%c", word[i]); diff --git a/engine/src/flutter/include/minikin/Hyphenator.h b/engine/src/flutter/include/minikin/Hyphenator.h index f922dcbfb79..ea81813745a 100644 --- a/engine/src/flutter/include/minikin/Hyphenator.h +++ b/engine/src/flutter/include/minikin/Hyphenator.h @@ -18,6 +18,7 @@ * An implementation of Liang's hyphenation algorithm. */ +#include "unicode/locid.h" #include #include @@ -26,38 +27,131 @@ namespace minikin { +enum class HyphenationType : uint8_t { + // Note: There are implicit assumptions scattered in the code that DONT_BREAK is 0. + + // Do not break. + DONT_BREAK = 0, + // Break the line and insert a normal hyphen. + BREAK_AND_INSERT_HYPHEN = 1, + // Break the line and insert an Armenian hyphen (U+058A). + BREAK_AND_INSERT_ARMENIAN_HYPHEN = 2, + // Break the line and insert a maqaf (Hebrew hyphen, U+05BE). + BREAK_AND_INSERT_MAQAF = 3, + // Break the line and insert a Canadian Syllabics hyphen (U+1400). + BREAK_AND_INSERT_UCAS_HYPHEN = 4, + // Break the line, but don't insert a hyphen. Used for cases when there is already a hyphen + // present or the script does not use a hyphen (e.g. in Malayalam). + BREAK_AND_DONT_INSERT_HYPHEN = 5, + // Break and replace the last code unit with hyphen. Used for Catalan "l·l" which hyphenates + // as "l-/l". + BREAK_AND_REPLACE_WITH_HYPHEN = 6, + // Break the line, and repeat the hyphen (which is the last character) at the beginning of the + // next line. Used in Polish, where "czerwono-niebieska" should hyphenate as + // "czerwono-/-niebieska". + BREAK_AND_INSERT_HYPHEN_AT_NEXT_LINE = 7, + // Break the line, insert a ZWJ and hyphen at the first line, and a ZWJ at the second line. + // This is used in Arabic script, mostly for writing systems of Central Asia. It's our default + // behavior when a soft hyphen is used in Arabic script. + BREAK_AND_INSERT_HYPHEN_AND_ZWJ = 8 +}; + +// The hyphen edit represents an edit to the string when a word is +// hyphenated. The most common hyphen edit is adding a "-" at the end +// of a syllable, but nonstandard hyphenation allows for more choices. +// Note that a HyphenEdit can hold two types of edits at the same time, +// One at the beginning of the string/line and one at the end. +class HyphenEdit { +public: + static const uint32_t NO_EDIT = 0x00; + + static const uint32_t INSERT_HYPHEN_AT_END = 0x01; + static const uint32_t INSERT_ARMENIAN_HYPHEN_AT_END = 0x02; + static const uint32_t INSERT_MAQAF_AT_END = 0x03; + static const uint32_t INSERT_UCAS_HYPHEN_AT_END = 0x04; + static const uint32_t INSERT_ZWJ_AND_HYPHEN_AT_END = 0x05; + static const uint32_t REPLACE_WITH_HYPHEN_AT_END = 0x06; + static const uint32_t BREAK_AT_END = 0x07; + + static const uint32_t INSERT_HYPHEN_AT_START = 0x01 << 3; + static const uint32_t INSERT_ZWJ_AT_START = 0x02 << 3; + static const uint32_t BREAK_AT_START = 0x03 << 3; + + // Keep in sync with the definitions in the Java code at: + // frameworks/base/graphics/java/android/graphics/Paint.java + static const uint32_t MASK_END_OF_LINE = 0x07; + static const uint32_t MASK_START_OF_LINE = 0x03 << 3; + + inline static bool isReplacement(uint32_t hyph) { + return hyph == REPLACE_WITH_HYPHEN_AT_END; + } + + inline static bool isInsertion(uint32_t hyph) { + return (hyph == INSERT_HYPHEN_AT_END + || hyph == INSERT_ARMENIAN_HYPHEN_AT_END + || hyph == INSERT_MAQAF_AT_END + || hyph == INSERT_UCAS_HYPHEN_AT_END + || hyph == INSERT_ZWJ_AND_HYPHEN_AT_END + || hyph == INSERT_HYPHEN_AT_START + || hyph == INSERT_ZWJ_AT_START); + } + + const static uint32_t* getHyphenString(uint32_t hyph); + static uint32_t editForThisLine(HyphenationType type); + static uint32_t editForNextLine(HyphenationType type); + + HyphenEdit() : hyphen(NO_EDIT) { } + HyphenEdit(uint32_t hyphenInt) : hyphen(hyphenInt) { } // NOLINT(implicit) + uint32_t getHyphen() const { return hyphen; } + bool operator==(const HyphenEdit &other) const { return hyphen == other.hyphen; } + + uint32_t getEnd() const { return hyphen & MASK_END_OF_LINE; } + uint32_t getStart() const { return hyphen & MASK_START_OF_LINE; } + +private: + uint32_t hyphen; +}; + // hyb file header; implementation details are in the .cpp file struct Header; class Hyphenator { public: - // Note: this will also require a locale, for proper case folding behavior - static Hyphenator* load(const uint16_t* patternData, size_t size); + // Compute the hyphenation of a word, storing the hyphenation in result vector. Each entry in + // the vector is a "hyphenation type" for a potential hyphenation that can be applied at the + // corresponding code unit offset in the word. + // + // Example: word is "hyphen", result is the following, corresponding to "hy-phen": + // [DONT_BREAK, DONT_BREAK, BREAK_AND_INSERT_HYPHEN, DONT_BREAK, DONT_BREAK, DONT_BREAK] + void hyphenate(std::vector* result, const uint16_t* word, size_t len, + const icu::Locale& locale); - // Compute the hyphenation of a word, storing the hyphenation in result vector. Each - // entry in the vector is a "hyphen edit" to be applied at the corresponding code unit - // offset in the word. Currently 0 means no hyphen and 1 means insert hyphen and break, - // but this will be expanded to other edits for nonstandard hyphenation. - // Example: word is "hyphen", result is [0 0 1 0 0 0], corresponding to "hy-phen". - void hyphenate(std::vector* result, const uint16_t* word, size_t len); + // Returns true if the codepoint is like U+2010 HYPHEN in line breaking and usage: a character + // immediately after which line breaks are allowed, but words containing it should not be + // automatically hyphenated. + static bool isLineBreakingHyphen(uint32_t cp); // pattern data is in binary format, as described in doc/hyb_file_format.md. Note: // the caller is responsible for ensuring that the lifetime of the pattern data is // at least as long as the Hyphenator object. - // Note: nullptr is valid input, in which case the hyphenator only processes soft hyphens + // Note: nullptr is valid input, in which case the hyphenator only processes soft hyphens. static Hyphenator* loadBinary(const uint8_t* patternData); private: - // apply soft hyphens only, ignoring patterns - void hyphenateSoft(uint8_t* result, const uint16_t* word, size_t len); + // apply various hyphenation rules including hard and soft hyphens, ignoring patterns + void hyphenateWithNoPatterns(HyphenationType* result, const uint16_t* word, size_t len, + const icu::Locale& locale); - // try looking up word in alphabet table, return false if any code units fail to map - // Note that this methor writes len+2 entries into alpha_codes (including start and stop) - bool alphabetLookup(uint16_t* alpha_codes, const uint16_t* word, size_t len); + // Try looking up word in alphabet table, return DONT_BREAK if any code units fail to map. + // Otherwise, returns BREAK_AND_INSERT_HYPHEN, BREAK_AND_INSERT_ARMENIAN_HYPHEN, or + // BREAK_AND_DONT_INSERT_HYPHEN based on the the script of the characters seen. + // Note that this method writes len+2 entries into alpha_codes (including start and stop) + HyphenationType alphabetLookup(uint16_t* alpha_codes, const uint16_t* word, size_t len); // calculate hyphenation from patterns, assuming alphabet lookup has already been done - void hyphenateFromCodes(uint8_t* result, const uint16_t* codes, size_t len); + void hyphenateFromCodes(HyphenationType* result, const uint16_t* codes, size_t len, + HyphenationType hyphenValue); // TODO: these should become parameters, as they might vary by locale, screen size, and // possibly explicit user control. diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index e93953666be..ce8eb7d571a 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -198,18 +198,18 @@ class LineBreaker { size_t lineNumber; // only updated for non-constant line widths size_t preSpaceCount; // preceding space count before breaking size_t postSpaceCount; // preceding space count after breaking - uint8_t hyphenEdit; + HyphenationType hyphenType; }; float currentLineWidth() const; void addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth postBreak, - size_t preSpaceCount, size_t postSpaceCount, float penalty, uint8_t hyph); + size_t preSpaceCount, size_t postSpaceCount, float penalty, HyphenationType hyph); void addCandidate(Candidate cand); // push an actual break to the output. Takes care of setting flags for tab - void pushBreak(int offset, float width, uint8_t hyph); + void pushBreak(int offset, float width, uint8_t hyphenEdit); float getSpaceWidth() const; @@ -220,11 +220,12 @@ class LineBreaker { void finishBreaksOptimal(); WordBreaker mWordBreaker; + icu::Locale mLocale; std::vectormTextBuf; std::vectormCharWidths; Hyphenator* mHyphenator; - std::vector mHyphBuf; + std::vector mHyphBuf; // layout parameters BreakStrategy mStrategy = kBreakStrategy_Greedy; diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 1d5ebb774a8..52263f529a2 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -21,25 +21,13 @@ #include #include +#include // An abstraction for platform fonts, allowing Minikin to be used with // multiple actual implementations of fonts. namespace minikin { -// The hyphen edit represents an edit to the string when a word is -// hyphenated. The most common hyphen edit is adding a "-" at the end -// of a syllable, but nonstandard hyphenation allows for more choices. -class HyphenEdit { -public: - HyphenEdit() : hyphen(0) { } - HyphenEdit(uint32_t hyphenInt) : hyphen(hyphenInt) { } // NOLINT(implicit) - bool hasHyphen() const { return hyphen != 0; } - bool operator==(const HyphenEdit &other) const { return hyphen == other.hyphen; } -private: - uint32_t hyphen; -}; - class MinikinFont; // Possibly move into own .h file? diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index c351c3a58dc..8ec302b5eab 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -328,7 +328,8 @@ const std::shared_ptr& FontCollection::getFamilyForChar(uint32_t ch, return familyVec[bestFamilyIndex]; } -const uint32_t NBSP = 0xA0; +const uint32_t NBSP = 0x00A0; +const uint32_t SOFT_HYPHEN = 0x00AD; const uint32_t ZWJ = 0x200C; const uint32_t ZWNJ = 0x200D; const uint32_t HYPHEN = 0x2010; @@ -421,8 +422,8 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty if (isStickyWhitelisted(ch)) { // Continue using existing font as long as it has coverage and is whitelisted shouldContinueRun = lastFamily->getCoverage().get(ch); - } else if (isVariationSelector(ch)) { - // Always continue if the character is a variation selector. + } else if (ch == SOFT_HYPHEN || isVariationSelector(ch)) { + // Always continue if the character is the soft hyphen or a variation selector. shouldContinueRun = true; } } diff --git a/engine/src/flutter/libs/minikin/Hyphenator.cpp b/engine/src/flutter/libs/minikin/Hyphenator.cpp index c170c6bd483..5ec82feb506 100644 --- a/engine/src/flutter/libs/minikin/Hyphenator.cpp +++ b/engine/src/flutter/libs/minikin/Hyphenator.cpp @@ -19,6 +19,7 @@ #include #include #include +#include // HACK: for reading pattern file #include @@ -32,7 +33,10 @@ using std::vector; namespace minikin { +static const uint16_t CHAR_HYPHEN_MINUS = 0x002D; static const uint16_t CHAR_SOFT_HYPHEN = 0x00AD; +static const uint16_t CHAR_MIDDLE_DOT = 0x00B7; +static const uint16_t CHAR_HYPHEN = 0x2010; // The following are structs that correspond to tables inside the hyb file format @@ -110,34 +114,216 @@ Hyphenator* Hyphenator::loadBinary(const uint8_t* patternData) { return result; } -void Hyphenator::hyphenate(vector* result, const uint16_t* word, size_t len) { +void Hyphenator::hyphenate(vector* result, const uint16_t* word, size_t len, + const icu::Locale& locale) { result->clear(); result->resize(len); const size_t paddedLen = len + 2; // start and stop code each count for 1 if (patternData != nullptr && (int)len >= MIN_PREFIX + MIN_SUFFIX && paddedLen <= MAX_HYPHENATED_SIZE) { uint16_t alpha_codes[MAX_HYPHENATED_SIZE]; - if (alphabetLookup(alpha_codes, word, len)) { - hyphenateFromCodes(result->data(), alpha_codes, paddedLen); + const HyphenationType hyphenValue = alphabetLookup(alpha_codes, word, len); + if (hyphenValue != HyphenationType::DONT_BREAK) { + hyphenateFromCodes(result->data(), alpha_codes, paddedLen, hyphenValue); return; } // TODO: try NFC normalization // TODO: handle non-BMP Unicode (requires remapping of offsets) } - hyphenateSoft(result->data(), word, len); + // Note that we will always get here if the word contains a hyphen or a soft hyphen, because the + // alphabet is not expected to contain a hyphen or a soft hyphen character, so alphabetLookup + // would return DONT_BREAK. + hyphenateWithNoPatterns(result->data(), word, len, locale); } -// If any soft hyphen is present in the word, use soft hyphens to decide hyphenation, -// as recommended in UAX #14 (Use of Soft Hyphen) -void Hyphenator::hyphenateSoft(uint8_t* result, const uint16_t* word, size_t len) { - result[0] = 0; +// This function determines whether a character is like U+2010 HYPHEN in +// line breaking and usage: a character immediately after which line breaks +// are allowed, but words containing it should not be automatically +// hyphenated using patterns. This is a curated set, created by manually +// inspecting all the characters that have the Unicode line breaking +// property of BA or HY and seeing which ones are hyphens. +bool Hyphenator::isLineBreakingHyphen(uint32_t c) { + return (c == 0x002D || // HYPHEN-MINUS + c == 0x058A || // ARMENIAN HYPHEN + c == 0x05BE || // HEBREW PUNCTUATION MAQAF + c == 0x1400 || // CANADIAN SYLLABICS HYPHEN + c == 0x2010 || // HYPHEN + c == 0x2013 || // EN DASH + c == 0x2027 || // HYPHENATION POINT + c == 0x2E17 || // DOUBLE OBLIQUE HYPHEN + c == 0x2E40); // DOUBLE HYPHEN +} + +const static uint32_t HYPHEN_STR[] = {0x2010, 0}; +const static uint32_t ARMENIAN_HYPHEN_STR[] = {0x058A, 0}; +const static uint32_t MAQAF_STR[] = {0x05BE, 0}; +const static uint32_t UCAS_HYPHEN_STR[] = {0x1400, 0}; +const static uint32_t ZWJ_STR[] = {0x200D, 0}; +const static uint32_t ZWJ_AND_HYPHEN_STR[] = {0x200D, 0x2010, 0}; + +const uint32_t* HyphenEdit::getHyphenString(uint32_t hyph) { + switch (hyph) { + case INSERT_HYPHEN_AT_END: + case REPLACE_WITH_HYPHEN_AT_END: + case INSERT_HYPHEN_AT_START: + return HYPHEN_STR; + case INSERT_ARMENIAN_HYPHEN_AT_END: + return ARMENIAN_HYPHEN_STR; + case INSERT_MAQAF_AT_END: + return MAQAF_STR; + case INSERT_UCAS_HYPHEN_AT_END: + return UCAS_HYPHEN_STR; + case INSERT_ZWJ_AND_HYPHEN_AT_END: + return ZWJ_AND_HYPHEN_STR; + case INSERT_ZWJ_AT_START: + return ZWJ_STR; + default: + return nullptr; + } +} + +uint32_t HyphenEdit::editForThisLine(HyphenationType type) { + switch (type) { + case HyphenationType::DONT_BREAK: + return NO_EDIT; + case HyphenationType::BREAK_AND_INSERT_HYPHEN: + return INSERT_HYPHEN_AT_END; + case HyphenationType::BREAK_AND_INSERT_ARMENIAN_HYPHEN: + return INSERT_ARMENIAN_HYPHEN_AT_END; + case HyphenationType::BREAK_AND_INSERT_MAQAF: + return INSERT_MAQAF_AT_END; + case HyphenationType::BREAK_AND_INSERT_UCAS_HYPHEN: + return INSERT_UCAS_HYPHEN_AT_END; + case HyphenationType::BREAK_AND_REPLACE_WITH_HYPHEN: + return REPLACE_WITH_HYPHEN_AT_END; + case HyphenationType::BREAK_AND_INSERT_HYPHEN_AND_ZWJ: + return INSERT_ZWJ_AND_HYPHEN_AT_END; + default: + return BREAK_AT_END; + } +} + +uint32_t HyphenEdit::editForNextLine(HyphenationType type) { + switch (type) { + case HyphenationType::DONT_BREAK: + return NO_EDIT; + case HyphenationType::BREAK_AND_INSERT_HYPHEN_AT_NEXT_LINE: + return INSERT_HYPHEN_AT_START; + case HyphenationType::BREAK_AND_INSERT_HYPHEN_AND_ZWJ: + return INSERT_ZWJ_AT_START; + default: + return BREAK_AT_START; + } +} + +static UScriptCode getScript(uint32_t codePoint) { + UErrorCode errorCode = U_ZERO_ERROR; + const UScriptCode script = uscript_getScript(static_cast(codePoint), &errorCode); + if (U_SUCCESS(errorCode)) { + return script; + } else { + return USCRIPT_INVALID_CODE; + } +} + +static HyphenationType hyphenationTypeBasedOnScript(uint32_t codePoint) { + // Note: It's not clear what the best hyphen for Hebrew is. While maqaf is the "correct" hyphen + // for Hebrew, modern practice may have shifted towards Western hyphens. We use normal hyphens + // for now to be safe. BREAK_AND_INSERT_MAQAF is already implemented, so if we want to switch + // to maqaf for Hebrew, we can simply add a condition here. + const UScriptCode script = getScript(codePoint); + if (script == USCRIPT_KANNADA + || script == USCRIPT_MALAYALAM + || script == USCRIPT_TAMIL + || script == USCRIPT_TELUGU) { + // Grantha is not included, since we don't support non-BMP hyphenation yet. + return HyphenationType::BREAK_AND_DONT_INSERT_HYPHEN; + } else if (script == USCRIPT_ARMENIAN) { + return HyphenationType::BREAK_AND_INSERT_ARMENIAN_HYPHEN; + } else if (script == USCRIPT_CANADIAN_ABORIGINAL) { + return HyphenationType::BREAK_AND_INSERT_UCAS_HYPHEN; + } else { + return HyphenationType::BREAK_AND_INSERT_HYPHEN; + } +} + +static inline int32_t getJoiningType(UChar32 codepoint) { + return u_getIntPropertyValue(codepoint, UCHAR_JOINING_TYPE); +} + +// Assumption for caller: location must be >= 2 and word[location] == CHAR_SOFT_HYPHEN. +// This function decides if the letters before and after the hyphen should appear as joining. +static inline HyphenationType getHyphTypeForArabic(const uint16_t* word, size_t len, + size_t location) { + ssize_t i = location; + int32_t type = U_JT_NON_JOINING; + while (static_cast(i) < len && (type = getJoiningType(word[i])) == U_JT_TRANSPARENT) { + i++; + } + if (type == U_JT_DUAL_JOINING || type == U_JT_RIGHT_JOINING || type == U_JT_JOIN_CAUSING) { + // The next character is of the type that may join the last character. See if the last + // character is also of the right type. + i = location - 2; // Skip the soft hyphen + type = U_JT_NON_JOINING; + while (i >= 0 && (type = getJoiningType(word[i])) == U_JT_TRANSPARENT) { + i--; + } + if (type == U_JT_DUAL_JOINING || type == U_JT_LEFT_JOINING || type == U_JT_JOIN_CAUSING) { + return HyphenationType::BREAK_AND_INSERT_HYPHEN_AND_ZWJ; + } + } + return HyphenationType::BREAK_AND_INSERT_HYPHEN; +} + +// Use various recommendations of UAX #14 Unicode Line Breaking Algorithm for hyphenating words +// that didn't match patterns, especially words that contain hyphens or soft hyphens (See sections +// 5.3, Use of Hyphen, and 5.4, Use of Soft Hyphen). +void Hyphenator::hyphenateWithNoPatterns(HyphenationType* result, const uint16_t* word, size_t len, + const icu::Locale& locale) { + result[0] = HyphenationType::DONT_BREAK; for (size_t i = 1; i < len; i++) { - result[i] = word[i - 1] == CHAR_SOFT_HYPHEN; + const uint16_t prevChar = word[i - 1]; + if (i > 1 && isLineBreakingHyphen(prevChar)) { + // Break after hyphens, but only if they don't start the word. + + if ((prevChar == CHAR_HYPHEN_MINUS || prevChar == CHAR_HYPHEN) + && strcmp(locale.getLanguage(), "pl") == 0 + && getScript(word[i]) == USCRIPT_LATIN ) { + // In Polish, hyphens get repeated at the next line. To be safe, + // we will do this only if the next character is Latin. + result[i] = HyphenationType::BREAK_AND_INSERT_HYPHEN_AT_NEXT_LINE; + } else { + result[i] = HyphenationType::BREAK_AND_DONT_INSERT_HYPHEN; + } + } else if (i > 1 && prevChar == CHAR_SOFT_HYPHEN) { + // Break after soft hyphens, but only if they don't start the word (a soft hyphen + // starting the word doesn't give any useful break opportunities). The type of the break + // is based on the script of the character we break on. + if (getScript(word[i]) == USCRIPT_ARABIC) { + // For Arabic, we need to look and see if the characters around the soft hyphen + // actually join. If they don't, we'll just insert a normal hyphen. + result[i] = getHyphTypeForArabic(word, len, i); + } else { + result[i] = hyphenationTypeBasedOnScript(word[i]); + } + } else if (prevChar == CHAR_MIDDLE_DOT + && MIN_PREFIX < i && i <= len - MIN_SUFFIX + && ((word[i - 2] == 'l' && word[i] == 'l') + || (word[i - 2] == 'L' && word[i] == 'L')) + && strcmp(locale.getLanguage(), "ca") == 0) { + // In Catalan, "l·l" should break as "l-" on the first line + // and "l" on the next line. + result[i] = HyphenationType::BREAK_AND_REPLACE_WITH_HYPHEN; + } else { + result[i] = HyphenationType::DONT_BREAK; + } } } -bool Hyphenator::alphabetLookup(uint16_t* alpha_codes, const uint16_t* word, size_t len) { +HyphenationType Hyphenator::alphabetLookup(uint16_t* alpha_codes, const uint16_t* word, + size_t len) { const Header* header = getHeader(); + HyphenationType result = HyphenationType::BREAK_AND_INSERT_HYPHEN; // TODO: check header magic uint32_t alphabetVersion = header->alphabetVersion(); if (alphabetVersion == 0) { @@ -148,16 +334,19 @@ bool Hyphenator::alphabetLookup(uint16_t* alpha_codes, const uint16_t* word, siz for (size_t i = 0; i < len; i++) { uint16_t c = word[i]; if (c < min_codepoint || c >= max_codepoint) { - return false; + return HyphenationType::DONT_BREAK; } uint8_t code = alphabet->data[c - min_codepoint]; if (code == 0) { - return false; + return HyphenationType::DONT_BREAK; + } + if (result == HyphenationType::BREAK_AND_INSERT_HYPHEN) { + result = hyphenationTypeBasedOnScript(c); } alpha_codes[i + 1] = code; } alpha_codes[len + 1] = 0; // word termination - return true; + return result; } else if (alphabetVersion == 1) { const AlphabetTable1* alphabet = header->alphabetTable1(); size_t n_entries = alphabet->n_entries; @@ -168,18 +357,21 @@ bool Hyphenator::alphabetLookup(uint16_t* alpha_codes, const uint16_t* word, siz uint16_t c = word[i]; auto p = std::lower_bound(begin, end, c << 11); if (p == end) { - return false; + return HyphenationType::DONT_BREAK; } uint32_t entry = *p; if (AlphabetTable1::codepoint(entry) != c) { - return false; + return HyphenationType::DONT_BREAK; + } + if (result == HyphenationType::BREAK_AND_INSERT_HYPHEN) { + result = hyphenationTypeBasedOnScript(c); } alpha_codes[i + 1] = AlphabetTable1::value(entry); } alpha_codes[len + 1] = 0; - return true; + return result; } - return false; + return HyphenationType::DONT_BREAK; } /** @@ -187,7 +379,12 @@ bool Hyphenator::alphabetLookup(uint16_t* alpha_codes, const uint16_t* word, siz * has been done by now, and all characters have been found in the alphabet. * Note: len here is the padded length including 0 codes at start and end. **/ -void Hyphenator::hyphenateFromCodes(uint8_t* result, const uint16_t* codes, size_t len) { +void Hyphenator::hyphenateFromCodes(HyphenationType* result, const uint16_t* codes, size_t len, + HyphenationType hyphenValue) { + static_assert(sizeof(HyphenationType) == sizeof(uint8_t), "HyphnationType must be uint8_t."); + // Reuse the result array as a buffer for calculating intermediate hyphenation numbers. + uint8_t* buffer = reinterpret_cast(result); + const Header* header = getHeader(); const Trie* trie = header->trieTable(); const Pattern* pattern = header->patternTable(); @@ -209,26 +406,27 @@ void Hyphenator::hyphenateFromCodes(uint8_t* result, const uint16_t* codes, size uint32_t pat_ix = trie->data[node] >> pattern_shift; // pat_ix contains a 3-tuple of length, shift (number of trailing zeros), and an offset // into the buf pool. This is the pattern for the substring (i..j) we just matched, - // which we combine (via point-wise max) into the result vector. + // which we combine (via point-wise max) into the buffer vector. if (pat_ix != 0) { uint32_t pat_entry = pattern->data[pat_ix]; int pat_len = Pattern::len(pat_entry); int pat_shift = Pattern::shift(pat_entry); const uint8_t* pat_buf = pattern->buf(pat_entry); int offset = j + 1 - (pat_len + pat_shift); - // offset is the index within result that lines up with the start of pat_buf + // offset is the index within buffer that lines up with the start of pat_buf int start = std::max(MIN_PREFIX - offset, 0); int end = std::min(pat_len, (int)maxOffset - offset); for (int k = start; k < end; k++) { - result[offset + k] = std::max(result[offset + k], pat_buf[k]); + buffer[offset + k] = std::max(buffer[offset + k], pat_buf[k]); } } } } // Since the above calculation does not modify values outside - // [MIN_PREFIX, len - MIN_SUFFIX], they are left as 0. + // [MIN_PREFIX, len - MIN_SUFFIX], they are left as 0 = DONT_BREAK. for (size_t i = MIN_PREFIX; i < maxOffset; i++) { - result[i] &= 1; + // Hyphenation opportunities happen when the hyphenation numbers are odd. + result[i] = (buffer[i] & 1u) ? hyphenValue : HyphenationType::DONT_BREAK; } } diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 6b28f57a331..743cb763aea 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -242,7 +243,7 @@ android::hash_t LayoutCacheKey::computeHash() const { hash = android::JenkinsHashMix(hash, hash_type(mSkewX)); hash = android::JenkinsHashMix(hash, hash_type(mLetterSpacing)); hash = android::JenkinsHashMix(hash, hash_type(mPaintFlags)); - hash = android::JenkinsHashMix(hash, hash_type(mHyphenEdit.hasHyphen())); + hash = android::JenkinsHashMix(hash, hash_type(mHyphenEdit.getHyphen())); hash = android::JenkinsHashMix(hash, hash_type(mIsRtl)); hash = android::JenkinsHashMixShorts(hash, mChars, mNchars); return android::JenkinsHashWhiten(hash); @@ -623,7 +624,7 @@ float Layout::measureText(const uint16_t* buf, size_t start, size_t count, size_ float Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t bufSize, bool isRtl, LayoutContext* ctx, size_t dstStart, const std::shared_ptr& collection, Layout* layout, float* advances) { - HyphenEdit hyphen = ctx->paint.hyphenEdit; + const uint32_t originalHyphen = ctx->paint.hyphenEdit.getHyphen(); float advance = 0; if (!isRtl) { // left to right @@ -632,8 +633,15 @@ float Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t wordend; for (size_t iter = start; iter < start + count; iter = wordend) { wordend = getNextWordBreakForCache(buf, iter, bufSize); - // Only apply hyphen to the last word in the string. - ctx->paint.hyphenEdit = wordend >= start + count ? hyphen : HyphenEdit(); + // Only apply hyphen to the first or last word in the string. + uint32_t hyphen = originalHyphen; + if (iter != start) { // Not the first word + hyphen &= ~HyphenEdit::MASK_START_OF_LINE; + } + if (wordend < start + count) { // Not the last word + hyphen &= ~HyphenEdit::MASK_END_OF_LINE; + } + ctx->paint.hyphenEdit = hyphen; size_t wordcount = std::min(start + count, wordend) - iter; advance += doLayoutWord(buf + wordstart, iter - wordstart, wordcount, wordend - wordstart, isRtl, ctx, iter - dstStart, collection, layout, @@ -647,8 +655,15 @@ float Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, size_t wordend = end == 0 ? 0 : getNextWordBreakForCache(buf, end - 1, bufSize); for (size_t iter = end; iter > start; iter = wordstart) { wordstart = getPrevWordBreakForCache(buf, iter, bufSize); - // Only apply hyphen to the last (leftmost) word in the string. - ctx->paint.hyphenEdit = iter == end ? hyphen : HyphenEdit(); + // Only apply hyphen to the first (rightmost) or last (leftmost) word in the string. + uint32_t hyphen = originalHyphen; + if (wordstart > start) { // Not the first word + hyphen &= ~HyphenEdit::MASK_START_OF_LINE; + } + if (iter != end) { // Not the last word + hyphen &= ~HyphenEdit::MASK_END_OF_LINE; + } + ctx->paint.hyphenEdit = hyphen; size_t bufStart = std::max(start, wordstart); advance += doLayoutWord(buf + wordstart, bufStart - wordstart, iter - bufStart, wordend - wordstart, isRtl, ctx, bufStart - dstStart, collection, layout, @@ -719,6 +734,134 @@ static void addFeatures(const string &str, vector* features) { } } +static inline hb_codepoint_t determineHyphenChar(hb_codepoint_t preferredHyphen, hb_font_t* font) { + if (preferredHyphen == 0x2010 /* HYPHEN */ + || preferredHyphen == 0x058A /* ARMENIAN_HYPHEN */ + || preferredHyphen == 0x05BE /* HEBREW PUNCTUATION MAQAF */ + || preferredHyphen == 0x1400 /* CANADIAN SYLLABIC HYPHEN */) { + hb_codepoint_t glyph; + // Fallback to ASCII HYPHEN-MINUS if the font didn't have a glyph for the preferred hyphen. + // Note that we intentionally don't do anything special if the font doesn't have a + // HYPHEN-MINUS either, so a tofu could be shown, hinting towards something missing. + if (!hb_font_get_nominal_glyph(font, preferredHyphen, &glyph)) { + return 0x002D; // HYPHEN-MINUS + } + } + return preferredHyphen; +} + +static inline void addHyphenToHbBuffer(hb_buffer_t* buffer, hb_font_t* font, uint32_t hyphen, + uint32_t cluster) { + const uint32_t* hyphenStr = HyphenEdit::getHyphenString(hyphen); + while (*hyphenStr != 0) { + hb_codepoint_t hyphenChar = determineHyphenChar(*hyphenStr, font); + hb_buffer_add(buffer, hyphenChar, cluster); + hyphenStr++; + } +} + +// Returns the cluster value assigned to the first codepoint added to the buffer, which can be used +// to translate cluster values returned by HarfBuzz to input indices. +static inline uint32_t addToHbBuffer(hb_buffer_t* buffer, + const uint16_t* buf, size_t start, size_t count, size_t bufSize, + ssize_t scriptRunStart, ssize_t scriptRunEnd, + HyphenEdit hyphenEdit, hb_font_t* hbFont) { + + // Only hyphenate the very first script run for starting hyphens. + const uint32_t startHyphen = (scriptRunStart == 0) + ? hyphenEdit.getStart() + : HyphenEdit::NO_EDIT; + // Only hyphenate the very last script run for ending hyphens. + const uint32_t endHyphen = (static_cast(scriptRunEnd) == count) + ? hyphenEdit.getEnd() + : HyphenEdit::NO_EDIT; + + // In the following code, we drop the pre-context and/or post-context if there is a + // hyphen edit at that end. This is not absolutely necessary, since HarfBuzz uses + // contexts only for joining scripts at the moment, e.g. to determine if the first or + // last letter of a text range to shape should take a joining form based on an + // adjacent letter or joiner (that comes from the context). + // + // TODO: Revisit this for: + // 1. Desperate breaks for joining scripts like Arabic (where it may be better to keep + // the context); + // 2. Special features like start-of-word font features (not implemented in HarfBuzz + // yet). + + // We don't have any start-of-line replacement edit yet, so we don't need to check for + // those. + if (HyphenEdit::isInsertion(startHyphen)) { + // A cluster value of zero guarantees that the inserted hyphen will be in the same + // cluster with the next codepoint, since there is no pre-context. + addHyphenToHbBuffer(buffer, hbFont, startHyphen, 0 /* cluster value */); + } + + const uint16_t* hbText; + int hbTextLength; + unsigned int hbItemOffset; + unsigned int hbItemLength = scriptRunEnd - scriptRunStart; // This is >= 1. + + const bool hasEndInsertion = HyphenEdit::isInsertion(endHyphen); + const bool hasEndReplacement = HyphenEdit::isReplacement(endHyphen); + if (hasEndReplacement) { + // Skip the last code unit while copying the buffer for HarfBuzz if it's a replacement. We + // don't need to worry about non-BMP characters yet since replacements are only done for + // code units at the moment. + hbItemLength -= 1; + } + + if (startHyphen == HyphenEdit::NO_EDIT) { + // No edit at the beginning. Use the whole pre-context. + hbText = buf; + hbItemOffset = start + scriptRunStart; + } else { + // There's an edit at the beginning. Drop the pre-context and start the buffer at where we + // want to start shaping. + hbText = buf + start + scriptRunStart; + hbItemOffset = 0; + } + + if (endHyphen == HyphenEdit::NO_EDIT) { + // No edit at the end, use the whole post-context. + hbTextLength = (buf + bufSize) - hbText; + } else { + // There is an edit at the end. Drop the post-context. + hbTextLength = hbItemOffset + hbItemLength; + } + + hb_buffer_add_utf16(buffer, hbText, hbTextLength, hbItemOffset, hbItemLength); + + unsigned int numCodepoints; + hb_glyph_info_t* cpInfo = hb_buffer_get_glyph_infos(buffer, &numCodepoints); + + // Add the hyphen at the end, if there's any. + if (hasEndInsertion || hasEndReplacement) { + // When a hyphen is inserted, by assigning the added hyphen and the last + // codepoint added to the HarfBuzz buffer to the same cluster, we can make sure + // that they always remain in the same cluster, even if the last codepoint gets + // merged into another cluster (for example when it's a combining mark). + // + // When a replacement happens instead, we want it to get the cluster value of + // the character it's replacing, which is one "codepoint length" larger than + // the last cluster. But since the character replaced is always just one + // code unit, we can just add 1. + uint32_t hyphenCluster; + if (numCodepoints == 0) { + // Nothing was added to the HarfBuzz buffer. This can only happen if + // we have a replacement that is replacing a one-code unit script run. + hyphenCluster = 0; + } else { + hyphenCluster = cpInfo[numCodepoints - 1].cluster + (uint32_t) hasEndReplacement; + } + addHyphenToHbBuffer(buffer, hbFont, endHyphen, hyphenCluster); + // Since we have just added to the buffer, cpInfo no longer necessarily points to + // the right place. Refresh it. + cpInfo = hb_buffer_get_glyph_infos(buffer, nullptr /* we don't need the size */); + } + return cpInfo[0].cluster; +} + + void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, bool isRtl, LayoutContext* ctx) { hb_buffer_t* buffer = LayoutEngine::getInstance().hbBuffer; @@ -769,10 +912,21 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t // TODO: if there are multiple scripts within a font in an RTL run, // we need to reorder those runs. This is unlikely with our current // font stack, but should be done for correctness. - ssize_t srunend; - for (ssize_t srunstart = run.start; srunstart < run.end; srunstart = srunend) { - srunend = srunstart; - hb_script_t script = getScriptRun(buf + start, run.end, &srunend); + + // Note: scriptRunStart and scriptRunEnd, as well as run.start and run.end, run between 0 + // and count. + ssize_t scriptRunEnd; + for (ssize_t scriptRunStart = run.start; + scriptRunStart < run.end; + scriptRunStart = scriptRunEnd) { + scriptRunEnd = scriptRunStart; + hb_script_t script = getScriptRun(buf + start, run.end, &scriptRunEnd /* iterator */); + // After the last line, scriptRunEnd is guaranteed to have increased, since the only + // time getScriptRun does not increase its iterator is when it has already reached the + // end of the buffer. But that can't happen, since if we have already reached the end + // of the buffer, we should have had (scriptRunEnd == run.end), which means + // (scriptRunStart == run.end) which is impossible due to the exit condition of the for + // loop. So we can be sure that scriptRunEnd > scriptRunStart. double letterSpace = 0.0; double letterSpaceHalfLeft = 0.0; @@ -804,30 +958,29 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t } hb_buffer_set_language(buffer, hbLanguage->getHbLanguage()); } - hb_buffer_add_utf16(buffer, buf, bufSize, srunstart + start, srunend - srunstart); - if (ctx->paint.hyphenEdit.hasHyphen() && srunend > srunstart) { - // TODO: check whether this is really the desired semantics. It could have the - // effect of assigning the hyphen width to a nonspacing mark - unsigned int lastCluster = start + srunend - 1; - hb_codepoint_t hyphenChar = 0x2010; // HYPHEN - hb_codepoint_t glyph; - // Fallback to ASCII HYPHEN-MINUS if the font didn't have a glyph for HYPHEN. Note - // that we intentionally don't do anything special if the font doesn't have a - // HYPHEN-MINUS either, so a tofu could be shown, hinting towards something - // missing. - if (!hb_font_get_glyph(hbFont, hyphenChar, 0, &glyph)) { - hyphenChar = 0x002D; // HYPHEN-MINUS - } - hb_buffer_add(buffer, hyphenChar, lastCluster); - } + const uint32_t clusterStart = addToHbBuffer( + buffer, + buf, start, count, bufSize, + scriptRunStart, scriptRunEnd, + ctx->paint.hyphenEdit, hbFont); + hb_shape(hbFont, buffer, features.empty() ? NULL : &features[0], features.size()); unsigned int numGlyphs; hb_glyph_info_t* info = hb_buffer_get_glyph_infos(buffer, &numGlyphs); hb_glyph_position_t* positions = hb_buffer_get_glyph_positions(buffer, NULL); + + // At this point in the code, the cluster values in the info buffer correspond to the + // input characters with some shift. The cluster value clusterStart corresponds to the + // first character passed to HarfBuzz, which is at buf[start + scriptRunStart] whose + // advance needs to be saved into mAdvances[scriptRunStart]. So cluster values need to + // be reduced by (clusterStart - scriptRunStart) to get converted to indices of + // mAdvances. + const ssize_t clusterOffset = clusterStart - scriptRunStart; + if (numGlyphs) { - mAdvances[info[0].cluster - start] += letterSpaceHalfLeft; + mAdvances[info[0].cluster - clusterOffset] += letterSpaceHalfLeft; x += letterSpaceHalfLeft; } for (unsigned int i = 0; i < numGlyphs; i++) { @@ -840,8 +993,8 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t positions[i].x_offset, positions[i].y_offset); #endif if (i > 0 && info[i - 1].cluster != info[i].cluster) { - mAdvances[info[i - 1].cluster - start] += letterSpaceHalfRight; - mAdvances[info[i].cluster - start] += letterSpaceHalfLeft; + mAdvances[info[i - 1].cluster - clusterOffset] += letterSpaceHalfRight; + mAdvances[info[i].cluster - clusterOffset] += letterSpaceHalfLeft; x += letterSpace; } @@ -871,17 +1024,17 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t } glyphBounds.offset(x + xoff, y + yoff); mBounds.join(glyphBounds); - if (info[i].cluster - start < count) { - mAdvances[info[i].cluster - start] += xAdvance; + if (static_cast(info[i].cluster - clusterOffset) < count) { + mAdvances[info[i].cluster - clusterOffset] += xAdvance; } else { ALOGE("cluster %zu (start %zu) out of bounds of count %zu", - info[i].cluster - start, start, count); + info[i].cluster - clusterOffset, start, count); } x += xAdvance; } if (numGlyphs) { - mAdvances[info[numGlyphs - 1].cluster - start] += letterSpaceHalfRight; + mAdvances[info[numGlyphs - 1].cluster - clusterOffset] += letterSpaceHalfRight; x += letterSpaceHalfRight; } } diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index 3965cbd4c84..b8814b63d45 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -63,7 +63,7 @@ const float SHRINKABILITY = 1.0 / 3.0; void LineBreaker::setLocale(const icu::Locale& locale, Hyphenator* hyphenator) { mWordBreaker.setLocale(locale); - + mLocale = locale; mHyphenator = hyphenator; } @@ -73,7 +73,7 @@ void LineBreaker::setText() { // handle initial break here because addStyleRun may never be called mWordBreaker.next(); mCandidates.clear(); - Candidate cand = {0, 0, 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0}; + Candidate cand = {0, 0, 0.0, 0.0, 0.0, 0.0, 0, 0, 0, HyphenationType::DONT_BREAK}; mCandidates.push_back(cand); // reset greedy breaker state @@ -106,24 +106,6 @@ static bool isLineEndSpace(uint16_t c) { c == 0x205F || c == 0x3000; } -// This function determines whether a character is like U+2010 HYPHEN in -// line breaking and usage: a character immediately after which line breaks -// are allowed, but words containing it should not be automatically -// hyphenated. This is a curated set, created by manually inspecting all -// the characters that have the Unicode line breaking property of BA or HY -// and seeing which ones are hyphens. -static bool isLineBreakingHyphen(uint16_t c) { - return (c == 0x002D || // HYPHEN-MINUS - c == 0x058A || // ARMENIAN HYPHEN - c == 0x05BE || // HEBREW PUNCTUATION MAQAF - c == 0x1400 || // CANADIAN SYLLABICS HYPHEN - c == 0x2010 || // HYPHEN - c == 0x2013 || // EN DASH - c == 0x2027 || // HYPHENATION POINT - c == 0x2E17 || // DOUBLE OBLIQUE HYPHEN - c == 0x2E40); // DOUBLE HYPHEN -} - // Ordinarily, this method measures the text in the range given. However, when paint // is nullptr, it assumes the widths have already been calculated and stored in the // width buffer. @@ -161,7 +143,6 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const std::shared_ptr= start && wordEnd > wordStart && wordEnd - wordStart <= LONGEST_HYPHENATED_WORD) { - mHyphenator->hyphenate(&mHyphBuf, &mTextBuf[wordStart], wordEnd - wordStart); + mHyphenator->hyphenate(&mHyphBuf, + &mTextBuf[wordStart], + wordEnd - wordStart, + mLocale); #if VERBOSE_DEBUG std::string hyphenatedString; for (size_t j = wordStart; j < wordEnd; j++) { - if (mHyphBuf[j - wordStart]) hyphenatedString.push_back('-'); + if (mHyphBuf[j - wordStart] == HyphenationType::BREAK_AND_INSERT_HYPHEN) { + hyphenatedString.push_back('-'); + } // Note: only works with ASCII, should do UTF-8 conversion here hyphenatedString.push_back(buffer()[j]); } @@ -204,32 +186,33 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const std::shared_ptrhyphenEdit = hyph; - + HyphenationType hyph = mHyphBuf[j - wordStart]; + if (hyph != HyphenationType::DONT_BREAK) { + paint->hyphenEdit = HyphenEdit::editForThisLine(hyph); const float firstPartWidth = Layout::measureText(mTextBuf.data(), lastBreak, j - lastBreak, mTextBuf.size(), bidiFlags, style, *paint, typeface, nullptr); ParaWidth hyphPostBreak = lastBreakWidth + firstPartWidth; - paint->hyphenEdit = 0; + paint->hyphenEdit = HyphenEdit::editForNextLine(hyph); const float secondPartWidth = Layout::measureText(mTextBuf.data(), j, afterWord - j, mTextBuf.size(), bidiFlags, style, *paint, typeface, nullptr); ParaWidth hyphPreBreak = postBreak - secondPartWidth; + addWordBreak(j, hyphPreBreak, hyphPostBreak, postSpaceCount, postSpaceCount, hyphenPenalty, hyph); + + paint->hyphenEdit = HyphenEdit::NO_EDIT; } } } - // Skip hyphenating the next word if and only if the present word ends in a hyphen - temporarilySkipHyphenation = wordEndsInHyphen; // Skip break for zero-width characters inside replacement span if (paint != nullptr || current == end || mCharWidths[current] > 0) { float penalty = hyphenPenalty * mWordBreaker.breakBadness(); - addWordBreak(current, mWidth, postBreak, mSpaceCount, postSpaceCount, penalty, 0); + addWordBreak(current, mWidth, postBreak, mSpaceCount, postSpaceCount, penalty, + HyphenationType::DONT_BREAK); } lastBreak = current; lastBreakWidth = mWidth; @@ -243,7 +226,7 @@ float LineBreaker::addStyleRun(MinikinPaint* paint, const std::shared_ptr currentLineWidth()) { @@ -262,7 +245,7 @@ void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth post cand.preSpaceCount = postSpaceCount; cand.postSpaceCount = postSpaceCount; cand.penalty = SCORE_DESPERATE; - cand.hyphenEdit = 0; + cand.hyphenType = HyphenationType::BREAK_AND_DONT_INSERT_HYPHEN; #if VERBOSE_DEBUG ALOGD("desperate cand: %zd %g:%g", mCandidates.size(), cand.postBreak, cand.preBreak); @@ -279,7 +262,7 @@ void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth post cand.penalty = penalty; cand.preSpaceCount = preSpaceCount; cand.postSpaceCount = postSpaceCount; - cand.hyphenEdit = hyph; + cand.hyphenType = hyph; #if VERBOSE_DEBUG ALOGD("cand: %zd %g:%g", mCandidates.size(), cand.postBreak, cand.preBreak); #endif @@ -296,7 +279,7 @@ void LineBreaker::addCandidate(Candidate cand) { mBestBreak = candIndex; } pushBreak(mCandidates[mBestBreak].offset, mCandidates[mBestBreak].postBreak - mPreBreak, - mCandidates[mBestBreak].hyphenEdit); + HyphenEdit::editForThisLine(mCandidates[mBestBreak].hyphenType)); mBestScore = SCORE_INFTY; #if VERBOSE_DEBUG ALOGD("break: %d %g", mBreaks.back(), mWidths.back()); @@ -310,11 +293,11 @@ void LineBreaker::addCandidate(Candidate cand) { } } -void LineBreaker::pushBreak(int offset, float width, uint8_t hyph) { +void LineBreaker::pushBreak(int offset, float width, uint8_t hyphenEdit) { mBreaks.push_back(offset); mWidths.push_back(width); int flags = (mFirstTabIndex < mBreaks.back()) << kTab_Shift; - flags |= hyph; + flags |= hyphenEdit; mFlags.push_back(flags); mFirstTabIndex = INT_MAX; } @@ -345,7 +328,8 @@ void LineBreaker::computeBreaksGreedy() { // All breaks but the last have been added in addCandidate already. size_t nCand = mCandidates.size(); if (nCand == 1 || mLastBreak != nCand - 1) { - pushBreak(mCandidates[nCand - 1].offset, mCandidates[nCand - 1].postBreak - mPreBreak, 0); + pushBreak(mCandidates[nCand - 1].offset, mCandidates[nCand - 1].postBreak - mPreBreak, + HyphenEdit::NO_EDIT); // don't need to update mBestScore, because we're done #if VERBOSE_DEBUG ALOGD("final break: %d %g", mBreaks.back(), mWidths.back()); @@ -365,7 +349,11 @@ void LineBreaker::finishBreaksOptimal() { prev = mCandidates[i].prev; mBreaks.push_back(mCandidates[i].offset); mWidths.push_back(mCandidates[i].postBreak - mCandidates[prev].preBreak); - mFlags.push_back(mCandidates[i].hyphenEdit); + int flags = HyphenEdit::editForThisLine(mCandidates[i].hyphenType); + if (prev > 0) { + flags |= HyphenEdit::editForNextLine(mCandidates[prev].hyphenType); + } + mFlags.push_back(flags); } std::reverse(mBreaks.begin(), mBreaks.end()); std::reverse(mWidths.begin(), mWidths.end()); diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index 82596f8a04e..7ad7242dff6 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -19,6 +19,7 @@ #include #include +#include #include "MinikinInternal.h" #include @@ -74,7 +75,8 @@ static bool isBreakValid(const uint16_t* buf, size_t bufEnd, size_t i) { uint32_t codePoint; size_t prev_offset = i; U16_PREV(buf, 0, prev_offset, codePoint); - if (codePoint == CHAR_SOFT_HYPHEN) { + // Do not break on hard or soft hyphens. These are handled by automatic hyphenation. + if (Hyphenator::isLineBreakingHyphen(codePoint) || codePoint == CHAR_SOFT_HYPHEN) { return false; } // For Myanmar kinzi sequences, created by . This is to go diff --git a/engine/src/flutter/tests/perftests/Hyphenator.cpp b/engine/src/flutter/tests/perftests/Hyphenator.cpp index 692e06d2bf0..1e6411f76df 100644 --- a/engine/src/flutter/tests/perftests/Hyphenator.cpp +++ b/engine/src/flutter/tests/perftests/Hyphenator.cpp @@ -22,13 +22,14 @@ namespace minikin { const char* enUsHyph = "/system/usr/hyphen-data/hyph-en-us.hyb"; +const icu::Locale& usLocale = icu::Locale::getUS(); static void BM_Hyphenator_short_word(benchmark::State& state) { Hyphenator* hyphenator = Hyphenator::loadBinary(readWholeFile(enUsHyph).data()); std::vector word = utf8ToUtf16("hyphen"); - std::vector result; + std::vector result; while (state.KeepRunning()) { - hyphenator->hyphenate(&result, word.data(), word.size()); + hyphenator->hyphenate(&result, word.data(), word.size(), usLocale); } Hyphenator::loadBinary(nullptr); } @@ -40,9 +41,9 @@ static void BM_Hyphenator_long_word(benchmark::State& state) { Hyphenator* hyphenator = Hyphenator::loadBinary(readWholeFile(enUsHyph).data()); std::vector word = utf8ToUtf16( "Pneumonoultramicroscopicsilicovolcanoconiosis"); - std::vector result; + std::vector result; while (state.KeepRunning()) { - hyphenator->hyphenate(&result, word.data(), word.size()); + hyphenator->hyphenate(&result, word.data(), word.size(), usLocale); } Hyphenator::loadBinary(nullptr); } diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index 7b3f60f8f9e..da7851a3e7d 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -62,6 +62,7 @@ LOCAL_STATIC_LIBRARIES += \ libxml2 LOCAL_SRC_FILES += \ + ../util/FileUtils.cpp \ ../util/FontTestUtils.cpp \ ../util/MinikinFontForTest.cpp \ ../util/UnicodeUtils.cpp \ @@ -70,6 +71,7 @@ LOCAL_SRC_FILES += \ FontFamilyTest.cpp \ FontLanguageListCacheTest.cpp \ HbFontCacheTest.cpp \ + HyphenatorTest.cpp \ MinikinInternalTest.cpp \ GraphemeBreakTests.cpp \ LayoutTest.cpp \ diff --git a/engine/src/flutter/tests/unittest/HyphenatorTest.cpp b/engine/src/flutter/tests/unittest/HyphenatorTest.cpp new file mode 100644 index 00000000000..6265c2c6c1b --- /dev/null +++ b/engine/src/flutter/tests/unittest/HyphenatorTest.cpp @@ -0,0 +1,335 @@ +/* + * Copyright (C) 2017 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 + +#include "ICUTestBase.h" +#include +#include + +#ifndef NELEM +#define NELEM(x) ((sizeof(x) / sizeof((x)[0]))) +#endif + +namespace minikin { + +const char* usHyph = "/system/usr/hyphen-data/hyph-en-us.hyb"; +const char* malayalamHyph = "/system/usr/hyphen-data/hyph-ml.hyb"; + +typedef ICUTestBase HyphenatorTest; + +const icu::Locale catalanLocale("ca", "ES", nullptr, nullptr); +const icu::Locale polishLocale("pl", "PL", nullptr, nullptr); +const icu::Locale& usLocale = icu::Locale::getUS(); + +const uint16_t HYPHEN_MINUS = 0x002D; +const uint16_t SOFT_HYPHEN = 0x00AD; +const uint16_t MIDDLE_DOT = 0x00B7; +const uint16_t GREEK_LOWER_ALPHA = 0x03B1; +const uint16_t ARMENIAN_AYB = 0x0531; +const uint16_t HEBREW_ALEF = 0x05D0; +const uint16_t ARABIC_ALEF = 0x0627; +const uint16_t ARABIC_BEH = 0x0628; +const uint16_t ARABIC_ZWARAKAY = 0x0659; +const uint16_t MALAYALAM_KA = 0x0D15; +const uint16_t UCAS_E = 0x1401; +const uint16_t HYPHEN = 0x2010; +const uint16_t EN_DASH = 0x2013; + +// Simple test for US English. This tests "table", which happens to be the in the exceptions list. +TEST_F(HyphenatorTest, usEnglishAutomaticHyphenation) { + Hyphenator* hyphenator = Hyphenator::loadBinary(readWholeFile(usHyph).data()); + const uint16_t word[] = {'t', 'a', 'b', 'l', 'e'}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 5, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_INSERT_HYPHEN, result[2]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[3]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[4]); +} + +// Catalan l·l should break as l-/l +TEST_F(HyphenatorTest, catalanMiddleDot) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {'l', 'l', MIDDLE_DOT, 'l', 'l', 'l'}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), catalanLocale); + EXPECT_EQ((size_t) 6, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[2]); + EXPECT_EQ(HyphenationType::BREAK_AND_REPLACE_WITH_HYPHEN, result[3]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[4]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[5]); +} + +// Catalan l·l should not break if the word is too short. +TEST_F(HyphenatorTest, catalanMiddleDotShortWord) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {'l', MIDDLE_DOT, 'l'}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), catalanLocale); + EXPECT_EQ((size_t) 3, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[2]); +} + +// If we break on a hyphen in Polish, the hyphen should be repeated on the next line. +TEST_F(HyphenatorTest, polishHyphen) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {'x', HYPHEN, 'y'}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), polishLocale); + EXPECT_EQ((size_t) 3, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_INSERT_HYPHEN_AT_NEXT_LINE, result[2]); +} + +// If the language is Polish but the script is not Latin, don't use Polish rules for hyphenation. +TEST_F(HyphenatorTest, polishHyphenButNonLatinWord) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {GREEK_LOWER_ALPHA, HYPHEN, GREEK_LOWER_ALPHA}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), polishLocale); + EXPECT_EQ((size_t) 3, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_DONT_INSERT_HYPHEN, result[2]); +} + +// Polish en dash doesn't repeat on next line (as far as we know), but just provides a break +// opportunity. +TEST_F(HyphenatorTest, polishEnDash) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {'x', EN_DASH, 'y'}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), polishLocale); + EXPECT_EQ((size_t) 3, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_DONT_INSERT_HYPHEN, result[2]); +} + +// In Latin script text, soft hyphens should insert a visible hyphen if broken at. +TEST_F(HyphenatorTest, latinSoftHyphen) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {'x', SOFT_HYPHEN, 'y'}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 3, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_INSERT_HYPHEN, result[2]); +} + +// Soft hyphens at the beginning of a word are not useful in linebreaking. +TEST_F(HyphenatorTest, latinSoftHyphenStartingTheWord) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {SOFT_HYPHEN, 'y'}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 2, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); +} + +// In Malayalam script text, soft hyphens should not insert a visible hyphen if broken at. +TEST_F(HyphenatorTest, malayalamSoftHyphen) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {MALAYALAM_KA, SOFT_HYPHEN, MALAYALAM_KA}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 3, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_DONT_INSERT_HYPHEN, result[2]); +} + +// In automatically hyphenated Malayalam script text, we should not insert a visible hyphen. +TEST_F(HyphenatorTest, malayalamAutomaticHyphenation) { + Hyphenator* hyphenator = Hyphenator::loadBinary(readWholeFile(malayalamHyph).data()); + const uint16_t word[] = { + MALAYALAM_KA, MALAYALAM_KA, MALAYALAM_KA, MALAYALAM_KA, MALAYALAM_KA}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 5, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_DONT_INSERT_HYPHEN, result[2]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[3]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[4]); +} + +// In Armenian script text, soft hyphens should insert an Armenian hyphen if broken at. +TEST_F(HyphenatorTest, aremenianSoftHyphen) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {ARMENIAN_AYB, SOFT_HYPHEN, ARMENIAN_AYB}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 3, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_INSERT_ARMENIAN_HYPHEN, result[2]); +} + +// In Hebrew script text, soft hyphens should insert a normal hyphen if broken at, for now. +// We may need to change this to maqaf later. +TEST_F(HyphenatorTest, hebrewSoftHyphen) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {HEBREW_ALEF, SOFT_HYPHEN, HEBREW_ALEF}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 3, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_INSERT_HYPHEN, result[2]); +} + +// Soft hyphen between two Arabic letters that join should keep the joining +// behavior when broken across lines. +TEST_F(HyphenatorTest, arabicSoftHyphenConnecting) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {ARABIC_BEH, SOFT_HYPHEN, ARABIC_BEH}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 3, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_INSERT_HYPHEN_AND_ZWJ, result[2]); +} + +// Arabic letters may be joining on one side, but if it's the wrong side, we +// should use the normal hyphen. +TEST_F(HyphenatorTest, arabicSoftHyphenNonConnecting) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {ARABIC_ALEF, SOFT_HYPHEN, ARABIC_BEH}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 3, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_INSERT_HYPHEN, result[2]); +} + +// Skip transparent characters until you find a non-transparent one. +TEST_F(HyphenatorTest, arabicSoftHyphenSkipTransparents) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {ARABIC_BEH, ARABIC_ZWARAKAY, SOFT_HYPHEN, ARABIC_ZWARAKAY, ARABIC_BEH}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 5, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[2]); + EXPECT_EQ(HyphenationType::BREAK_AND_INSERT_HYPHEN_AND_ZWJ, result[3]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[4]); +} + +// Skip transparent characters until you find a non-transparent one. If we get to one end without +// finding anything, we are still non-joining. +TEST_F(HyphenatorTest, arabicSoftHyphenTransparentsAtEnd) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {ARABIC_BEH, ARABIC_ZWARAKAY, SOFT_HYPHEN, ARABIC_ZWARAKAY}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 4, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[2]); + EXPECT_EQ(HyphenationType::BREAK_AND_INSERT_HYPHEN, result[3]); +} + +// Skip transparent characters until you find a non-transparent one. If we get to one end without +// finding anything, we are still non-joining. +TEST_F(HyphenatorTest, arabicSoftHyphenTransparentsAtStart) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {ARABIC_ZWARAKAY, SOFT_HYPHEN, ARABIC_ZWARAKAY, ARABIC_BEH}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 4, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_INSERT_HYPHEN, result[2]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[3]); +} + +// In Unified Canadian Aboriginal script (UCAS) text, soft hyphens should insert a UCAS hyphen. +TEST_F(HyphenatorTest, ucasSoftHyphen) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {UCAS_E, SOFT_HYPHEN, UCAS_E}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 3, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_INSERT_UCAS_HYPHEN, result[2]); +} + +// Presently, soft hyphen looks at the character after it to determine hyphenation type. This is a +// little arbitrary, but let's test it anyway. +TEST_F(HyphenatorTest, mixedScriptSoftHyphen) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {'a', SOFT_HYPHEN, UCAS_E}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 3, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_INSERT_UCAS_HYPHEN, result[2]); +} + +// Hard hyphens provide a breaking opportunity with nothing extra inserted. +TEST_F(HyphenatorTest, hardHyphen) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {'x', HYPHEN, 'y'}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 3, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_DONT_INSERT_HYPHEN, result[2]); +} + +// Hyphen-minuses also provide a breaking opportunity with nothing extra inserted. +TEST_F(HyphenatorTest, hyphenMinus) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {'x', HYPHEN_MINUS, 'y'}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 3, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); + EXPECT_EQ(HyphenationType::BREAK_AND_DONT_INSERT_HYPHEN, result[2]); +} + +// If the word starts with a hard hyphen or hyphen-minus, it doesn't make sense to break +// it at that point. +TEST_F(HyphenatorTest, startingHyphenMinus) { + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + const uint16_t word[] = {HYPHEN_MINUS, 'y'}; + std::vector result; + hyphenator->hyphenate(&result, word, NELEM(word), usLocale); + EXPECT_EQ((size_t) 2, result.size()); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); + EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); +} + +} // namespace minikin + diff --git a/engine/src/flutter/tests/unittest/LayoutTest.cpp b/engine/src/flutter/tests/unittest/LayoutTest.cpp index 4a849aa3ebc..ed41ca45742 100644 --- a/engine/src/flutter/tests/unittest/LayoutTest.cpp +++ b/engine/src/flutter/tests/unittest/LayoutTest.cpp @@ -356,6 +356,53 @@ TEST_F(LayoutTest, doLayoutTest_rtlTest) { } } +TEST_F(LayoutTest, hyphenationTest) { + Layout layout(mCollection); + std::vector text; + + // The mock implementation returns 10.0f advance for all glyphs. + { + SCOPED_TRACE("one word with no hyphen edit"); + text = utf8ToUtf16("oneword"); + MinikinPaint paint; + paint.hyphenEdit = HyphenEdit::NO_EDIT; + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(70.0f, layout.getAdvance()); + } + { + SCOPED_TRACE("one word with hyphen insertion at the end"); + text = utf8ToUtf16("oneword"); + MinikinPaint paint; + paint.hyphenEdit = HyphenEdit::INSERT_HYPHEN_AT_END; + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(80.0f, layout.getAdvance()); + } + { + SCOPED_TRACE("one word with hyphen replacement at the end"); + text = utf8ToUtf16("oneword"); + MinikinPaint paint; + paint.hyphenEdit = HyphenEdit::REPLACE_WITH_HYPHEN_AT_END; + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(70.0f, layout.getAdvance()); + } + { + SCOPED_TRACE("one word with hyphen insertion at the start"); + text = utf8ToUtf16("oneword"); + MinikinPaint paint; + paint.hyphenEdit = HyphenEdit::INSERT_HYPHEN_AT_START; + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(80.0f, layout.getAdvance()); + } + { + SCOPED_TRACE("one word with hyphen insertion at the both ends"); + text = utf8ToUtf16("oneword"); + MinikinPaint paint; + paint.hyphenEdit = HyphenEdit::INSERT_HYPHEN_AT_START | HyphenEdit::INSERT_HYPHEN_AT_END; + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + EXPECT_EQ(90.0f, layout.getAdvance()); + } +} + // TODO: Add more test cases, e.g. measure text, letter spacing. } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/WordBreakerTests.cpp b/engine/src/flutter/tests/unittest/WordBreakerTests.cpp index dc46c19d24c..7971b490703 100644 --- a/engine/src/flutter/tests/unittest/WordBreakerTests.cpp +++ b/engine/src/flutter/tests/unittest/WordBreakerTests.cpp @@ -39,7 +39,7 @@ typedef ICUTestBase WordBreakerTest; TEST_F(WordBreakerTest, basic) { uint16_t buf[] = {'h', 'e', 'l', 'l' ,'o', ' ', 'w', 'o', 'r', 'l', 'd'}; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(6, breaker.next()); // after "hello " @@ -57,7 +57,7 @@ TEST_F(WordBreakerTest, basic) { TEST_F(WordBreakerTest, softHyphen) { uint16_t buf[] = {'h', 'e', 'l', 0x00AD, 'l' ,'o', ' ', 'w', 'o', 'r', 'l', 'd'}; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(7, breaker.next()); // after "hel{SOFT HYPHEN}lo " @@ -70,10 +70,23 @@ TEST_F(WordBreakerTest, softHyphen) { EXPECT_EQ(0, breaker.breakBadness()); } +TEST_F(WordBreakerTest, hardHyphen) { + // Hyphens should not allow breaks anymore. + uint16_t buf[] = {'s', 'u', 'g', 'a', 'r', '-', 'f', 'r', 'e', 'e'}; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getUS()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); + EXPECT_EQ(0, breaker.wordStart()); + EXPECT_EQ((ssize_t)NELEM(buf), breaker.wordEnd()); + EXPECT_EQ(0, breaker.breakBadness()); +} + TEST_F(WordBreakerTest, postfixAndPrefix) { uint16_t buf[] = {'U', 'S', 0x00A2, ' ', 'J', 'P', 0x00A5}; // US¢ JP¥ WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); @@ -111,7 +124,7 @@ TEST_F(WordBreakerTest, zwjEmojiSequences) { UTF16(0x1F431), 0x200D, UTF16(0x1F464), }; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(7, breaker.next()); // after man + zwj + heart + zwj + man @@ -134,7 +147,7 @@ TEST_F(WordBreakerTest, emojiWithModifier) { 0x270C, 0xFE0F, UTF16(0x1F3FF) // victory hand + emoji style + type 6 fitzpatrick modifier }; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(4, breaker.next()); // after boy + type 1-2 fitzpatrick modifier @@ -157,7 +170,7 @@ TEST_F(WordBreakerTest, flagsSequenceSingleFlag) { ParseUnicode(buf, BUF_SIZE, flags.c_str(), &size, nullptr); WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, size); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(kFlagLength, breaker.next()); // end of the first flag @@ -182,7 +195,7 @@ TEST_F(WordBreakerTest, flagsSequence) { ParseUnicode(buf, BUF_SIZE, flagSequence.c_str(), &size, nullptr); WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, size); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(kFlagLength, breaker.next()); // end of the first flag sequence @@ -197,7 +210,7 @@ TEST_F(WordBreakerTest, punct) { uint16_t buf[] = {0x00A1, 0x00A1, 'h', 'e', 'l', 'l' ,'o', ',', ' ', 'w', 'o', 'r', 'l', 'd', '!', '!'}; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(9, breaker.next()); // after "¡¡hello, " @@ -214,7 +227,7 @@ TEST_F(WordBreakerTest, email) { uint16_t buf[] = {'f', 'o', 'o', '@', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', ' ', 'x'}; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(11, breaker.next()); // after "foo@example" @@ -233,7 +246,7 @@ TEST_F(WordBreakerTest, mailto) { uint16_t buf[] = {'m', 'a', 'i', 'l', 't', 'o', ':', 'f', 'o', 'o', '@', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', ' ', 'x'}; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(7, breaker.next()); // after "mailto:" @@ -257,7 +270,7 @@ TEST_F(WordBreakerTest, emailNonAscii) { uint16_t buf[] = {'f', 'o', 'o', '@', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', 0x4E00}; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(11, breaker.next()); // after "foo@example" @@ -276,7 +289,7 @@ TEST_F(WordBreakerTest, emailCombining) { uint16_t buf[] = {'f', 'o', 'o', '@', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', 0x0303, ' ', 'x'}; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(11, breaker.next()); // after "foo@example" @@ -294,7 +307,7 @@ TEST_F(WordBreakerTest, emailCombining) { TEST_F(WordBreakerTest, lonelyAt) { uint16_t buf[] = {'a', ' ', '@', ' ', 'b'}; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(2, breaker.next()); // after "a " @@ -314,7 +327,7 @@ TEST_F(WordBreakerTest, url) { uint16_t buf[] = {'h', 't', 't', 'p', ':', '/', '/', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', ' ', 'x'}; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(5, breaker.next()); // after "http:" @@ -340,7 +353,7 @@ TEST_F(WordBreakerTest, urlBreakChars) { uint16_t buf[] = {'h', 't', 't', 'p', ':', '/', '/', 'a', '.', 'b', '/', '~', 'c', ',', 'd', '-', 'e', '?', 'f', '=', 'g', '&', 'h', '#', 'i', '%', 'j', '_', 'k', '/', 'l'}; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(5, breaker.next()); // after "http:" @@ -399,7 +412,7 @@ TEST_F(WordBreakerTest, urlBreakChars) { TEST_F(WordBreakerTest, urlNoHyphenBreak) { uint16_t buf[] = {'h', 't', 't', 'p', ':', '/', '/', 'a', '-', '/', 'b'}; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(5, breaker.next()); // after "http:" @@ -415,7 +428,7 @@ TEST_F(WordBreakerTest, urlNoHyphenBreak) { TEST_F(WordBreakerTest, urlEndsWithSlash) { uint16_t buf[] = {'h', 't', 't', 'p', ':', '/', '/', 'a', '/'}; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ(5, breaker.next()); // after "http:" @@ -431,7 +444,7 @@ TEST_F(WordBreakerTest, urlEndsWithSlash) { TEST_F(WordBreakerTest, emailStartsWithSlash) { uint16_t buf[] = {'/', 'a', '@', 'b'}; WordBreaker breaker; - breaker.setLocale(icu::Locale::getEnglish()); + breaker.setLocale(icu::Locale::getUS()); breaker.setText(buf, NELEM(buf)); EXPECT_EQ(0, breaker.current()); EXPECT_EQ((ssize_t)NELEM(buf), breaker.next()); // end From 22d4e7e3f34ebd01aac522a0a7022a43941e5269 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Mon, 6 Mar 2017 14:05:23 -0800 Subject: [PATCH 237/364] Remove sample directory Since there are no known users of Minikin outside Android yet, these files are simply a maintenance burden with no actual benefit. Removing the samples until there are potential external users. Test: Not needed Change-Id: If7f1fb775cae427fbe31b86c202d1380c701bf28 --- engine/src/flutter/sample/Android.mk | 69 ---------- engine/src/flutter/sample/MinikinSkia.cpp | 68 ---------- engine/src/flutter/sample/MinikinSkia.h | 40 ------ engine/src/flutter/sample/example.cpp | 100 -------------- engine/src/flutter/sample/example_skia.cpp | 150 --------------------- 5 files changed, 427 deletions(-) delete mode 100644 engine/src/flutter/sample/Android.mk delete mode 100644 engine/src/flutter/sample/MinikinSkia.cpp delete mode 100644 engine/src/flutter/sample/MinikinSkia.h delete mode 100644 engine/src/flutter/sample/example.cpp delete mode 100644 engine/src/flutter/sample/example_skia.cpp diff --git a/engine/src/flutter/sample/Android.mk b/engine/src/flutter/sample/Android.mk deleted file mode 100644 index c4a644d74d5..00000000000 --- a/engine/src/flutter/sample/Android.mk +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (C) 2013 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. - -LOCAL_PATH:= $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES += \ - external/harfbuzz_ng/src \ - external/freetype/include \ - frameworks/minikin/include - -LOCAL_SRC_FILES:= example.cpp - -LOCAL_SHARED_LIBRARIES += \ - libutils \ - liblog \ - libcutils \ - libharfbuzz_ng \ - libicuuc \ - libft2 \ - libpng \ - libz \ - libminikin - -LOCAL_MODULE:= minikin_example - -include $(BUILD_EXECUTABLE) - - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAG := tests - -LOCAL_C_INCLUDES += \ - external/harfbuzz_ng/src \ - external/freetype/include \ - frameworks/minikin/include \ - external/skia/src/core - -LOCAL_SRC_FILES:= example_skia.cpp \ - MinikinSkia.cpp - -LOCAL_SHARED_LIBRARIES += \ - libutils \ - liblog \ - libcutils \ - libharfbuzz_ng \ - libicuuc \ - libskia \ - libminikin \ - libft2 - -LOCAL_MODULE:= minikin_skia_example - -include $(BUILD_EXECUTABLE) diff --git a/engine/src/flutter/sample/MinikinSkia.cpp b/engine/src/flutter/sample/MinikinSkia.cpp deleted file mode 100644 index 1ba7cccb417..00000000000 --- a/engine/src/flutter/sample/MinikinSkia.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include - -#include -#include "MinikinSkia.h" - -namespace minikin { - -MinikinFontSkia::MinikinFontSkia(sk_sp typeface) : - MinikinFont(typeface->uniqueID()), - mTypeface(std::move(typeface)) { -} - -static void MinikinFontSkia_SetSkiaPaint(sk_sp typeface, SkPaint* skPaint, const MinikinPaint& paint) { - skPaint->setTypeface(std::move(typeface)); - skPaint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); - // TODO: set more paint parameters from Minikin - skPaint->setTextSize(paint.size); -} - -float MinikinFontSkia::GetHorizontalAdvance(uint32_t glyph_id, - const MinikinPaint &paint) const { - SkPaint skPaint; - uint16_t glyph16 = glyph_id; - SkScalar skWidth; - MinikinFontSkia_SetSkiaPaint(mTypeface, &skPaint, paint); - skPaint.getTextWidths(&glyph16, sizeof(glyph16), &skWidth, NULL); -#ifdef VERBOSE - ALOGD("width for typeface %d glyph %d = %f", mTypeface->uniqueID(), glyph_id -#endif - return skWidth; -} - -void MinikinFontSkia::GetBounds(MinikinRect* bounds, uint32_t glyph_id, - const MinikinPaint& paint) const { - SkPaint skPaint; - uint16_t glyph16 = glyph_id; - SkRect skBounds; - MinikinFontSkia_SetSkiaPaint(mTypeface, &skPaint, paint); - skPaint.getTextWidths(&glyph16, sizeof(glyph16), NULL, &skBounds); - bounds->mLeft = skBounds.fLeft; - bounds->mTop = skBounds.fTop; - bounds->mRight = skBounds.fRight; - bounds->mBottom = skBounds.fBottom; -} - -const void* MinikinFontSkia::GetTable(uint32_t tag, size_t* size, - MinikinDestroyFunc* destroy) const { - // we don't have a buffer to the font data, copy to own buffer - const size_t tableSize = mTypeface->getTableSize(tag); - *size = tableSize; - if (tableSize == 0) { - return nullptr; - } - void* buf = malloc(tableSize); - if (buf == nullptr) { - return nullptr; - } - mTypeface->getTableData(tag, 0, tableSize, buf); - *destroy = free; - return buf; -} - -SkTypeface *MinikinFontSkia::GetSkTypeface() const { - return mTypeface.get(); -} - -} // namespace minikin diff --git a/engine/src/flutter/sample/MinikinSkia.h b/engine/src/flutter/sample/MinikinSkia.h deleted file mode 100644 index 5ebf1b61617..00000000000 --- a/engine/src/flutter/sample/MinikinSkia.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2016 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. - */ -namespace minikin { - -class MinikinFontSkia : public MinikinFont { -public: - explicit MinikinFontSkia(sk_sp typeface); - - float GetHorizontalAdvance(uint32_t glyph_id, - const MinikinPaint &paint) const; - - void GetBounds(MinikinRect* bounds, uint32_t glyph_id, - const MinikinPaint& paint) const; - - const std::vector& GetAxes() const { - return mAxes; - } - const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) const; - - SkTypeface *GetSkTypeface() const; - -private: - sk_sp mTypeface; - std::vector mAxes; -}; - -} // namespace minikin diff --git a/engine/src/flutter/sample/example.cpp b/engine/src/flutter/sample/example.cpp deleted file mode 100644 index 3df09050030..00000000000 --- a/engine/src/flutter/sample/example.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2013 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. - */ - -// This is a test program that uses Minikin to layout and draw some text. -// At the moment, it just draws a string into /data/local/tmp/foo.pgm. - -#include -#include -#include - -#include -#include - -#include -#include - -using std::vector; -using namespace minikin; - -FT_Library library; // TODO: this should not be a global - -FontCollection *makeFontCollection() { - vector>typefaces; - const char *fns[] = { - "/system/fonts/Roboto-Regular.ttf", - "/system/fonts/Roboto-Italic.ttf", - "/system/fonts/Roboto-BoldItalic.ttf", - "/system/fonts/Roboto-Light.ttf", - "/system/fonts/Roboto-Thin.ttf", - "/system/fonts/Roboto-Bold.ttf", - "/system/fonts/Roboto-ThinItalic.ttf", - "/system/fonts/Roboto-LightItalic.ttf" - }; - - FT_Face face; - FT_Error error; - std::vector fonts; - for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) { - const char *fn = fns[i]; - printf("adding %s\n", fn); - error = FT_New_Face(library, fn, 0, &face); - if (error != 0) { - printf("error loading %s, %d\n", fn, error); - } - std::shared_ptr font(new MinikinFontFreeType(face)); - fonts.push_back(Font(font, FontStyle())); - } - std::shared_ptr family(new FontFamily(std::move(fonts))); - typefaces.push_back(family); - -#if 1 - const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf"; - error = FT_New_Face(library, fn, 0, &face); - std::shared_ptr font(new MinikinFontFreeType(face)); - family.reset(new FontFamily(std::vector({ Font(font, FontStyle()) }))); - typefaces.push_back(family); -#endif - - return new FontCollection(typefaces); -} - -int runMinikinTest() { - FT_Error error = FT_Init_FreeType(&library); - if (error) { - return -1; - } - std::shared_ptr collection(makeFontCollection()); - Layout layout(collection); - const char *text = "fine world \xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa5\x87"; - int bidiFlags = 0; - FontStyle fontStyle; - MinikinPaint paint; - paint.size = 32; - icu::UnicodeString icuText = icu::UnicodeString::fromUTF8(text); - layout.doLayout(icuText.getBuffer(), 0, icuText.length(), icuText.length(), bidiFlags, fontStyle, paint); - layout.dump(); - Bitmap bitmap(250, 50); - layout.draw(&bitmap, 10, 40, 32); - std::ofstream o; - o.open("/data/local/tmp/foo.pgm", std::ios::out | std::ios::binary); - bitmap.writePnm(o); - return 0; -} - -int main() { - return runMinikinTest(); -} diff --git a/engine/src/flutter/sample/example_skia.cpp b/engine/src/flutter/sample/example_skia.cpp deleted file mode 100644 index 6fa788b9e77..00000000000 --- a/engine/src/flutter/sample/example_skia.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright (C) 2013 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. - */ - -// This is a test program that uses Minikin to layout and draw some text. -// At the moment, it just draws a string into /data/local/tmp/foo.pgm. - -#include -#include -#include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - -#include "MinikinSkia.h" - -using std::vector; - -namespace minikin { - -FT_Library library; // TODO: this should not be a global - -FontCollection *makeFontCollection() { - vector> typefaces; - const char *fns[] = { - "/system/fonts/Roboto-Regular.ttf", - "/system/fonts/Roboto-Italic.ttf", - "/system/fonts/Roboto-BoldItalic.ttf", - "/system/fonts/Roboto-Light.ttf", - "/system/fonts/Roboto-Thin.ttf", - "/system/fonts/Roboto-Bold.ttf", - "/system/fonts/Roboto-ThinItalic.ttf", - "/system/fonts/Roboto-LightItalic.ttf" - }; - - std::vector fonts; - for (size_t i = 0; i < sizeof(fns)/sizeof(fns[0]); i++) { - const char *fn = fns[i]; - sk_sp skFace = SkTypeface::MakeFromFile(fn); - std::shared_ptr font(new MinikinFontSkia(std::move(skFace))); - fonts.push_back(Font(font, FontStyle())); - } - std::shared_ptr family(new FontFamily(std::move(fonts))); - typefaces.push_back(family); - -#if 1 - const char *fn = "/system/fonts/DroidSansDevanagari-Regular.ttf"; - sk_sp skFace = SkTypeface::MakeFromFile(fn); - std::shared_ptr font(new MinikinFontSkia(std::move(skFace))); - family.reset(new FontFamily(std::vector({ Font(font, FontStyle()) }))); - typefaces.push_back(family); -#endif - return new FontCollection(typefaces); -} - -// Maybe move to MinikinSkia (esp. instead of opening GetSkTypeface publicly)? - -void drawToSkia(SkCanvas *canvas, SkPaint *paint, Layout *layout, float x, float y) { - size_t nGlyphs = layout->nGlyphs(); - uint16_t *glyphs = new uint16_t[nGlyphs]; - SkPoint *pos = new SkPoint[nGlyphs]; - SkTypeface *lastFace = NULL; - SkTypeface *skFace = NULL; - size_t start = 0; - - paint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); - for (size_t i = 0; i < nGlyphs; i++) { - const MinikinFontSkia *mfs = static_cast(layout->getFont(i)); - skFace = mfs->GetSkTypeface(); - glyphs[i] = layout->getGlyphId(i); - pos[i].fX = x + layout->getX(i); - pos[i].fY = y + layout->getY(i); - if (i > 0 && skFace != lastFace) { - paint->setTypeface(sk_ref_sp(lastFace)); - canvas->drawPosText(glyphs + start, (i - start) << 1, pos + start, *paint); - start = i; - } - lastFace = skFace; - } - paint->setTypeface(sk_ref_sp(skFace)); - canvas->drawPosText(glyphs + start, (nGlyphs - start) << 1, pos + start, *paint); - delete[] glyphs; - delete[] pos; -} - -int runMinikinTest() { - FT_Error error = FT_Init_FreeType(&library); - if (error) { - return -1; - } - - std::shared_ptr collection(makeFontCollection()); - Layout layout(collection); - const char *text = "fine world \xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa5\x87"; - int bidiFlags = 0; - FontStyle fontStyle(7); - MinikinPaint minikinPaint; - minikinPaint.size = 32; - icu::UnicodeString icuText = icu::UnicodeString::fromUTF8(text); - layout.doLayout(icuText.getBuffer(), 0, icuText.length(), icuText.length(), bidiFlags, fontStyle, minikinPaint); - layout.dump(); - - SkAutoGraphics ag; - - int width = 800; - int height = 600; - SkBitmap bitmap; - bitmap.allocN32Pixels(width, height); - SkCanvas canvas(bitmap); - SkPaint paint; - paint.setARGB(255, 0, 0, 128); - paint.setStyle(SkPaint::kStroke_Style); - paint.setStrokeWidth(2); - paint.setTextSize(100); - paint.setAntiAlias(true); - canvas.drawLine(10, 300, 10 + layout.getAdvance(), 300, paint); - paint.setStyle(SkPaint::kFill_Style); - drawToSkia(&canvas, &paint, &layout, 10, 300); - - SkFILEWStream file("/data/local/tmp/foo.png"); - SkEncodeImage(&file, bitmap, SkEncodedImageFormat::kPNG, 100); - return 0; -} - -} // namespace minikin - -int main(int argc, const char** argv) { - return minikin::runMinikinTest(); -} From 068c7ba2eab4cd546f74665d7a9bcc549584d5ce Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Mon, 27 Feb 2017 18:54:01 -0800 Subject: [PATCH 238/364] Customizable min suffix/prefix length for hyphenation in Minikin With this change, different languages can have a different minimum length for suffix and prefixes when hyphenating. Previously, the defaults used for English, 2 and 3, were used for every language. Bug: 35712376 Test: Minikin unit tests were updated and the pass Change-Id: Iffaf11c6b208c57d28d45b17246e177572dc1210 --- engine/src/flutter/app/HyphTool.cpp | 6 +-- .../src/flutter/include/minikin/Hyphenator.h | 8 +-- .../src/flutter/libs/minikin/Hyphenator.cpp | 16 +++--- .../flutter/tests/perftests/Hyphenator.cpp | 12 +++-- .../flutter/tests/unittest/HyphenatorTest.cpp | 51 +++++++++---------- 5 files changed, 47 insertions(+), 46 deletions(-) diff --git a/engine/src/flutter/app/HyphTool.cpp b/engine/src/flutter/app/HyphTool.cpp index cdb1466f409..403d37439a8 100644 --- a/engine/src/flutter/app/HyphTool.cpp +++ b/engine/src/flutter/app/HyphTool.cpp @@ -11,7 +11,7 @@ using minikin::HyphenationType; using minikin::Hyphenator; -Hyphenator* loadHybFile(const char* fn) { +Hyphenator* loadHybFile(const char* fn, int minPrefix, int minSuffix) { struct stat statbuf; int status = stat(fn, &statbuf); if (status < 0) { @@ -32,11 +32,11 @@ Hyphenator* loadHybFile(const char* fn) { delete[] buf; return nullptr; } - return Hyphenator::loadBinary(buf); + return Hyphenator::loadBinary(buf, minPrefix, minSuffix); } int main(int argc, char** argv) { - Hyphenator* hyph = loadHybFile("/tmp/en.hyb"); // should also be configurable + Hyphenator* hyph = loadHybFile("/tmp/en.hyb", 2, 3); // should also be configurable std::vector result; std::vector word; if (argc < 2) { diff --git a/engine/src/flutter/include/minikin/Hyphenator.h b/engine/src/flutter/include/minikin/Hyphenator.h index ea81813745a..2b8ccb71a7d 100644 --- a/engine/src/flutter/include/minikin/Hyphenator.h +++ b/engine/src/flutter/include/minikin/Hyphenator.h @@ -136,7 +136,7 @@ public: // at least as long as the Hyphenator object. // Note: nullptr is valid input, in which case the hyphenator only processes soft hyphens. - static Hyphenator* loadBinary(const uint8_t* patternData); + static Hyphenator* loadBinary(const uint8_t* patternData, size_t minPrefix, size_t minSuffix); private: // apply various hyphenation rules including hard and soft hyphens, ignoring patterns @@ -153,17 +153,13 @@ private: void hyphenateFromCodes(HyphenationType* result, const uint16_t* codes, size_t len, HyphenationType hyphenValue); - // TODO: these should become parameters, as they might vary by locale, screen size, and - // possibly explicit user control. - static const int MIN_PREFIX = 2; - static const int MIN_SUFFIX = 3; - // See also LONGEST_HYPHENATED_WORD in LineBreaker.cpp. Here the constant is used so // that temporary buffers can be stack-allocated without waste, which is a slightly // different use case. It measures UTF-16 code units. static const size_t MAX_HYPHENATED_SIZE = 64; const uint8_t* patternData; + size_t minPrefix, minSuffix; // accessors for binary data const Header* getHeader() const { diff --git a/engine/src/flutter/libs/minikin/Hyphenator.cpp b/engine/src/flutter/libs/minikin/Hyphenator.cpp index 5ec82feb506..0605b278312 100644 --- a/engine/src/flutter/libs/minikin/Hyphenator.cpp +++ b/engine/src/flutter/libs/minikin/Hyphenator.cpp @@ -108,9 +108,11 @@ struct Header { } }; -Hyphenator* Hyphenator::loadBinary(const uint8_t* patternData) { +Hyphenator* Hyphenator::loadBinary(const uint8_t* patternData, size_t minPrefix, size_t minSuffix) { Hyphenator* result = new Hyphenator; result->patternData = patternData; + result->minPrefix = minPrefix; + result->minSuffix = minSuffix; return result; } @@ -120,7 +122,7 @@ void Hyphenator::hyphenate(vector* result, const uint16_t* word result->resize(len); const size_t paddedLen = len + 2; // start and stop code each count for 1 if (patternData != nullptr && - (int)len >= MIN_PREFIX + MIN_SUFFIX && paddedLen <= MAX_HYPHENATED_SIZE) { + len >= minPrefix + minSuffix && paddedLen <= MAX_HYPHENATED_SIZE) { uint16_t alpha_codes[MAX_HYPHENATED_SIZE]; const HyphenationType hyphenValue = alphabetLookup(alpha_codes, word, len); if (hyphenValue != HyphenationType::DONT_BREAK) { @@ -307,7 +309,7 @@ void Hyphenator::hyphenateWithNoPatterns(HyphenationType* result, const uint16_t result[i] = hyphenationTypeBasedOnScript(word[i]); } } else if (prevChar == CHAR_MIDDLE_DOT - && MIN_PREFIX < i && i <= len - MIN_SUFFIX + && minPrefix < i && i <= len - minSuffix && ((word[i - 2] == 'l' && word[i] == 'l') || (word[i - 2] == 'L' && word[i] == 'L')) && strcmp(locale.getLanguage(), "ca") == 0) { @@ -392,7 +394,7 @@ void Hyphenator::hyphenateFromCodes(HyphenationType* result, const uint16_t* cod uint32_t link_shift = trie->link_shift; uint32_t link_mask = trie->link_mask; uint32_t pattern_shift = trie->pattern_shift; - size_t maxOffset = len - MIN_SUFFIX - 1; + size_t maxOffset = len - minSuffix - 1; for (size_t i = 0; i < len - 1; i++) { uint32_t node = 0; // index into Trie table for (size_t j = i; j < len; j++) { @@ -414,7 +416,7 @@ void Hyphenator::hyphenateFromCodes(HyphenationType* result, const uint16_t* cod const uint8_t* pat_buf = pattern->buf(pat_entry); int offset = j + 1 - (pat_len + pat_shift); // offset is the index within buffer that lines up with the start of pat_buf - int start = std::max(MIN_PREFIX - offset, 0); + int start = std::max((int)minPrefix - offset, 0); int end = std::min(pat_len, (int)maxOffset - offset); for (int k = start; k < end; k++) { buffer[offset + k] = std::max(buffer[offset + k], pat_buf[k]); @@ -423,8 +425,8 @@ void Hyphenator::hyphenateFromCodes(HyphenationType* result, const uint16_t* cod } } // Since the above calculation does not modify values outside - // [MIN_PREFIX, len - MIN_SUFFIX], they are left as 0 = DONT_BREAK. - for (size_t i = MIN_PREFIX; i < maxOffset; i++) { + // [minPrefix, len - minSuffix], they are left as 0 = DONT_BREAK. + for (size_t i = minPrefix; i < maxOffset; i++) { // Hyphenation opportunities happen when the hyphenation numbers are odd. result[i] = (buffer[i] & 1u) ? hyphenValue : HyphenationType::DONT_BREAK; } diff --git a/engine/src/flutter/tests/perftests/Hyphenator.cpp b/engine/src/flutter/tests/perftests/Hyphenator.cpp index 1e6411f76df..2107e0575ce 100644 --- a/engine/src/flutter/tests/perftests/Hyphenator.cpp +++ b/engine/src/flutter/tests/perftests/Hyphenator.cpp @@ -22,30 +22,34 @@ namespace minikin { const char* enUsHyph = "/system/usr/hyphen-data/hyph-en-us.hyb"; +const int enUsMinPrefix = 2; +const int enUsMinSuffix = 3; const icu::Locale& usLocale = icu::Locale::getUS(); static void BM_Hyphenator_short_word(benchmark::State& state) { - Hyphenator* hyphenator = Hyphenator::loadBinary(readWholeFile(enUsHyph).data()); + Hyphenator* hyphenator = Hyphenator::loadBinary( + readWholeFile(enUsHyph).data(), enUsMinPrefix, enUsMinSuffix); std::vector word = utf8ToUtf16("hyphen"); std::vector result; while (state.KeepRunning()) { hyphenator->hyphenate(&result, word.data(), word.size(), usLocale); } - Hyphenator::loadBinary(nullptr); + Hyphenator::loadBinary(nullptr, 2, 2); } // TODO: Use BENCHMARK_CAPTURE for parametrise. BENCHMARK(BM_Hyphenator_short_word); static void BM_Hyphenator_long_word(benchmark::State& state) { - Hyphenator* hyphenator = Hyphenator::loadBinary(readWholeFile(enUsHyph).data()); + Hyphenator* hyphenator = Hyphenator::loadBinary( + readWholeFile(enUsHyph).data(), enUsMinPrefix, enUsMinSuffix); std::vector word = utf8ToUtf16( "Pneumonoultramicroscopicsilicovolcanoconiosis"); std::vector result; while (state.KeepRunning()) { hyphenator->hyphenate(&result, word.data(), word.size(), usLocale); } - Hyphenator::loadBinary(nullptr); + Hyphenator::loadBinary(nullptr, 2, 2); } // TODO: Use BENCHMARK_CAPTURE for parametrise. diff --git a/engine/src/flutter/tests/unittest/HyphenatorTest.cpp b/engine/src/flutter/tests/unittest/HyphenatorTest.cpp index 6265c2c6c1b..ecd58a2ea08 100644 --- a/engine/src/flutter/tests/unittest/HyphenatorTest.cpp +++ b/engine/src/flutter/tests/unittest/HyphenatorTest.cpp @@ -51,7 +51,7 @@ const uint16_t EN_DASH = 0x2013; // Simple test for US English. This tests "table", which happens to be the in the exceptions list. TEST_F(HyphenatorTest, usEnglishAutomaticHyphenation) { - Hyphenator* hyphenator = Hyphenator::loadBinary(readWholeFile(usHyph).data()); + Hyphenator* hyphenator = Hyphenator::loadBinary(readWholeFile(usHyph).data(), 2, 3); const uint16_t word[] = {'t', 'a', 'b', 'l', 'e'}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -65,22 +65,21 @@ TEST_F(HyphenatorTest, usEnglishAutomaticHyphenation) { // Catalan l·l should break as l-/l TEST_F(HyphenatorTest, catalanMiddleDot) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); - const uint16_t word[] = {'l', 'l', MIDDLE_DOT, 'l', 'l', 'l'}; + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); + const uint16_t word[] = {'l', 'l', MIDDLE_DOT, 'l', 'l'}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), catalanLocale); - EXPECT_EQ((size_t) 6, result.size()); + EXPECT_EQ((size_t) 5, result.size()); EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); EXPECT_EQ(HyphenationType::DONT_BREAK, result[2]); EXPECT_EQ(HyphenationType::BREAK_AND_REPLACE_WITH_HYPHEN, result[3]); EXPECT_EQ(HyphenationType::DONT_BREAK, result[4]); - EXPECT_EQ(HyphenationType::DONT_BREAK, result[5]); } // Catalan l·l should not break if the word is too short. TEST_F(HyphenatorTest, catalanMiddleDotShortWord) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {'l', MIDDLE_DOT, 'l'}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), catalanLocale); @@ -92,7 +91,7 @@ TEST_F(HyphenatorTest, catalanMiddleDotShortWord) { // If we break on a hyphen in Polish, the hyphen should be repeated on the next line. TEST_F(HyphenatorTest, polishHyphen) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {'x', HYPHEN, 'y'}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), polishLocale); @@ -104,7 +103,7 @@ TEST_F(HyphenatorTest, polishHyphen) { // If the language is Polish but the script is not Latin, don't use Polish rules for hyphenation. TEST_F(HyphenatorTest, polishHyphenButNonLatinWord) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {GREEK_LOWER_ALPHA, HYPHEN, GREEK_LOWER_ALPHA}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), polishLocale); @@ -117,7 +116,7 @@ TEST_F(HyphenatorTest, polishHyphenButNonLatinWord) { // Polish en dash doesn't repeat on next line (as far as we know), but just provides a break // opportunity. TEST_F(HyphenatorTest, polishEnDash) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {'x', EN_DASH, 'y'}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), polishLocale); @@ -129,7 +128,7 @@ TEST_F(HyphenatorTest, polishEnDash) { // In Latin script text, soft hyphens should insert a visible hyphen if broken at. TEST_F(HyphenatorTest, latinSoftHyphen) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {'x', SOFT_HYPHEN, 'y'}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -141,7 +140,7 @@ TEST_F(HyphenatorTest, latinSoftHyphen) { // Soft hyphens at the beginning of a word are not useful in linebreaking. TEST_F(HyphenatorTest, latinSoftHyphenStartingTheWord) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {SOFT_HYPHEN, 'y'}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -152,7 +151,7 @@ TEST_F(HyphenatorTest, latinSoftHyphenStartingTheWord) { // In Malayalam script text, soft hyphens should not insert a visible hyphen if broken at. TEST_F(HyphenatorTest, malayalamSoftHyphen) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {MALAYALAM_KA, SOFT_HYPHEN, MALAYALAM_KA}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -164,7 +163,7 @@ TEST_F(HyphenatorTest, malayalamSoftHyphen) { // In automatically hyphenated Malayalam script text, we should not insert a visible hyphen. TEST_F(HyphenatorTest, malayalamAutomaticHyphenation) { - Hyphenator* hyphenator = Hyphenator::loadBinary(readWholeFile(malayalamHyph).data()); + Hyphenator* hyphenator = Hyphenator::loadBinary(readWholeFile(malayalamHyph).data(), 2, 2); const uint16_t word[] = { MALAYALAM_KA, MALAYALAM_KA, MALAYALAM_KA, MALAYALAM_KA, MALAYALAM_KA}; std::vector result; @@ -173,13 +172,13 @@ TEST_F(HyphenatorTest, malayalamAutomaticHyphenation) { EXPECT_EQ(HyphenationType::DONT_BREAK, result[0]); EXPECT_EQ(HyphenationType::DONT_BREAK, result[1]); EXPECT_EQ(HyphenationType::BREAK_AND_DONT_INSERT_HYPHEN, result[2]); - EXPECT_EQ(HyphenationType::DONT_BREAK, result[3]); + EXPECT_EQ(HyphenationType::BREAK_AND_DONT_INSERT_HYPHEN, result[3]); EXPECT_EQ(HyphenationType::DONT_BREAK, result[4]); } // In Armenian script text, soft hyphens should insert an Armenian hyphen if broken at. TEST_F(HyphenatorTest, aremenianSoftHyphen) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {ARMENIAN_AYB, SOFT_HYPHEN, ARMENIAN_AYB}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -192,7 +191,7 @@ TEST_F(HyphenatorTest, aremenianSoftHyphen) { // In Hebrew script text, soft hyphens should insert a normal hyphen if broken at, for now. // We may need to change this to maqaf later. TEST_F(HyphenatorTest, hebrewSoftHyphen) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {HEBREW_ALEF, SOFT_HYPHEN, HEBREW_ALEF}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -205,7 +204,7 @@ TEST_F(HyphenatorTest, hebrewSoftHyphen) { // Soft hyphen between two Arabic letters that join should keep the joining // behavior when broken across lines. TEST_F(HyphenatorTest, arabicSoftHyphenConnecting) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {ARABIC_BEH, SOFT_HYPHEN, ARABIC_BEH}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -218,7 +217,7 @@ TEST_F(HyphenatorTest, arabicSoftHyphenConnecting) { // Arabic letters may be joining on one side, but if it's the wrong side, we // should use the normal hyphen. TEST_F(HyphenatorTest, arabicSoftHyphenNonConnecting) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {ARABIC_ALEF, SOFT_HYPHEN, ARABIC_BEH}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -230,7 +229,7 @@ TEST_F(HyphenatorTest, arabicSoftHyphenNonConnecting) { // Skip transparent characters until you find a non-transparent one. TEST_F(HyphenatorTest, arabicSoftHyphenSkipTransparents) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {ARABIC_BEH, ARABIC_ZWARAKAY, SOFT_HYPHEN, ARABIC_ZWARAKAY, ARABIC_BEH}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -245,7 +244,7 @@ TEST_F(HyphenatorTest, arabicSoftHyphenSkipTransparents) { // Skip transparent characters until you find a non-transparent one. If we get to one end without // finding anything, we are still non-joining. TEST_F(HyphenatorTest, arabicSoftHyphenTransparentsAtEnd) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {ARABIC_BEH, ARABIC_ZWARAKAY, SOFT_HYPHEN, ARABIC_ZWARAKAY}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -259,7 +258,7 @@ TEST_F(HyphenatorTest, arabicSoftHyphenTransparentsAtEnd) { // Skip transparent characters until you find a non-transparent one. If we get to one end without // finding anything, we are still non-joining. TEST_F(HyphenatorTest, arabicSoftHyphenTransparentsAtStart) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {ARABIC_ZWARAKAY, SOFT_HYPHEN, ARABIC_ZWARAKAY, ARABIC_BEH}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -272,7 +271,7 @@ TEST_F(HyphenatorTest, arabicSoftHyphenTransparentsAtStart) { // In Unified Canadian Aboriginal script (UCAS) text, soft hyphens should insert a UCAS hyphen. TEST_F(HyphenatorTest, ucasSoftHyphen) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {UCAS_E, SOFT_HYPHEN, UCAS_E}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -285,7 +284,7 @@ TEST_F(HyphenatorTest, ucasSoftHyphen) { // Presently, soft hyphen looks at the character after it to determine hyphenation type. This is a // little arbitrary, but let's test it anyway. TEST_F(HyphenatorTest, mixedScriptSoftHyphen) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {'a', SOFT_HYPHEN, UCAS_E}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -297,7 +296,7 @@ TEST_F(HyphenatorTest, mixedScriptSoftHyphen) { // Hard hyphens provide a breaking opportunity with nothing extra inserted. TEST_F(HyphenatorTest, hardHyphen) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {'x', HYPHEN, 'y'}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -309,7 +308,7 @@ TEST_F(HyphenatorTest, hardHyphen) { // Hyphen-minuses also provide a breaking opportunity with nothing extra inserted. TEST_F(HyphenatorTest, hyphenMinus) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {'x', HYPHEN_MINUS, 'y'}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); @@ -322,7 +321,7 @@ TEST_F(HyphenatorTest, hyphenMinus) { // If the word starts with a hard hyphen or hyphen-minus, it doesn't make sense to break // it at that point. TEST_F(HyphenatorTest, startingHyphenMinus) { - Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr); + Hyphenator* hyphenator = Hyphenator::loadBinary(nullptr, 2, 2); const uint16_t word[] = {HYPHEN_MINUS, 'y'}; std::vector result; hyphenator->hyphenate(&result, word, NELEM(word), usLocale); From 684ac0b636cf0d9b0db0841e125a79c89ab39c03 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 17 Jan 2017 15:56:28 +0900 Subject: [PATCH 239/364] Reduce memory usage of FontCollection. This is 2nd attempt at I9e01d237c9adcb05e200932401cb1a4780049f86. The previous CL was reverted because 8-bit integers were too small to store the indices of mFamilyVec. This CL changes it to 16-bit integers since size_t is still unnecessary large. Theoretically, 32-bit integers are necessary for the indices of mFamilyVec since the size of mFamilyVec can be 0x10EE01. However, in practice, 16-bit integers are enough for the indices of mFamilyVec. The length of mFamilyVec for the system fonts is 2084. Even if the developers load their own very large fonts, it can only increase the number of elements in mFamilyVec to at most 0x10FF. As the result, memory usage of the FontCollections for the system fonts decreases as follows. 64-bit process: before: 398,264 bytes, after: 282,568 bytes (-115,696 bytes) 32-bit process: before: 199,132 bytes, after: 149,548 bytes (-49,584 bytes) Bug: 33562608 Test: Verified Emoji and CJK characters are present. Test: android.text.cts.EmojiTest passed Test: Minikin unit tests passed Change-Id: I6796fd55ac30fe30528a212ebf6097b1d672e2f8 --- .../flutter/include/minikin/FontCollection.h | 15 +++++++++---- .../flutter/libs/minikin/FontCollection.cpp | 21 +++++++++++-------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 23645387997..d5fc5a11bd2 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -59,9 +59,14 @@ private: static const int kLogCharsPerPage = 8; static const int kPageMask = (1 << kLogCharsPerPage) - 1; + // mFamilyVec holds the indices of the mFamilies and mRanges holds the range of indices of + // mFamilyVec. The maximum number of pages is 0x10FF (U+10FFFF >> 8). The maximum number of + // the fonts is 0xFF. Thus, technically the maximum length of mFamilyVec is 0x10EE01 + // (0x10FF * 0xFF). However, in practice, 16-bit integers are enough since most fonts supports + // only limited range of code points. struct Range { - size_t start; - size_t end; + uint16_t start; + uint16_t end; }; // Initialize the FontCollection. @@ -96,10 +101,12 @@ private: // Following two vectors are pre-calculated tables for resolving coverage faster. // For example, to iterate over all fonts which support Unicode code point U+XXYYZZ, - // iterate font families from mFamilyVec[mRanges[0xXXYY].start] to + // iterate font families index from mFamilyVec[mRanges[0xXXYY].start] to // mFamilyVec[mRange[0xXXYY].end] instead of whole mFamilies. + // This vector contains indices into mFamilies. + // This vector can't be empty. std::vector mRanges; - std::vector> mFamilyVec; + std::vector mFamilyVec; // This vector has pointers to the font family instances which have cmap 14 subtables. std::vector> mVSFamilyVec; diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 8ec302b5eab..a3d2d974e0e 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -118,8 +118,9 @@ void FontCollection::init(const vector>& typefaces) nTypefaces = mFamilies.size(); LOG_ALWAYS_FATAL_IF(nTypefaces == 0, "Font collection must have at least one valid typeface"); + LOG_ALWAYS_FATAL_IF(nTypefaces > 254, + "Font collection may only have up to 254 font families."); size_t nPages = (mMaxChar + kPageMask) >> kLogCharsPerPage; - size_t offset = 0; // TODO: Use variation selector map for mRanges construction. // A font can have a glyph for a base code point and variation selector pair but no glyph for // the base code point without variation selector. The family won't be listed in the range in @@ -131,12 +132,11 @@ void FontCollection::init(const vector>& typefaces) #ifdef VERBOSE_DEBUG ALOGD("i=%zd: range start = %zd\n", i, offset); #endif - range->start = offset; + range->start = mFamilyVec.size(); for (size_t j = 0; j < nTypefaces; j++) { if (lastChar[j] < (i + 1) << kLogCharsPerPage) { const std::shared_ptr& family = mFamilies[j]; - mFamilyVec.push_back(family); - offset++; + mFamilyVec.push_back(static_cast(j)); uint32_t nextChar = family->getCoverage().nextSetBit((i + 1) << kLogCharsPerPage); #ifdef VERBOSE_DEBUG ALOGD("nextChar = %d (j = %zd)\n", nextChar, j); @@ -144,8 +144,11 @@ void FontCollection::init(const vector>& typefaces) lastChar[j] = nextChar; } } - range->end = offset; + range->end = mFamilyVec.size(); } + // See the comment in Range for more details. + LOG_ALWAYS_FATAL_IF(mFamilyVec.size() >= 0xFFFF, + "Exceeded the maximum indexable cmap coverage."); } // Special scores for the font fallback. @@ -286,11 +289,10 @@ const std::shared_ptr& FontCollection::getFamilyForChar(uint32_t ch, return mFamilies[0]; } - const std::vector>& familyVec = (vs == 0) ? mFamilyVec : mFamilies; Range range = mRanges[ch >> kLogCharsPerPage]; if (vs != 0) { - range = { 0, mFamilies.size() }; + range = { 0, static_cast(mFamilies.size()) }; } #ifdef VERBOSE_DEBUG @@ -299,7 +301,8 @@ const std::shared_ptr& FontCollection::getFamilyForChar(uint32_t ch, int bestFamilyIndex = -1; uint32_t bestScore = kUnsupportedFontScore; for (size_t i = range.start; i < range.end; i++) { - const std::shared_ptr& family = familyVec[i]; + const std::shared_ptr& family = + vs == 0 ? mFamilies[mFamilyVec[i]] : mFamilies[i]; const uint32_t score = calcFamilyScore(ch, vs, variant, langListId, family); if (score == kFirstFontScore) { // If the first font family supports the given character or variation sequence, always @@ -325,7 +328,7 @@ const std::shared_ptr& FontCollection::getFamilyForChar(uint32_t ch, } return mFamilies[0]; } - return familyVec[bestFamilyIndex]; + return vs == 0 ? mFamilies[mFamilyVec[bestFamilyIndex]] : mFamilies[bestFamilyIndex]; } const uint32_t NBSP = 0x00A0; From 0eac702718a070e8ee226e63b5f540510b425e9a Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 21 Feb 2017 15:12:43 +0900 Subject: [PATCH 240/364] Use std::mutex instead of android::Mutex This CL includes: - Stop using utils/Mutex and use std::mutex instead. - Stop using utils/Singleton. Test: minikin_tests passed Change-Id: Ib3f75b83397a546472bb5f91e066e44506e78263 --- .../flutter/include/minikin/FontCollection.h | 9 +- .../src/flutter/include/minikin/FontFamily.h | 2 + .../flutter/libs/minikin/FontCollection.cpp | 34 +++--- .../src/flutter/libs/minikin/FontFamily.cpp | 18 +-- .../libs/minikin/FontLanguageListCache.cpp | 91 ++++++++------ .../libs/minikin/FontLanguageListCache.h | 36 ++---- .../src/flutter/libs/minikin/HbFontCache.cpp | 114 ++++++++++-------- engine/src/flutter/libs/minikin/Layout.cpp | 47 ++++---- .../src/flutter/libs/minikin/MinikinFont.cpp | 2 +- .../flutter/libs/minikin/MinikinInternal.cpp | 11 +- .../flutter/libs/minikin/MinikinInternal.h | 21 ++-- .../tests/perftests/FontCollection.cpp | 2 +- .../unittest/FontCollectionItemizeTest.cpp | 6 +- .../flutter/tests/unittest/FontFamilyTest.cpp | 16 +-- .../unittest/FontLanguageListCacheTest.cpp | 49 ++++---- .../tests/unittest/HbFontCacheTest.cpp | 9 +- 16 files changed, 245 insertions(+), 222 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index d5fc5a11bd2..a3396277ecb 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -26,6 +26,8 @@ namespace minikin { +class FontLanguages; + class FontCollection { public: explicit FontCollection(const std::vector>& typefaces); @@ -73,15 +75,16 @@ private: void init(const std::vector>& typefaces); const std::shared_ptr& getFamilyForChar(uint32_t ch, uint32_t vs, - uint32_t langListId, int variant) const; + const FontLanguages& styleLanguages, int variant) const; - uint32_t calcFamilyScore(uint32_t ch, uint32_t vs, int variant, uint32_t langListId, + uint32_t calcFamilyScore(uint32_t ch, uint32_t vs, int variant, + const FontLanguages& styleLanguages, const std::shared_ptr& fontFamily) const; uint32_t calcCoverageScore(uint32_t ch, uint32_t vs, const std::shared_ptr& fontFamily) const; - static uint32_t calcLanguageMatchingScore(uint32_t userLangListId, + static uint32_t calcLanguageMatchingScore(const FontLanguages& styleLanguages, const FontFamily& fontFamily); static uint32_t calcVariantMatchingScore(int variant, const FontFamily& fontFamily); diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index c7018a6f8c0..e6eeca3237a 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -31,6 +31,7 @@ namespace minikin { class MinikinFont; +class FontLanguages; // FontStyle represents all style information needed to select an actual font // from a collection. The implementation is packed into two 32-bit words @@ -168,6 +169,7 @@ private: int mVariant; std::vector mFonts; std::unordered_set mSupportedAxes; + std::unique_ptr mLanguages; SparseBitSet mCoverage; bool mHasVSTable; diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index a3d2d974e0e..e8c05d7d77f 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -91,7 +91,7 @@ FontCollection::FontCollection(const vector>& typefa } void FontCollection::init(const vector>& typefaces) { - android::AutoMutex _l(gMinikinLock); + ScopedLock _l(gLock); mId = sNextId++; vector lastChar; size_t nTypefaces = typefaces.size(); @@ -171,7 +171,8 @@ const uint32_t kFirstFontScore = UINT32_MAX; // base character. // - kFirstFontScore: When the font is the first font family in the collection and it supports the // given character or variation sequence. -uint32_t FontCollection::calcFamilyScore(uint32_t ch, uint32_t vs, int variant, uint32_t langListId, +uint32_t FontCollection::calcFamilyScore(uint32_t ch, uint32_t vs, int variant, + const FontLanguages& styleLanguages, const std::shared_ptr& fontFamily) const { const uint32_t coverageScore = calcCoverageScore(ch, vs, fontFamily); @@ -180,7 +181,7 @@ uint32_t FontCollection::calcFamilyScore(uint32_t ch, uint32_t vs, int variant, return coverageScore; } - const uint32_t languageScore = calcLanguageMatchingScore(langListId, *fontFamily); + const uint32_t languageScore = calcLanguageMatchingScore(styleLanguages, *fontFamily); const uint32_t variantScore = calcVariantMatchingScore(variant, *fontFamily); // Subscores are encoded into 31 bits representation to meet the subscore priority. @@ -222,7 +223,7 @@ uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, } if (vs == EMOJI_STYLE_VS || vs == TEXT_STYLE_VS) { - const FontLanguages& langs = FontLanguageListCache::getById(fontFamily->langId()); + const FontLanguages& langs = getFontLanguagesFromCacheLocked(fontFamily->langId()); bool hasEmojiFlag = false; for (size_t i = 0; i < langs.size(); ++i) { if (langs[i].getEmojiStyle() == FontLanguage::EMSTYLE_EMOJI) { @@ -259,14 +260,13 @@ uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, // Here, m is the maximum number of languages to be compared, and s(i) is the i-th language's // matching score. The possible values of s(i) are 0, 1, 2, 3 and 4. uint32_t FontCollection::calcLanguageMatchingScore( - uint32_t userLangListId, const FontFamily& fontFamily) { - const FontLanguages& langList = FontLanguageListCache::getById(userLangListId); - const FontLanguages& fontLanguages = FontLanguageListCache::getById(fontFamily.langId()); + const FontLanguages& styleLanguages, const FontFamily& fontFamily) { + const FontLanguages& fontLanguages = getFontLanguagesFromCacheLocked(fontFamily.langId()); - const size_t maxCompareNum = std::min(langList.size(), FONT_LANGUAGES_LIMIT); + const size_t maxCompareNum = std::min(styleLanguages.size(), FONT_LANGUAGES_LIMIT); uint32_t score = 0; for (size_t i = 0; i < maxCompareNum; ++i) { - score = score * 5u + langList[i].calcScoreFor(fontLanguages); + score = score * 5u + styleLanguages[i].calcScoreFor(fontLanguages); } return score; } @@ -284,7 +284,7 @@ uint32_t FontCollection::calcVariantMatchingScore(int variant, const FontFamily& // 3. Highest score wins, with ties resolved to the first font. // This method never returns nullptr. const std::shared_ptr& FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, - uint32_t langListId, int variant) const { + const FontLanguages& styleLanguages, int variant) const { if (ch >= mMaxChar) { return mFamilies[0]; } @@ -303,7 +303,7 @@ const std::shared_ptr& FontCollection::getFamilyForChar(uint32_t ch, for (size_t i = range.start; i < range.end; i++) { const std::shared_ptr& family = vs == 0 ? mFamilies[mFamilyVec[i]] : mFamilies[i]; - const uint32_t score = calcFamilyScore(ch, vs, variant, langListId, family); + const uint32_t score = calcFamilyScore(ch, vs, variant, styleLanguages, family); if (score == kFirstFontScore) { // If the first font family supports the given character or variation sequence, always // use it. @@ -323,7 +323,7 @@ const std::shared_ptr& FontCollection::getFamilyForChar(uint32_t ch, if (U_SUCCESS(errorCode) && len > 0) { int off = 0; U16_NEXT_UNSAFE(decomposed, off, ch); - return getFamilyForChar(ch, vs, langListId, variant); + return getFamilyForChar(ch, vs, styleLanguages, variant); } } return mFamilies[0]; @@ -368,7 +368,7 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, return false; } - android::AutoMutex _l(gMinikinLock); + ScopedLock _l(gLock); // Currently mRanges can not be used here since it isn't aware of the variation sequence. for (size_t i = 0; i < mVSFamilyVec.size(); i++) { @@ -381,8 +381,7 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, // for emoji + U+FE0E case since we have special fallback rule for the sequence. if (isEmojiStyleVSBase(baseCodepoint) && variationSelector == TEXT_STYLE_VS) { for (size_t i = 0; i < mFamilies.size(); ++i) { - if (!mFamilies[i]->isColorEmojiFamily() && variationSelector == TEXT_STYLE_VS && - mFamilies[i]->hasGlyph(baseCodepoint, 0)) { + if (!mFamilies[i]->isColorEmojiFamily() && mFamilies[i]->hasGlyph(baseCodepoint, 0)) { return true; } } @@ -393,7 +392,8 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, void FontCollection::itemize(const uint16_t *string, size_t string_size, FontStyle style, vector* result) const { - const uint32_t langListId = style.getLanguageListId(); + const FontLanguages& styleLanguages = + getFontLanguagesFromCacheLocked(style.getLanguageListId()); int variant = style.getVariant(); const FontFamily* lastFamily = nullptr; Run* run = NULL; @@ -433,7 +433,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty if (!shouldContinueRun) { const std::shared_ptr& family = getFamilyForChar( - ch, isVariationSelector(nextCh) ? nextCh : 0, langListId, variant); + ch, isVariationSelector(nextCh) ? nextCh : 0, styleLanguages, variant); if (utf16Pos == 0 || family.get() != lastFamily) { size_t start = utf16Pos; // Workaround for combining marks and emoji modifiers until we implement diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index d0a0138ef2d..598929ae296 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -41,7 +41,7 @@ using std::vector; namespace minikin { FontStyle::FontStyle(int variant, int weight, bool italic) - : FontStyle(FontLanguageListCache::kEmptyListId, variant, weight, italic) { + : FontStyle(kEmptyLanguageListId, variant, weight, italic) { } FontStyle::FontStyle(uint32_t languageListId, int variant, int weight, bool italic) @@ -56,8 +56,8 @@ android::hash_t FontStyle::hash() const { // static uint32_t FontStyle::registerLanguageList(const std::string& languages) { - android::AutoMutex _l(gMinikinLock); - return FontLanguageListCache::getId(languages); + ScopedLock _l(gLock); + return putLanguageListToCacheLocked(languages); } // static @@ -76,7 +76,7 @@ Font::Font(std::shared_ptr&& typeface, FontStyle style) } void Font::loadAxes() { - android::AutoMutex _l(gMinikinLock); + ScopedLock _l(gLock); const uint32_t fvarTag = MinikinFont::MakeTag('f', 'v', 'a', 'r'); HbBlob fvarTable(getFontTable(typeface.get(), fvarTag)); if (fvarTable.size() == 0) { @@ -104,7 +104,7 @@ FontFamily::FontFamily(std::vector&& fonts) : FontFamily(0 /* variant */, } FontFamily::FontFamily(int variant, std::vector&& fonts) - : FontFamily(FontLanguageListCache::kEmptyListId, variant, std::move(fonts)) { + : FontFamily(kEmptyLanguageListId, variant, std::move(fonts)) { } FontFamily::FontFamily(uint32_t langId, int variant, std::vector&& fonts) @@ -117,7 +117,7 @@ FontFamily::~FontFamily() { bool FontFamily::analyzeStyle(const std::shared_ptr& typeface, int* weight, bool* italic) { - android::AutoMutex _l(gMinikinLock); + ScopedLock _l(gLock); const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2'); HbBlob os2Table(getFontTable(typeface.get(), os2Tag)); if (os2Table.get() == nullptr) return false; @@ -162,7 +162,7 @@ FakedFont FontFamily::getClosestMatch(FontStyle style) const { } bool FontFamily::isColorEmojiFamily() const { - const FontLanguages& languageList = FontLanguageListCache::getById(mLangId); + const FontLanguages& languageList = getFontLanguagesFromCacheLocked(mLangId); for (size_t i = 0; i < languageList.size(); ++i) { if (languageList[i].getEmojiStyle() == FontLanguage::EMSTYLE_EMOJI) { return true; @@ -172,7 +172,7 @@ bool FontFamily::isColorEmojiFamily() const { } void FontFamily::computeCoverage() { - android::AutoMutex _l(gMinikinLock); + ScopedLock _l(gLock); const FontStyle defaultStyle; const MinikinFont* typeface = getClosestMatch(defaultStyle).font; const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); @@ -190,7 +190,7 @@ void FontFamily::computeCoverage() { } bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) const { - assertMinikinLocked(); + assertLocked(gLock); if (variationSelector != 0 && !mHasVSTable) { // Early exit if the variation selector is specified but the font doesn't have a cmap format // 14 subtable. diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp index f1e14f0a66d..5323e580cec 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp @@ -20,6 +20,8 @@ #include #include +#include +#include #include @@ -28,8 +30,6 @@ namespace minikin { -const uint32_t FontLanguageListCache::kEmptyListId; - // Returns the text length of output. static size_t toLanguageTag(char* output, size_t outSize, const std::string& locale) { output[0] = '\0'; @@ -111,46 +111,61 @@ static std::vector parseLanguageList(const std::string& input) { return result; } -// static -uint32_t FontLanguageListCache::getId(const std::string& languages) { - FontLanguageListCache* inst = FontLanguageListCache::getInstance(); - std::unordered_map::const_iterator it = - inst->mLanguageListLookupTable.find(languages); - if (it != inst->mLanguageListLookupTable.end()) { - return it->second; - } - - // Given language list is not in cache. Insert it and return newly assigned ID. - const uint32_t nextId = inst->mLanguageLists.size(); - FontLanguages fontLanguages(parseLanguageList(languages)); - if (fontLanguages.empty()) { - return kEmptyListId; - } - inst->mLanguageLists.push_back(std::move(fontLanguages)); - inst->mLanguageListLookupTable.insert(std::make_pair(languages, nextId)); - return nextId; -} - -// static -const FontLanguages& FontLanguageListCache::getById(uint32_t id) { - FontLanguageListCache* inst = FontLanguageListCache::getInstance(); - LOG_ALWAYS_FATAL_IF(id >= inst->mLanguageLists.size(), "Lookup by unknown language list ID."); - return inst->mLanguageLists[id]; -} - -// static -FontLanguageListCache* FontLanguageListCache::getInstance() { - assertMinikinLocked(); - static FontLanguageListCache* instance = nullptr; - if (instance == nullptr) { - instance = new FontLanguageListCache(); - +class FontLanguageListCache { +public: + FontLanguageListCache() { // Insert an empty language list for mapping default language list to kEmptyListId. // The default language list has only one FontLanguage and it is the unsupported language. - instance->mLanguageLists.push_back(FontLanguages()); - instance->mLanguageListLookupTable.insert(std::make_pair("", kEmptyListId)); + mLanguageLists.emplace(kEmptyLanguageListId, FontLanguages()); + mLanguageListLookupTable.emplace("", kEmptyLanguageListId); } + + uint32_t put(const std::string& languages) { + assertLocked(gLock); + + const auto& it = mLanguageListLookupTable.find(languages); + if (it != mLanguageListLookupTable.end()) { + return it->second; + } + + // Given language list is not in cache. Insert it and return newly assigned ID. + const uint32_t nextId = mLanguageLists.size(); + FontLanguages fontLanguages(parseLanguageList(languages)); + if (fontLanguages.empty()) { + mLanguageListLookupTable.emplace(languages, kEmptyLanguageListId); + return kEmptyLanguageListId; + } + mLanguageLists.emplace(nextId, std::move(fontLanguages)); + mLanguageListLookupTable.emplace(languages, nextId); + return nextId; + } + + const FontLanguages& get(uint32_t id) { + assertLocked(gLock); + + return mLanguageLists[id]; + } + +private: + std::unordered_map mLanguageLists; + + // A map from string representation of the font language list to the ID. + std::unordered_map mLanguageListLookupTable; +}; + +static FontLanguageListCache& getInstance() { + static FontLanguageListCache instance; return instance; } +// static +uint32_t putLanguageListToCacheLocked(const std::string& languages) { + return getInstance().put(languages); +} + +// static +const FontLanguages& getFontLanguagesFromCacheLocked(uint32_t id) { + return getInstance().get(id); +} + } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.h b/engine/src/flutter/libs/minikin/FontLanguageListCache.h index 9bf156f9de7..2eafab91518 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.h +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.h @@ -17,39 +17,21 @@ #ifndef MINIKIN_FONT_LANGUAGE_LIST_CACHE_H #define MINIKIN_FONT_LANGUAGE_LIST_CACHE_H -#include - -#include #include "FontLanguage.h" namespace minikin { -class FontLanguageListCache { -public: - // A special ID for the empty language list. - // This value must be 0 since the empty language list is inserted into mLanguageLists by - // default. - const static uint32_t kEmptyListId = 0; +// A special ID for the empty language list. +// This value must be 0 since the empty language list is inserted into mLanguageLists by default. +const uint32_t kEmptyLanguageListId = 0; - // Returns language list ID for the given string representation of FontLanguages. - // Caller should acquire a lock before calling the method. - static uint32_t getId(const std::string& languages); +// Looks up from internal cache and returns associated ID if FontLanguages constructed from given +// string is already registered. If it is new to internal cache, put it to internal cache and +// returns newly assigned ID. +uint32_t putLanguageListToCacheLocked(const std::string& languages); - // Caller should acquire a lock before calling the method. - static const FontLanguages& getById(uint32_t id); - -private: - FontLanguageListCache() {} // Singleton - ~FontLanguageListCache() {} - - // Caller should acquire a lock before calling the method. - static FontLanguageListCache* getInstance(); - - std::vector mLanguageLists; - - // A map from string representation of the font language list to the ID. - std::unordered_map mLanguageListLookupTable; -}; +// Returns FontLanguages associated with given ID. +const FontLanguages& getFontLanguagesFromCacheLocked(uint32_t id); } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index af3d783bc84..79aebe931e5 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -62,70 +62,80 @@ private: android::LruCache mCache; }; -HbFontCache* getFontCacheLocked() { - assertMinikinLocked(); - static HbFontCache* cache = nullptr; - if (cache == nullptr) { - cache = new HbFontCache(); +class HbFontCacheHolder { +public: + HbFontCacheHolder() {} + + hb_font_t* getCachedFont(const MinikinFont* minikinFont) { + assertLocked(gLock); + + // TODO: get rid of nullFaceFont + static hb_font_t* nullFaceFont = nullptr; + if (minikinFont == nullptr) { + if (nullFaceFont == nullptr) { + nullFaceFont = hb_font_create(nullptr); + } + return hb_font_reference(nullFaceFont); + } + + const int32_t fontId = minikinFont->GetUniqueId(); + hb_font_t* font = mFontCache.get(fontId); + if (font != nullptr) { + return hb_font_reference(font); + } + + hb_face_t* face; + const void* buf = minikinFont->GetFontData(); + size_t size = minikinFont->GetFontSize(); + hb_blob_t* blob = hb_blob_create(reinterpret_cast(buf), size, + HB_MEMORY_MODE_READONLY, nullptr, nullptr); + face = hb_face_create(blob, minikinFont->GetFontIndex()); + hb_blob_destroy(blob); + + hb_font_t* parent_font = hb_font_create(face); + hb_ot_font_set_funcs(parent_font); + + unsigned int upem = hb_face_get_upem(face); + hb_font_set_scale(parent_font, upem, upem); + + font = hb_font_create_sub_font(parent_font); + hb_font_destroy(parent_font); + hb_face_destroy(face); + mFontCache.put(fontId, font); + return hb_font_reference(font); } - return cache; + + void clearFontCache() { + assertLocked(gLock); + mFontCache.clear(); + } + + void removeFont(const MinikinFont* minikinFont) { + assertLocked(gLock); + mFontCache.remove(minikinFont->GetUniqueId()); + } + +private: + HbFontCache mFontCache; +}; + +static HbFontCacheHolder& getInstance() { + static HbFontCacheHolder instance; + return instance; } void purgeHbFontCacheLocked() { - assertMinikinLocked(); - getFontCacheLocked()->clear(); + getInstance().clearFontCache(); } void purgeHbFontLocked(const MinikinFont* minikinFont) { - assertMinikinLocked(); - const int32_t fontId = minikinFont->GetUniqueId(); - getFontCacheLocked()->remove(fontId); + getInstance().removeFont(minikinFont); } // Returns a new reference to a hb_font_t object, caller is // responsible for calling hb_font_destroy() on it. hb_font_t* getHbFontLocked(const MinikinFont* minikinFont) { - assertMinikinLocked(); - // TODO: get rid of nullFaceFont - static hb_font_t* nullFaceFont = nullptr; - if (minikinFont == nullptr) { - if (nullFaceFont == nullptr) { - nullFaceFont = hb_font_create(nullptr); - } - return hb_font_reference(nullFaceFont); - } - - HbFontCache* fontCache = getFontCacheLocked(); - const int32_t fontId = minikinFont->GetUniqueId(); - hb_font_t* font = fontCache->get(fontId); - if (font != nullptr) { - return hb_font_reference(font); - } - - hb_face_t* face; - const void* buf = minikinFont->GetFontData(); - size_t size = minikinFont->GetFontSize(); - hb_blob_t* blob = hb_blob_create(reinterpret_cast(buf), size, - HB_MEMORY_MODE_READONLY, nullptr, nullptr); - face = hb_face_create(blob, minikinFont->GetFontIndex()); - hb_blob_destroy(blob); - - hb_font_t* parent_font = hb_font_create(face); - hb_ot_font_set_funcs(parent_font); - - unsigned int upem = hb_face_get_upem(face); - hb_font_set_scale(parent_font, upem, upem); - - font = hb_font_create_sub_font(parent_font); - std::vector variations; - for (const FontVariation& variation : minikinFont->GetAxes()) { - variations.push_back({variation.axisTag, variation.value}); - } - hb_font_set_variations(font, variations.data(), variations.size()); - hb_font_destroy(parent_font); - hb_face_destroy(face); - fontCache->put(fontId, font); - return hb_font_reference(font); + return getInstance().getCachedFont(minikinFont); } } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 743cb763aea..d85ddd79a35 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -201,7 +200,7 @@ static unsigned int disabledDecomposeCompatibility(hb_unicode_funcs_t*, hb_codep return 0; } -class LayoutEngine : public ::android::Singleton { +class LayoutEngine { public: LayoutEngine() { unicodeFunctions = hb_unicode_funcs_create(hb_icu_get_unicode_funcs()); @@ -212,8 +211,26 @@ public: hb_buffer_set_unicode_funcs(hbBuffer, unicodeFunctions); } + Layout* getCachedLayout(LayoutCacheKey& key, LayoutContext* ctx, + const std::shared_ptr& collection) { + assertLocked(gLock); + return layoutCache.get(key, ctx, collection); + } + + void clearLayoutCache() { + assertLocked(gLock); + layoutCache.clear(); + } + hb_buffer_t* hbBuffer; hb_unicode_funcs_t* unicodeFunctions; + + static LayoutEngine& getInstance() { + static LayoutEngine instance; + return instance; + } + +private: LayoutCache layoutCache; }; @@ -288,8 +305,7 @@ static hb_bool_t harfbuzzGetGlyphHorizontalOrigin(hb_font_t* /* hbFont */, void* } hb_font_funcs_t* getHbFontFuncs(bool forColorBitmapFont) { - assertMinikinLocked(); - + assertLocked(gLock); static hb_font_funcs_t* hbFuncs = nullptr; static hb_font_funcs_t* hbFuncsForColorBitmap = nullptr; @@ -585,8 +601,7 @@ BidiText::BidiText(const uint16_t* buf, size_t start, size_t count, size_t bufSi void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint) { - android::AutoMutex _l(gMinikinLock); - + ScopedLock _l(gLock); LayoutContext ctx; ctx.style = style; ctx.paint = paint; @@ -604,8 +619,7 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu float Layout::measureText(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint, const std::shared_ptr& collection, float* advances) { - android::AutoMutex _l(gMinikinLock); - + ScopedLock _l(gLock); LayoutContext ctx; ctx.style = style; ctx.paint = paint; @@ -677,7 +691,6 @@ float Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, float Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_t bufSize, bool isRtl, LayoutContext* ctx, size_t bufStart, const std::shared_ptr& collection, Layout* layout, float* advances) { - LayoutCache& cache = LayoutEngine::getInstance().layoutCache; LayoutCacheKey key(collection, ctx->paint, ctx->style, buf, start, count, bufSize, isRtl); float wordSpacing = count == 1 && isWordSpace(buf[start]) ? ctx->paint.wordSpacing : 0; @@ -694,7 +707,7 @@ float Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size } advance = layoutForWord.getAdvance(); } else { - Layout* layoutForWord = cache.get(key, ctx, collection); + Layout* layoutForWord = LayoutEngine::getInstance().getCachedLayout(key, ctx, collection); if (layout) { layout->appendLayout(layoutForWord, bufStart, wordSpacing); } @@ -947,7 +960,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t hb_buffer_set_script(buffer, script); hb_buffer_set_direction(buffer, isRtl? HB_DIRECTION_RTL : HB_DIRECTION_LTR); const FontLanguages& langList = - FontLanguageListCache::getById(ctx->style.getLanguageListId()); + getFontLanguagesFromCacheLocked(ctx->style.getLanguageListId()); if (langList.size() != 0) { const FontLanguage* hbLanguage = &langList[0]; for (size_t i = 0; i < langList.size(); ++i) { @@ -1149,17 +1162,9 @@ void Layout::getBounds(MinikinRect* bounds) const { } void Layout::purgeCaches() { - android::AutoMutex _l(gMinikinLock); - LayoutCache& layoutCache = LayoutEngine::getInstance().layoutCache; - layoutCache.clear(); + ScopedLock _l(gLock); + LayoutEngine::getInstance().clearLayoutCache(); purgeHbFontCacheLocked(); } } // namespace minikin - -// Unable to define the static data member outside of android. -// TODO: introduce our own Singleton to drop android namespace. -namespace android { -ANDROID_SINGLETON_STATIC_INSTANCE(minikin::LayoutEngine); -} // namespace android - diff --git a/engine/src/flutter/libs/minikin/MinikinFont.cpp b/engine/src/flutter/libs/minikin/MinikinFont.cpp index 6bf6a4ae3b7..f8e0d5b2900 100644 --- a/engine/src/flutter/libs/minikin/MinikinFont.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFont.cpp @@ -21,7 +21,7 @@ namespace minikin { MinikinFont::~MinikinFont() { - android::AutoMutex _l(gMinikinLock); + ScopedLock _l(gLock); purgeHbFontLocked(this); } diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index e766dce992d..1d06e03aa68 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -25,13 +25,8 @@ namespace minikin { -android::Mutex gMinikinLock; - -void assertMinikinLocked() { -#ifdef ENABLE_RACE_DETECTION - LOG_ALWAYS_FATAL_IF(gMinikinLock.tryLock() == 0); -#endif -} +std::mutex gMutex; +std::unique_lock gLock(gMutex, std::defer_lock); bool isEmoji(uint32_t c) { // U+2695 U+2640 U+2642 are not in emoji category in Unicode 9 but they are now emoji category. @@ -86,7 +81,7 @@ bool isEmojiBase(uint32_t c) { } hb_blob_t* getFontTable(const MinikinFont* minikinFont, uint32_t tag) { - assertMinikinLocked(); + assertLocked(gLock); hb_font_t* font = getHbFontLocked(minikinFont); hb_face_t* face = hb_font_get_face(font); hb_blob_t* blob = hb_face_reference_table(face, tag); diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.h b/engine/src/flutter/libs/minikin/MinikinInternal.h index 365f20cc0df..c374cb4656e 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.h +++ b/engine/src/flutter/libs/minikin/MinikinInternal.h @@ -21,20 +21,27 @@ #include -#include - #include +#include + +#include namespace minikin { // All external Minikin interfaces are designed to be thread-safe. -// Presently, that's implemented by through a global lock, and having -// all external interfaces take that lock. +// Presently, that's implemented by a global lock, and having all external interfaces take that +// lock. +extern std::unique_lock gLock; +typedef std::unique_lock> ScopedLock; -extern android::Mutex gMinikinLock; +#ifdef ENABLE_RACE_DETECTION +inline void assertLocked(const std::unique_lock& lock) { + LOG_ALWAYS_FATAL_IF(!lock.owns_lock()); +} +#else +inline void assertLocked(const std::unique_lock&) {} +#endif -// Aborts if gMinikinLock is not acquired. Do nothing on the release build. -void assertMinikinLocked(); // Returns true if c is emoji. bool isEmoji(uint32_t c); diff --git a/engine/src/flutter/tests/perftests/FontCollection.cpp b/engine/src/flutter/tests/perftests/FontCollection.cpp index 6f9d636ca30..304708f6c77 100644 --- a/engine/src/flutter/tests/perftests/FontCollection.cpp +++ b/engine/src/flutter/tests/perftests/FontCollection.cpp @@ -77,7 +77,7 @@ static void BM_FontCollection_itemize(benchmark::State& state) { std::vector result; FontStyle style(FontStyle::registerLanguageList(ITEMIZE_TEST_CASES[testIndex].languageTag)); - android::AutoMutex _l(gMinikinLock); + ScopedLock _l(gLock); while (state.KeepRunning()) { result.clear(); collection->itemize(buffer, utf16_length, style, &result); diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index aa142cccdcd..557458b80bd 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -60,7 +60,7 @@ void itemize(const std::shared_ptr& collection, const char* str, result->clear(); ParseUnicode(buf, BUF_SIZE, str, &len, NULL); - android::AutoMutex _l(gMinikinLock); + ScopedLock _l(gLock); collection->itemize(buf, len, style, result); } @@ -72,8 +72,8 @@ const std::string& getFontPath(const FontCollection::Run& run) { // Utility function to obtain FontLanguages from string. const FontLanguages& registerAndGetFontLanguages(const std::string& lang_string) { - android::AutoMutex _l(gMinikinLock); - return FontLanguageListCache::getById(FontLanguageListCache::getId(lang_string)); + ScopedLock _l(gLock); + return getFontLanguagesFromCacheLocked(putLanguageListToCacheLocked(lang_string)); } TEST_F(FontCollectionItemizeTest, itemize_latin) { diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 5285f2642b4..81f595694ca 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -30,15 +30,15 @@ typedef ICUTestBase FontLanguagesTest; typedef ICUTestBase FontLanguageTest; static const FontLanguages& createFontLanguages(const std::string& input) { - android::AutoMutex _l(gMinikinLock); - uint32_t langId = FontLanguageListCache::getId(input); - return FontLanguageListCache::getById(langId); + ScopedLock _l(gLock); + uint32_t langId = putLanguageListToCacheLocked(input); + return getFontLanguagesFromCacheLocked(langId); } static FontLanguage createFontLanguage(const std::string& input) { - android::AutoMutex _l(gMinikinLock); - uint32_t langId = FontLanguageListCache::getId(input); - return FontLanguageListCache::getById(langId)[0]; + ScopedLock _l(gLock); + uint32_t langId = putLanguageListToCacheLocked(input); + return getFontLanguagesFromCacheLocked(langId)[0]; } static FontLanguage createFontLanguageWithoutICUSanitization(const std::string& input) { @@ -533,7 +533,7 @@ TEST_F(FontFamilyTest, hasVariationSelectorTest) { std::shared_ptr family( new FontFamily(std::vector{ Font(minikinFont, FontStyle()) })); - android::AutoMutex _l(gMinikinLock); + ScopedLock _l(gLock); const uint32_t kVS1 = 0xFE00; const uint32_t kVS2 = 0xFE01; @@ -586,7 +586,7 @@ TEST_F(FontFamilyTest, hasVSTableTest) { new MinikinFontForTest(testCase.fontPath)); std::shared_ptr family(new FontFamily( std::vector{ Font(minikinFont, FontStyle()) })); - android::AutoMutex _l(gMinikinLock); + ScopedLock _l(gLock); EXPECT_EQ(testCase.hasVSTable, family->hasVSTable()); } } diff --git a/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp b/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp index 81d84a8a288..bd82e0f9947 100644 --- a/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp @@ -31,40 +31,43 @@ TEST_F(FontLanguageListCacheTest, getId) { EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en,zh-Hans")); - android::AutoMutex _l(gMinikinLock); - EXPECT_EQ(0UL, FontLanguageListCache::getId("")); + ScopedLock _l(gLock); - EXPECT_EQ(FontLanguageListCache::getId("en"), FontLanguageListCache::getId("en")); - EXPECT_NE(FontLanguageListCache::getId("en"), FontLanguageListCache::getId("jp")); + EXPECT_EQ(0UL, putLanguageListToCacheLocked("")); - EXPECT_EQ(FontLanguageListCache::getId("en,zh-Hans"), - FontLanguageListCache::getId("en,zh-Hans")); - EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), - FontLanguageListCache::getId("zh-Hans,en")); - EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), - FontLanguageListCache::getId("jp")); - EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), - FontLanguageListCache::getId("en")); - EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), - FontLanguageListCache::getId("en,zh-Hant")); + EXPECT_EQ(putLanguageListToCacheLocked("en"), putLanguageListToCacheLocked("en")); + EXPECT_NE(putLanguageListToCacheLocked("en"), putLanguageListToCacheLocked("jp")); + + EXPECT_EQ(putLanguageListToCacheLocked("en,zh-Hans"), + putLanguageListToCacheLocked("en,zh-Hans")); + EXPECT_NE(putLanguageListToCacheLocked("en,zh-Hans"), + putLanguageListToCacheLocked("zh-Hans,en")); + EXPECT_NE(putLanguageListToCacheLocked("en,zh-Hans"), + putLanguageListToCacheLocked("jp")); + EXPECT_NE(putLanguageListToCacheLocked("en,zh-Hans"), + putLanguageListToCacheLocked("en")); + EXPECT_NE(putLanguageListToCacheLocked("en,zh-Hans"), + putLanguageListToCacheLocked("en,zh-Hant")); } TEST_F(FontLanguageListCacheTest, getById) { - android::AutoMutex _l(gMinikinLock); - uint32_t enLangId = FontLanguageListCache::getId("en"); - uint32_t jpLangId = FontLanguageListCache::getId("jp"); - FontLanguage english = FontLanguageListCache::getById(enLangId)[0]; - FontLanguage japanese = FontLanguageListCache::getById(jpLangId)[0]; + ScopedLock _l(gLock); - const FontLanguages& defLangs = FontLanguageListCache::getById(0); + uint32_t enLangId = putLanguageListToCacheLocked("en"); + uint32_t jpLangId = putLanguageListToCacheLocked("jp"); + FontLanguage english = getFontLanguagesFromCacheLocked(enLangId)[0]; + FontLanguage japanese = getFontLanguagesFromCacheLocked(jpLangId)[0]; + + const FontLanguages& defLangs = getFontLanguagesFromCacheLocked(0); EXPECT_TRUE(defLangs.empty()); - const FontLanguages& langs = FontLanguageListCache::getById(FontLanguageListCache::getId("en")); + const FontLanguages& langs = getFontLanguagesFromCacheLocked( + putLanguageListToCacheLocked("en")); ASSERT_EQ(1UL, langs.size()); EXPECT_EQ(english, langs[0]); - const FontLanguages& langs2 = - FontLanguageListCache::getById(FontLanguageListCache::getId("en,jp")); + const FontLanguages& langs2 = getFontLanguagesFromCacheLocked( + putLanguageListToCacheLocked("en,jp")); ASSERT_EQ(2UL, langs2.size()); EXPECT_EQ(english, langs2[0]); EXPECT_EQ(japanese, langs2[1]); diff --git a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp index a5581a27b88..7691b8421e9 100644 --- a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp @@ -18,7 +18,6 @@ #include #include -#include #include @@ -33,7 +32,7 @@ namespace minikin { class HbFontCacheTest : public testing::Test { public: virtual void TearDown() { - android::AutoMutex _l(gMinikinLock); + ScopedLock _l(gLock); purgeHbFontCacheLocked(); } }; @@ -48,7 +47,8 @@ TEST_F(HbFontCacheTest, getHbFontLockedTest) { std::shared_ptr fontC( new MinikinFontForTest(kTestFontDir "BoldItalic.ttf")); - android::AutoMutex _l(gMinikinLock); + ScopedLock _l(gLock); + // Never return NULL. EXPECT_NE(nullptr, getHbFontLocked(fontA.get())); EXPECT_NE(nullptr, getHbFontLocked(fontB.get())); @@ -70,7 +70,8 @@ TEST_F(HbFontCacheTest, purgeCacheTest) { std::shared_ptr minikinFont( new MinikinFontForTest(kTestFontDir "Regular.ttf")); - android::AutoMutex _l(gMinikinLock); + ScopedLock _l(gLock); + hb_font_t* font = getHbFontLocked(minikinFont.get()); ASSERT_NE(nullptr, font); From ff9a6740ed0c3648cae2facaac54a742a5a949ec Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 5 Jan 2017 20:44:14 +0900 Subject: [PATCH 241/364] Make SparseBitSet serializable. To share the calculated coverage information across the processes, make SparseBitSet serializable. Bug: 34042446 Test: minikin_tests passes Change-Id: I0463138adcf234739bb3ce1cdadf382021921f3e --- .../src/flutter/include/minikin/FontFamily.h | 17 +++ .../flutter/include/minikin/SparseBitSet.h | 25 +++- .../src/flutter/libs/minikin/FontFamily.cpp | 24 +++ .../src/flutter/libs/minikin/SparseBitSet.cpp | 106 +++++++++++-- engine/src/flutter/tests/perftests/Android.mk | 1 + .../flutter/tests/perftests/FontFamily.cpp | 54 +++++++ engine/src/flutter/tests/unittest/Android.mk | 1 + .../tests/unittest/SparseBitSetTest.cpp | 140 ++++++++++++++++++ 8 files changed, 348 insertions(+), 20 deletions(-) create mode 100644 engine/src/flutter/tests/perftests/FontFamily.cpp create mode 100644 engine/src/flutter/tests/unittest/SparseBitSetTest.cpp diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index c7018a6f8c0..4186c2baabb 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -128,8 +128,23 @@ public: FontFamily(int variant, std::vector&& fonts); FontFamily(uint32_t langId, int variant, std::vector&& fonts); + // The accelerator table won't be copied. Do not release the memory until the created FontFamily + // is destructed. + FontFamily(std::vector&& fonts, const uint8_t* acceleratorTable, size_t tableSize); + FontFamily(int variant, std::vector&& fonts, const uint8_t* acceleratorTable, + size_t tableSize); + FontFamily(uint32_t langId, int variant, std::vector&& fonts, + const uint8_t* acceleratorTable, size_t tableSize); + ~FontFamily(); + // Writes internal accelerator tables into the 'out' buffer. + // + // This method returns the number of bytes written to the buffer. By calling the method with + // 'out' set to nullptr, the method just returns the size needed, which the caller can then use + // for allocating a buffer for a second call. + size_t writeAcceleratorTable(uint8_t* out) const; + // TODO: Good to expose FontUtil.h. static bool analyzeStyle(const std::shared_ptr& typeface, int* weight, bool* italic); @@ -164,6 +179,8 @@ public: private: void computeCoverage(); + void readAcceleratorTable(const uint8_t* data, size_t size); + uint32_t mLangId; int mVariant; std::vector mFonts; diff --git a/engine/src/flutter/include/minikin/SparseBitSet.h b/engine/src/flutter/include/minikin/SparseBitSet.h index 2552d14d0b7..491e68ae7fb 100644 --- a/engine/src/flutter/include/minikin/SparseBitSet.h +++ b/engine/src/flutter/include/minikin/SparseBitSet.h @@ -34,7 +34,7 @@ namespace minikin { class SparseBitSet { public: - SparseBitSet(): mMaxVal(0) { + SparseBitSet(): mMaxVal(0), mOwnIndicesAndBitmaps(false) { } // Clear the set @@ -45,10 +45,21 @@ public: // inclusive of start, exclusive of end, laid out in a uint32 array. void initFromRanges(const uint32_t* ranges, size_t nRanges); + // Initializes the set with pre-calculted data. Returns false if the serialized data is invalid. + // Even if this function returns false, the internal data is cleared. + bool initFromBuffer(const uint8_t* data, size_t size); + + // Serialize the set and write into out. + // + // This method returns the number of bytes written to the buffer. By calling the method with + // 'out' set to nullptr, the method just returns the size needed, which the caller can then use + // for allocating a buffer for a second call. + size_t writeToBuffer(uint8_t* out) const; + // Determine whether the value is included in the set bool get(uint32_t ch) const { if (ch >= mMaxVal) return false; - uint32_t *bitmap = &mBitmaps[mIndices[ch >> kLogValuesPerPage]]; + const uint32_t *bitmap = &mBitmaps[mIndices[ch >> kLogValuesPerPage]]; uint32_t index = ch & kPageMask; return (bitmap[index >> kLogBitsPerEl] & (kElFirst >> (index & kElMask))) != 0; } @@ -80,8 +91,14 @@ private: static int CountLeadingZeros(element x); uint32_t mMaxVal; - std::unique_ptr mIndices; - std::unique_ptr mBitmaps; + + // True if this SparseBitSet is responsible for freeing mIndices and mBitamps. + bool mOwnIndicesAndBitmaps; + + uint32_t mIndexSize; + const uint32_t* mIndices; + uint32_t mBitmapSize; + const element* mBitmaps; uint32_t mZeroPageIndex; }; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index d0a0138ef2d..4097e8fb239 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -112,6 +112,22 @@ FontFamily::FontFamily(uint32_t langId, int variant, std::vector&& fonts) computeCoverage(); } +FontFamily::FontFamily(std::vector&& fonts, const uint8_t* acceleratorTable, size_t tableSize) + : FontFamily(0 /* variant */, std::move(fonts), acceleratorTable, tableSize) { +} + +FontFamily::FontFamily(int variant, std::vector&& fonts, const uint8_t* acceleratorTable, + size_t tableSize) + : FontFamily(FontLanguageListCache::kEmptyListId, variant, std::move(fonts), acceleratorTable, + tableSize) { +} + +FontFamily::FontFamily(uint32_t langId, int variant, std::vector&& fonts, + const uint8_t* acceleratorTable, size_t tableSize) + : mLangId(langId), mVariant(variant), mFonts(std::move(fonts)), mHasVSTable(false) { + readAcceleratorTable(acceleratorTable, tableSize); +} + FontFamily::~FontFamily() { } @@ -247,4 +263,12 @@ std::shared_ptr FontFamily::createFamilyWithVariation( return std::shared_ptr(new FontFamily(mLangId, mVariant, std::move(fonts))); } +size_t FontFamily::writeAcceleratorTable(uint8_t* out) const { + return mCoverage.writeToBuffer(out); +} + +void FontFamily::readAcceleratorTable(const uint8_t* data, size_t size) { + bool result = mCoverage.initFromBuffer(data, size); + LOG_ALWAYS_FATAL_IF(!result, "Failed to reconstruct accelerator table from buffer"); +} } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/SparseBitSet.cpp b/engine/src/flutter/libs/minikin/SparseBitSet.cpp index 85eddaef359..a95af4d716f 100644 --- a/engine/src/flutter/libs/minikin/SparseBitSet.cpp +++ b/engine/src/flutter/libs/minikin/SparseBitSet.cpp @@ -29,8 +29,13 @@ const uint32_t SparseBitSet::kNotFound; void SparseBitSet::clear() { mMaxVal = 0; - mIndices.reset(); - mBitmaps.reset(); + if (mOwnIndicesAndBitmaps) { + delete[] mIndices; + delete[] mBitmaps; + mIndexSize = 0; + mBitmapSize = 0; + mOwnIndicesAndBitmaps = false; + } } uint32_t SparseBitSet::calcNumPages(const uint32_t* ranges, size_t nRanges) { @@ -59,17 +64,17 @@ uint32_t SparseBitSet::calcNumPages(const uint32_t* ranges, size_t nRanges) { void SparseBitSet::initFromRanges(const uint32_t* ranges, size_t nRanges) { if (nRanges == 0) { - mMaxVal = 0; - mIndices.reset(); - mBitmaps.reset(); + clear(); return; } mMaxVal = ranges[nRanges * 2 - 1]; - size_t indexSize = (mMaxVal + kPageMask) >> kLogValuesPerPage; - mIndices.reset(new uint32_t[indexSize]); + mIndexSize = (mMaxVal + kPageMask) >> kLogValuesPerPage; + uint32_t* indices = new uint32_t[mIndexSize]; uint32_t nPages = calcNumPages(ranges, nRanges); - mBitmaps.reset(new element[nPages << (kLogValuesPerPage - kLogBitsPerEl)]); - memset(mBitmaps.get(), 0, nPages << (kLogValuesPerPage - 3)); + mBitmapSize = nPages << (kLogValuesPerPage - kLogBitsPerEl); + element* bitmaps = new element[mBitmapSize]; + mOwnIndicesAndBitmaps = true; + memset(bitmaps, 0, nPages << (kLogValuesPerPage - 3)); mZeroPageIndex = noZeroPage; uint32_t nonzeroPageEnd = 0; uint32_t currentPage = 0; @@ -85,30 +90,99 @@ void SparseBitSet::initFromRanges(const uint32_t* ranges, size_t nRanges) { mZeroPageIndex = (currentPage++) << (kLogValuesPerPage - kLogBitsPerEl); } for (uint32_t j = nonzeroPageEnd; j < startPage; j++) { - mIndices[j] = mZeroPageIndex; + indices[j] = mZeroPageIndex; } } - mIndices[startPage] = (currentPage++) << (kLogValuesPerPage - kLogBitsPerEl); + indices[startPage] = (currentPage++) << (kLogValuesPerPage - kLogBitsPerEl); } size_t index = ((currentPage - 1) << (kLogValuesPerPage - kLogBitsPerEl)) + ((start & kPageMask) >> kLogBitsPerEl); size_t nElements = (end - (start & ~kElMask) + kElMask) >> kLogBitsPerEl; if (nElements == 1) { - mBitmaps[index] |= (kElAllOnes >> (start & kElMask)) & + bitmaps[index] |= (kElAllOnes >> (start & kElMask)) & (kElAllOnes << ((~end + 1) & kElMask)); } else { - mBitmaps[index] |= kElAllOnes >> (start & kElMask); + bitmaps[index] |= kElAllOnes >> (start & kElMask); for (size_t j = 1; j < nElements - 1; j++) { - mBitmaps[index + j] = kElAllOnes; + bitmaps[index + j] = kElAllOnes; } - mBitmaps[index + nElements - 1] |= kElAllOnes << ((~end + 1) & kElMask); + bitmaps[index + nElements - 1] |= kElAllOnes << ((~end + 1) & kElMask); } for (size_t j = startPage + 1; j < endPage + 1; j++) { - mIndices[j] = (currentPage++) << (kLogValuesPerPage - kLogBitsPerEl); + indices[j] = (currentPage++) << (kLogValuesPerPage - kLogBitsPerEl); } nonzeroPageEnd = endPage + 1; } + mBitmaps = bitmaps; + mIndices = indices; +} + +struct SparseBitSetHeader { + uint32_t maxValue; + uint32_t zeroPageIndex; + uint32_t indexSize; + uint32_t bitmapSize; +}; + +bool SparseBitSet::initFromBuffer(const uint8_t* data, size_t size) { + // No need to be concerned about endianness here since Intel x86 CPUs are little-endian. ARM + // CPUs are bi-endian but the endianness is only changeable at reset time and is impossible to + // change at runtime. Thus incoming data is guaranteed to have the same endianness as when it + // was created. + + if (data == nullptr || size < sizeof(SparseBitSetHeader)) { + clear(); + return false; + } + + // The serialized data starts with SparseBitSetHeader. + const SparseBitSetHeader* header = reinterpret_cast(data); + mMaxVal = header->maxValue; + mZeroPageIndex = header->zeroPageIndex; + mIndexSize = header->indexSize; + mBitmapSize = header->bitmapSize; + + mOwnIndicesAndBitmaps = false; + if (mIndexSize == 0 || mBitmapSize == 0 || mMaxVal == 0) { + const bool isValidEmptyBitSet = (mIndexSize == 0 && mBitmapSize == 0 && mMaxVal == 0); + if (!isValidEmptyBitSet) { + clear(); + } + return isValidEmptyBitSet; + } + + const size_t indicesSizeInBytes = sizeof(mIndices[0]) * mIndexSize; + const size_t bitmapsSizeInBytes = sizeof(mBitmaps[0]) * mBitmapSize; + if (size != sizeof(SparseBitSetHeader) + indicesSizeInBytes + bitmapsSizeInBytes) { + clear(); + return false; + } + data += sizeof(SparseBitSetHeader); + mIndices = reinterpret_cast(data); + data += indicesSizeInBytes; + mBitmaps = reinterpret_cast(data); + return true; +} + +size_t SparseBitSet::writeToBuffer(uint8_t* out) const{ + // See comments in SparseBitSet::initFromBuffer for the data structure. + const size_t indicesSizeInBytes = sizeof(mIndices[0]) * mIndexSize; + const size_t bitmapsSizeInBytes = sizeof(mBitmaps[0]) * mBitmapSize; + size_t necessarySize = sizeof(SparseBitSetHeader) + indicesSizeInBytes + bitmapsSizeInBytes; + if (out != nullptr) { + SparseBitSetHeader* header = reinterpret_cast(out); + header->maxValue = mMaxVal; + header->zeroPageIndex = mZeroPageIndex; + header->indexSize = mIndexSize; + header->bitmapSize = mBitmapSize; + + out += sizeof(SparseBitSetHeader); + memcpy(out, mIndices, indicesSizeInBytes); + out += indicesSizeInBytes; + memcpy(out, mBitmaps, bitmapsSizeInBytes); + } + return necessarySize; } int SparseBitSet::CountLeadingZeros(element x) { diff --git a/engine/src/flutter/tests/perftests/Android.mk b/engine/src/flutter/tests/perftests/Android.mk index de5769c7436..c60123a83d7 100644 --- a/engine/src/flutter/tests/perftests/Android.mk +++ b/engine/src/flutter/tests/perftests/Android.mk @@ -22,6 +22,7 @@ perftest_src_files := \ ../util/MinikinFontForTest.cpp \ ../util/UnicodeUtils.cpp \ FontCollection.cpp \ + FontFamily.cpp \ FontLanguage.cpp \ GraphemeBreak.cpp \ Hyphenator.cpp \ diff --git a/engine/src/flutter/tests/perftests/FontFamily.cpp b/engine/src/flutter/tests/perftests/FontFamily.cpp new file mode 100644 index 00000000000..a731ef640f3 --- /dev/null +++ b/engine/src/flutter/tests/perftests/FontFamily.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2017 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 + +#include +#include "../util/MinikinFontForTest.h" + +namespace minikin { + +static void BM_FontFamily_create(benchmark::State& state) { + std::shared_ptr minikinFont = + std::make_shared("/system/fonts/NotoSansCJK-Regular.ttc", 0); + + while (state.KeepRunning()) { + std::shared_ptr family = std::make_shared( + std::vector({Font(minikinFont, FontStyle())})); + } +} + +BENCHMARK(BM_FontFamily_create); + +static void BM_FontFamily_create_fromBuffer(benchmark::State& state) { + std::shared_ptr minikinFont = + std::make_shared("/system/fonts/NotoSansCJK-Regular.ttc", 0); + + std::shared_ptr family = std::make_shared( + std::vector({Font(minikinFont, FontStyle())})); + + size_t bufSize = family->writeAcceleratorTable(nullptr); + std::unique_ptr buffer(new uint8_t[bufSize]); + family->writeAcceleratorTable(buffer.get()); + + while (state.KeepRunning()) { + std::shared_ptr family = std::make_shared( + std::vector({Font(minikinFont, FontStyle())}), buffer.get(), bufSize); + } +} + +BENCHMARK(BM_FontFamily_create_fromBuffer); + +} // namespace minikin diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index da7851a3e7d..fdcc0c4e472 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -76,6 +76,7 @@ LOCAL_SRC_FILES += \ GraphemeBreakTests.cpp \ LayoutTest.cpp \ LayoutUtilsTest.cpp \ + SparseBitSetTest.cpp \ UnicodeUtilsTest.cpp \ WordBreakerTests.cpp diff --git a/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp b/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp new file mode 100644 index 00000000000..ab38f6ca755 --- /dev/null +++ b/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp @@ -0,0 +1,140 @@ +/* + * Copyright (C) 2017 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 + +#include +#include + +namespace minikin { + +TEST(SparseBitSetTest, randomTest) { + const uint32_t kTestRangeNum = 4096; + + std::mt19937 mt; // Fix seeds to be able to reproduce the result. + std::uniform_int_distribution distribution(1, 512); + + std::vector range { distribution(mt) }; + for (size_t i = 1; i < kTestRangeNum * 2; ++i) { + range.push_back((range.back() - 1) + distribution(mt)); + } + + SparseBitSet bitset; + bitset.initFromRanges(range.data(), range.size() / 2); + + uint32_t ch = 0; + for (size_t i = 0; i < range.size() / 2; ++i) { + uint32_t start = range[i * 2]; + uint32_t end = range[i * 2 + 1]; + + for (; ch < start; ch++) { + ASSERT_FALSE(bitset.get(ch)) << std::hex << ch; + } + for (; ch < end; ch++) { + ASSERT_TRUE(bitset.get(ch)) << std::hex << ch; + } + } + for (; ch < 0x1FFFFFF; ++ch) { + ASSERT_FALSE(bitset.get(ch)) << std::hex << ch; + } +} + +TEST(SparseBitSetTest, randomTest_restoredFromBuffer) { + const uint32_t kTestRangeNum = 4096; + + std::mt19937 mt; // Fix seeds to be able to reproduce the result. + std::uniform_int_distribution distribution(1, 512); + + std::vector range { distribution(mt) }; + for (size_t i = 1; i < kTestRangeNum * 2; ++i) { + range.push_back((range.back() - 1) + distribution(mt)); + } + + SparseBitSet tmpBitset; + tmpBitset.initFromRanges(range.data(), range.size() / 2); + + size_t bufSize = tmpBitset.writeToBuffer(nullptr); + ASSERT_NE(0U, bufSize); + std::vector buffer(bufSize); + tmpBitset.writeToBuffer(buffer.data()); + + SparseBitSet bitset; + bitset.initFromBuffer(buffer.data(), buffer.size()); + + uint32_t ch = 0; + for (size_t i = 0; i < range.size() / 2; ++i) { + uint32_t start = range[i * 2]; + uint32_t end = range[i * 2 + 1]; + + for (; ch < start; ch++) { + ASSERT_FALSE(bitset.get(ch)) << std::hex << ch; + } + for (; ch < end; ch++) { + ASSERT_TRUE(bitset.get(ch)) << std::hex << ch; + } + } + for (; ch < 0x1FFFFFF; ++ch) { + ASSERT_FALSE(bitset.get(ch)) << std::hex << ch; + } +} + +TEST(SparseBitSetTest, emptyBitSet) { + SparseBitSet bitset; + uint32_t empty_bitset[4] = { + 0 /* max value */, 0 /* zero page index */, 0 /* index size */, 0 /* bitmap size */ + }; + EXPECT_TRUE(bitset.initFromBuffer( + reinterpret_cast(empty_bitset), sizeof(empty_bitset))); +} + +TEST(SparseBitSetTest, invalidData) { + SparseBitSet bitset; + EXPECT_FALSE(bitset.initFromBuffer(nullptr, 0)); + + // Buffer is too small. + uint32_t small_buffer[3] = { 0, 0, 0 }; + EXPECT_FALSE(bitset.initFromBuffer( + reinterpret_cast(small_buffer), sizeof(small_buffer))); + + // Buffer size does not match with necessary size. + uint32_t invalid_size_buffer[4] = { + 0x12345678 /* max value */, 0 /* zero page index */, 0x50 /* index size*/, + 0x80 /* bitmap size */ + }; + EXPECT_FALSE(bitset.initFromBuffer( + reinterpret_cast(invalid_size_buffer), sizeof(invalid_size_buffer))); + + // max value, index size, bitmap size must be zero if the bitset is empty. + uint32_t invalid_empty_bitset1[4] = { + 1 /* max value */, 0 /* zero page index */, 0 /* index size */, 0 /* bitmap size */ + }; + EXPECT_FALSE(bitset.initFromBuffer( + reinterpret_cast(invalid_empty_bitset1), sizeof(invalid_empty_bitset1))); + + uint32_t invalid_empty_bitset2[4] = { + 0 /* max value */, 0 /* zero page index */, 1 /* index size */, 0 /* bitmap size */ + }; + EXPECT_FALSE(bitset.initFromBuffer( + reinterpret_cast(invalid_empty_bitset2), sizeof(invalid_empty_bitset2))); + + uint32_t invalid_empty_bitset3[4] = { + 0 /* max value */, 0 /* zero page index */, 0 /* index size */, 1 /* bitmap size */ + }; + EXPECT_FALSE(bitset.initFromBuffer( + reinterpret_cast(invalid_empty_bitset3), sizeof(invalid_empty_bitset3))); +} + +} // namespace minikin From 7945b2d01967b9ff765a666071c752d1f93669c9 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Mon, 13 Mar 2017 16:42:46 -0700 Subject: [PATCH 242/364] Fix build failure due to unexpected merge. FontLanguageListCache::kEmptyListId is gone, use kEmptyLanguageListId instead. Test: N/A Change-Id: I96075849c53f23fbce8dbc180a51d8f97e45f316 --- engine/src/flutter/libs/minikin/FontFamily.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index b5190c0ed30..e434f246893 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -118,7 +118,7 @@ FontFamily::FontFamily(std::vector&& fonts, const uint8_t* acceleratorTabl FontFamily::FontFamily(int variant, std::vector&& fonts, const uint8_t* acceleratorTable, size_t tableSize) - : FontFamily(FontLanguageListCache::kEmptyListId, variant, std::move(fonts), acceleratorTable, + : FontFamily(kEmptyLanguageListId, variant, std::move(fonts), acceleratorTable, tableSize) { } From 44914ce013af80626aad3b19b48b2e4fb6b718bc Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 14 Mar 2017 10:46:11 -0700 Subject: [PATCH 243/364] Revert "Use std::mutex instead of android::Mutex" This reverts commit 0eac702718a070e8ee226e63b5f540510b425e9a. Bug: 36208043 Test: N/A Change-Id: I165ab7a0718ea50a8034adb6277809e271fd762c --- .../flutter/include/minikin/FontCollection.h | 9 +- .../src/flutter/include/minikin/FontFamily.h | 2 - .../flutter/libs/minikin/FontCollection.cpp | 34 +++--- .../src/flutter/libs/minikin/FontFamily.cpp | 20 +-- .../libs/minikin/FontLanguageListCache.cpp | 91 ++++++-------- .../libs/minikin/FontLanguageListCache.h | 36 ++++-- .../src/flutter/libs/minikin/HbFontCache.cpp | 114 ++++++++---------- engine/src/flutter/libs/minikin/Layout.cpp | 47 ++++---- .../src/flutter/libs/minikin/MinikinFont.cpp | 2 +- .../flutter/libs/minikin/MinikinInternal.cpp | 11 +- .../flutter/libs/minikin/MinikinInternal.h | 21 ++-- .../tests/perftests/FontCollection.cpp | 2 +- .../unittest/FontCollectionItemizeTest.cpp | 6 +- .../flutter/tests/unittest/FontFamilyTest.cpp | 16 +-- .../unittest/FontLanguageListCacheTest.cpp | 49 ++++---- .../tests/unittest/HbFontCacheTest.cpp | 9 +- 16 files changed, 223 insertions(+), 246 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index a3396277ecb..d5fc5a11bd2 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -26,8 +26,6 @@ namespace minikin { -class FontLanguages; - class FontCollection { public: explicit FontCollection(const std::vector>& typefaces); @@ -75,16 +73,15 @@ private: void init(const std::vector>& typefaces); const std::shared_ptr& getFamilyForChar(uint32_t ch, uint32_t vs, - const FontLanguages& styleLanguages, int variant) const; + uint32_t langListId, int variant) const; - uint32_t calcFamilyScore(uint32_t ch, uint32_t vs, int variant, - const FontLanguages& styleLanguages, + uint32_t calcFamilyScore(uint32_t ch, uint32_t vs, int variant, uint32_t langListId, const std::shared_ptr& fontFamily) const; uint32_t calcCoverageScore(uint32_t ch, uint32_t vs, const std::shared_ptr& fontFamily) const; - static uint32_t calcLanguageMatchingScore(const FontLanguages& styleLanguages, + static uint32_t calcLanguageMatchingScore(uint32_t userLangListId, const FontFamily& fontFamily); static uint32_t calcVariantMatchingScore(int variant, const FontFamily& fontFamily); diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index a44b9c312ff..4186c2baabb 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -31,7 +31,6 @@ namespace minikin { class MinikinFont; -class FontLanguages; // FontStyle represents all style information needed to select an actual font // from a collection. The implementation is packed into two 32-bit words @@ -186,7 +185,6 @@ private: int mVariant; std::vector mFonts; std::unordered_set mSupportedAxes; - std::unique_ptr mLanguages; SparseBitSet mCoverage; bool mHasVSTable; diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index e8c05d7d77f..a3d2d974e0e 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -91,7 +91,7 @@ FontCollection::FontCollection(const vector>& typefa } void FontCollection::init(const vector>& typefaces) { - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); mId = sNextId++; vector lastChar; size_t nTypefaces = typefaces.size(); @@ -171,8 +171,7 @@ const uint32_t kFirstFontScore = UINT32_MAX; // base character. // - kFirstFontScore: When the font is the first font family in the collection and it supports the // given character or variation sequence. -uint32_t FontCollection::calcFamilyScore(uint32_t ch, uint32_t vs, int variant, - const FontLanguages& styleLanguages, +uint32_t FontCollection::calcFamilyScore(uint32_t ch, uint32_t vs, int variant, uint32_t langListId, const std::shared_ptr& fontFamily) const { const uint32_t coverageScore = calcCoverageScore(ch, vs, fontFamily); @@ -181,7 +180,7 @@ uint32_t FontCollection::calcFamilyScore(uint32_t ch, uint32_t vs, int variant, return coverageScore; } - const uint32_t languageScore = calcLanguageMatchingScore(styleLanguages, *fontFamily); + const uint32_t languageScore = calcLanguageMatchingScore(langListId, *fontFamily); const uint32_t variantScore = calcVariantMatchingScore(variant, *fontFamily); // Subscores are encoded into 31 bits representation to meet the subscore priority. @@ -223,7 +222,7 @@ uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, } if (vs == EMOJI_STYLE_VS || vs == TEXT_STYLE_VS) { - const FontLanguages& langs = getFontLanguagesFromCacheLocked(fontFamily->langId()); + const FontLanguages& langs = FontLanguageListCache::getById(fontFamily->langId()); bool hasEmojiFlag = false; for (size_t i = 0; i < langs.size(); ++i) { if (langs[i].getEmojiStyle() == FontLanguage::EMSTYLE_EMOJI) { @@ -260,13 +259,14 @@ uint32_t FontCollection::calcCoverageScore(uint32_t ch, uint32_t vs, // Here, m is the maximum number of languages to be compared, and s(i) is the i-th language's // matching score. The possible values of s(i) are 0, 1, 2, 3 and 4. uint32_t FontCollection::calcLanguageMatchingScore( - const FontLanguages& styleLanguages, const FontFamily& fontFamily) { - const FontLanguages& fontLanguages = getFontLanguagesFromCacheLocked(fontFamily.langId()); + uint32_t userLangListId, const FontFamily& fontFamily) { + const FontLanguages& langList = FontLanguageListCache::getById(userLangListId); + const FontLanguages& fontLanguages = FontLanguageListCache::getById(fontFamily.langId()); - const size_t maxCompareNum = std::min(styleLanguages.size(), FONT_LANGUAGES_LIMIT); + const size_t maxCompareNum = std::min(langList.size(), FONT_LANGUAGES_LIMIT); uint32_t score = 0; for (size_t i = 0; i < maxCompareNum; ++i) { - score = score * 5u + styleLanguages[i].calcScoreFor(fontLanguages); + score = score * 5u + langList[i].calcScoreFor(fontLanguages); } return score; } @@ -284,7 +284,7 @@ uint32_t FontCollection::calcVariantMatchingScore(int variant, const FontFamily& // 3. Highest score wins, with ties resolved to the first font. // This method never returns nullptr. const std::shared_ptr& FontCollection::getFamilyForChar(uint32_t ch, uint32_t vs, - const FontLanguages& styleLanguages, int variant) const { + uint32_t langListId, int variant) const { if (ch >= mMaxChar) { return mFamilies[0]; } @@ -303,7 +303,7 @@ const std::shared_ptr& FontCollection::getFamilyForChar(uint32_t ch, for (size_t i = range.start; i < range.end; i++) { const std::shared_ptr& family = vs == 0 ? mFamilies[mFamilyVec[i]] : mFamilies[i]; - const uint32_t score = calcFamilyScore(ch, vs, variant, styleLanguages, family); + const uint32_t score = calcFamilyScore(ch, vs, variant, langListId, family); if (score == kFirstFontScore) { // If the first font family supports the given character or variation sequence, always // use it. @@ -323,7 +323,7 @@ const std::shared_ptr& FontCollection::getFamilyForChar(uint32_t ch, if (U_SUCCESS(errorCode) && len > 0) { int off = 0; U16_NEXT_UNSAFE(decomposed, off, ch); - return getFamilyForChar(ch, vs, styleLanguages, variant); + return getFamilyForChar(ch, vs, langListId, variant); } } return mFamilies[0]; @@ -368,7 +368,7 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, return false; } - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); // Currently mRanges can not be used here since it isn't aware of the variation sequence. for (size_t i = 0; i < mVSFamilyVec.size(); i++) { @@ -381,7 +381,8 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, // for emoji + U+FE0E case since we have special fallback rule for the sequence. if (isEmojiStyleVSBase(baseCodepoint) && variationSelector == TEXT_STYLE_VS) { for (size_t i = 0; i < mFamilies.size(); ++i) { - if (!mFamilies[i]->isColorEmojiFamily() && mFamilies[i]->hasGlyph(baseCodepoint, 0)) { + if (!mFamilies[i]->isColorEmojiFamily() && variationSelector == TEXT_STYLE_VS && + mFamilies[i]->hasGlyph(baseCodepoint, 0)) { return true; } } @@ -392,8 +393,7 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, void FontCollection::itemize(const uint16_t *string, size_t string_size, FontStyle style, vector* result) const { - const FontLanguages& styleLanguages = - getFontLanguagesFromCacheLocked(style.getLanguageListId()); + const uint32_t langListId = style.getLanguageListId(); int variant = style.getVariant(); const FontFamily* lastFamily = nullptr; Run* run = NULL; @@ -433,7 +433,7 @@ void FontCollection::itemize(const uint16_t *string, size_t string_size, FontSty if (!shouldContinueRun) { const std::shared_ptr& family = getFamilyForChar( - ch, isVariationSelector(nextCh) ? nextCh : 0, styleLanguages, variant); + ch, isVariationSelector(nextCh) ? nextCh : 0, langListId, variant); if (utf16Pos == 0 || family.get() != lastFamily) { size_t start = utf16Pos; // Workaround for combining marks and emoji modifiers until we implement diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index e434f246893..4097e8fb239 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -41,7 +41,7 @@ using std::vector; namespace minikin { FontStyle::FontStyle(int variant, int weight, bool italic) - : FontStyle(kEmptyLanguageListId, variant, weight, italic) { + : FontStyle(FontLanguageListCache::kEmptyListId, variant, weight, italic) { } FontStyle::FontStyle(uint32_t languageListId, int variant, int weight, bool italic) @@ -56,8 +56,8 @@ android::hash_t FontStyle::hash() const { // static uint32_t FontStyle::registerLanguageList(const std::string& languages) { - ScopedLock _l(gLock); - return putLanguageListToCacheLocked(languages); + android::AutoMutex _l(gMinikinLock); + return FontLanguageListCache::getId(languages); } // static @@ -76,7 +76,7 @@ Font::Font(std::shared_ptr&& typeface, FontStyle style) } void Font::loadAxes() { - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); const uint32_t fvarTag = MinikinFont::MakeTag('f', 'v', 'a', 'r'); HbBlob fvarTable(getFontTable(typeface.get(), fvarTag)); if (fvarTable.size() == 0) { @@ -104,7 +104,7 @@ FontFamily::FontFamily(std::vector&& fonts) : FontFamily(0 /* variant */, } FontFamily::FontFamily(int variant, std::vector&& fonts) - : FontFamily(kEmptyLanguageListId, variant, std::move(fonts)) { + : FontFamily(FontLanguageListCache::kEmptyListId, variant, std::move(fonts)) { } FontFamily::FontFamily(uint32_t langId, int variant, std::vector&& fonts) @@ -118,7 +118,7 @@ FontFamily::FontFamily(std::vector&& fonts, const uint8_t* acceleratorTabl FontFamily::FontFamily(int variant, std::vector&& fonts, const uint8_t* acceleratorTable, size_t tableSize) - : FontFamily(kEmptyLanguageListId, variant, std::move(fonts), acceleratorTable, + : FontFamily(FontLanguageListCache::kEmptyListId, variant, std::move(fonts), acceleratorTable, tableSize) { } @@ -133,7 +133,7 @@ FontFamily::~FontFamily() { bool FontFamily::analyzeStyle(const std::shared_ptr& typeface, int* weight, bool* italic) { - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2'); HbBlob os2Table(getFontTable(typeface.get(), os2Tag)); if (os2Table.get() == nullptr) return false; @@ -178,7 +178,7 @@ FakedFont FontFamily::getClosestMatch(FontStyle style) const { } bool FontFamily::isColorEmojiFamily() const { - const FontLanguages& languageList = getFontLanguagesFromCacheLocked(mLangId); + const FontLanguages& languageList = FontLanguageListCache::getById(mLangId); for (size_t i = 0; i < languageList.size(); ++i) { if (languageList[i].getEmojiStyle() == FontLanguage::EMSTYLE_EMOJI) { return true; @@ -188,7 +188,7 @@ bool FontFamily::isColorEmojiFamily() const { } void FontFamily::computeCoverage() { - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); const FontStyle defaultStyle; const MinikinFont* typeface = getClosestMatch(defaultStyle).font; const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); @@ -206,7 +206,7 @@ void FontFamily::computeCoverage() { } bool FontFamily::hasGlyph(uint32_t codepoint, uint32_t variationSelector) const { - assertLocked(gLock); + assertMinikinLocked(); if (variationSelector != 0 && !mHasVSTable) { // Early exit if the variation selector is specified but the font doesn't have a cmap format // 14 subtable. diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp index 5323e580cec..f1e14f0a66d 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.cpp @@ -20,8 +20,6 @@ #include #include -#include -#include #include @@ -30,6 +28,8 @@ namespace minikin { +const uint32_t FontLanguageListCache::kEmptyListId; + // Returns the text length of output. static size_t toLanguageTag(char* output, size_t outSize, const std::string& locale) { output[0] = '\0'; @@ -111,61 +111,46 @@ static std::vector parseLanguageList(const std::string& input) { return result; } -class FontLanguageListCache { -public: - FontLanguageListCache() { +// static +uint32_t FontLanguageListCache::getId(const std::string& languages) { + FontLanguageListCache* inst = FontLanguageListCache::getInstance(); + std::unordered_map::const_iterator it = + inst->mLanguageListLookupTable.find(languages); + if (it != inst->mLanguageListLookupTable.end()) { + return it->second; + } + + // Given language list is not in cache. Insert it and return newly assigned ID. + const uint32_t nextId = inst->mLanguageLists.size(); + FontLanguages fontLanguages(parseLanguageList(languages)); + if (fontLanguages.empty()) { + return kEmptyListId; + } + inst->mLanguageLists.push_back(std::move(fontLanguages)); + inst->mLanguageListLookupTable.insert(std::make_pair(languages, nextId)); + return nextId; +} + +// static +const FontLanguages& FontLanguageListCache::getById(uint32_t id) { + FontLanguageListCache* inst = FontLanguageListCache::getInstance(); + LOG_ALWAYS_FATAL_IF(id >= inst->mLanguageLists.size(), "Lookup by unknown language list ID."); + return inst->mLanguageLists[id]; +} + +// static +FontLanguageListCache* FontLanguageListCache::getInstance() { + assertMinikinLocked(); + static FontLanguageListCache* instance = nullptr; + if (instance == nullptr) { + instance = new FontLanguageListCache(); + // Insert an empty language list for mapping default language list to kEmptyListId. // The default language list has only one FontLanguage and it is the unsupported language. - mLanguageLists.emplace(kEmptyLanguageListId, FontLanguages()); - mLanguageListLookupTable.emplace("", kEmptyLanguageListId); + instance->mLanguageLists.push_back(FontLanguages()); + instance->mLanguageListLookupTable.insert(std::make_pair("", kEmptyListId)); } - - uint32_t put(const std::string& languages) { - assertLocked(gLock); - - const auto& it = mLanguageListLookupTable.find(languages); - if (it != mLanguageListLookupTable.end()) { - return it->second; - } - - // Given language list is not in cache. Insert it and return newly assigned ID. - const uint32_t nextId = mLanguageLists.size(); - FontLanguages fontLanguages(parseLanguageList(languages)); - if (fontLanguages.empty()) { - mLanguageListLookupTable.emplace(languages, kEmptyLanguageListId); - return kEmptyLanguageListId; - } - mLanguageLists.emplace(nextId, std::move(fontLanguages)); - mLanguageListLookupTable.emplace(languages, nextId); - return nextId; - } - - const FontLanguages& get(uint32_t id) { - assertLocked(gLock); - - return mLanguageLists[id]; - } - -private: - std::unordered_map mLanguageLists; - - // A map from string representation of the font language list to the ID. - std::unordered_map mLanguageListLookupTable; -}; - -static FontLanguageListCache& getInstance() { - static FontLanguageListCache instance; return instance; } -// static -uint32_t putLanguageListToCacheLocked(const std::string& languages) { - return getInstance().put(languages); -} - -// static -const FontLanguages& getFontLanguagesFromCacheLocked(uint32_t id) { - return getInstance().get(id); -} - } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/FontLanguageListCache.h b/engine/src/flutter/libs/minikin/FontLanguageListCache.h index 2eafab91518..9bf156f9de7 100644 --- a/engine/src/flutter/libs/minikin/FontLanguageListCache.h +++ b/engine/src/flutter/libs/minikin/FontLanguageListCache.h @@ -17,21 +17,39 @@ #ifndef MINIKIN_FONT_LANGUAGE_LIST_CACHE_H #define MINIKIN_FONT_LANGUAGE_LIST_CACHE_H +#include + +#include #include "FontLanguage.h" namespace minikin { -// A special ID for the empty language list. -// This value must be 0 since the empty language list is inserted into mLanguageLists by default. -const uint32_t kEmptyLanguageListId = 0; +class FontLanguageListCache { +public: + // A special ID for the empty language list. + // This value must be 0 since the empty language list is inserted into mLanguageLists by + // default. + const static uint32_t kEmptyListId = 0; -// Looks up from internal cache and returns associated ID if FontLanguages constructed from given -// string is already registered. If it is new to internal cache, put it to internal cache and -// returns newly assigned ID. -uint32_t putLanguageListToCacheLocked(const std::string& languages); + // Returns language list ID for the given string representation of FontLanguages. + // Caller should acquire a lock before calling the method. + static uint32_t getId(const std::string& languages); -// Returns FontLanguages associated with given ID. -const FontLanguages& getFontLanguagesFromCacheLocked(uint32_t id); + // Caller should acquire a lock before calling the method. + static const FontLanguages& getById(uint32_t id); + +private: + FontLanguageListCache() {} // Singleton + ~FontLanguageListCache() {} + + // Caller should acquire a lock before calling the method. + static FontLanguageListCache* getInstance(); + + std::vector mLanguageLists; + + // A map from string representation of the font language list to the ID. + std::unordered_map mLanguageListLookupTable; +}; } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index 79aebe931e5..af3d783bc84 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -62,80 +62,70 @@ private: android::LruCache mCache; }; -class HbFontCacheHolder { -public: - HbFontCacheHolder() {} - - hb_font_t* getCachedFont(const MinikinFont* minikinFont) { - assertLocked(gLock); - - // TODO: get rid of nullFaceFont - static hb_font_t* nullFaceFont = nullptr; - if (minikinFont == nullptr) { - if (nullFaceFont == nullptr) { - nullFaceFont = hb_font_create(nullptr); - } - return hb_font_reference(nullFaceFont); - } - - const int32_t fontId = minikinFont->GetUniqueId(); - hb_font_t* font = mFontCache.get(fontId); - if (font != nullptr) { - return hb_font_reference(font); - } - - hb_face_t* face; - const void* buf = minikinFont->GetFontData(); - size_t size = minikinFont->GetFontSize(); - hb_blob_t* blob = hb_blob_create(reinterpret_cast(buf), size, - HB_MEMORY_MODE_READONLY, nullptr, nullptr); - face = hb_face_create(blob, minikinFont->GetFontIndex()); - hb_blob_destroy(blob); - - hb_font_t* parent_font = hb_font_create(face); - hb_ot_font_set_funcs(parent_font); - - unsigned int upem = hb_face_get_upem(face); - hb_font_set_scale(parent_font, upem, upem); - - font = hb_font_create_sub_font(parent_font); - hb_font_destroy(parent_font); - hb_face_destroy(face); - mFontCache.put(fontId, font); - return hb_font_reference(font); +HbFontCache* getFontCacheLocked() { + assertMinikinLocked(); + static HbFontCache* cache = nullptr; + if (cache == nullptr) { + cache = new HbFontCache(); } - - void clearFontCache() { - assertLocked(gLock); - mFontCache.clear(); - } - - void removeFont(const MinikinFont* minikinFont) { - assertLocked(gLock); - mFontCache.remove(minikinFont->GetUniqueId()); - } - -private: - HbFontCache mFontCache; -}; - -static HbFontCacheHolder& getInstance() { - static HbFontCacheHolder instance; - return instance; + return cache; } void purgeHbFontCacheLocked() { - getInstance().clearFontCache(); + assertMinikinLocked(); + getFontCacheLocked()->clear(); } void purgeHbFontLocked(const MinikinFont* minikinFont) { - getInstance().removeFont(minikinFont); + assertMinikinLocked(); + const int32_t fontId = minikinFont->GetUniqueId(); + getFontCacheLocked()->remove(fontId); } // Returns a new reference to a hb_font_t object, caller is // responsible for calling hb_font_destroy() on it. hb_font_t* getHbFontLocked(const MinikinFont* minikinFont) { - return getInstance().getCachedFont(minikinFont); + assertMinikinLocked(); + // TODO: get rid of nullFaceFont + static hb_font_t* nullFaceFont = nullptr; + if (minikinFont == nullptr) { + if (nullFaceFont == nullptr) { + nullFaceFont = hb_font_create(nullptr); + } + return hb_font_reference(nullFaceFont); + } + + HbFontCache* fontCache = getFontCacheLocked(); + const int32_t fontId = minikinFont->GetUniqueId(); + hb_font_t* font = fontCache->get(fontId); + if (font != nullptr) { + return hb_font_reference(font); + } + + hb_face_t* face; + const void* buf = minikinFont->GetFontData(); + size_t size = minikinFont->GetFontSize(); + hb_blob_t* blob = hb_blob_create(reinterpret_cast(buf), size, + HB_MEMORY_MODE_READONLY, nullptr, nullptr); + face = hb_face_create(blob, minikinFont->GetFontIndex()); + hb_blob_destroy(blob); + + hb_font_t* parent_font = hb_font_create(face); + hb_ot_font_set_funcs(parent_font); + + unsigned int upem = hb_face_get_upem(face); + hb_font_set_scale(parent_font, upem, upem); + + font = hb_font_create_sub_font(parent_font); + std::vector variations; + for (const FontVariation& variation : minikinFont->GetAxes()) { + variations.push_back({variation.axisTag, variation.value}); + } + hb_font_set_variations(font, variations.data(), variations.size()); + hb_font_destroy(parent_font); + hb_face_destroy(face); + fontCache->put(fontId, font); + return hb_font_reference(font); } } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index d85ddd79a35..743cb763aea 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -200,7 +201,7 @@ static unsigned int disabledDecomposeCompatibility(hb_unicode_funcs_t*, hb_codep return 0; } -class LayoutEngine { +class LayoutEngine : public ::android::Singleton { public: LayoutEngine() { unicodeFunctions = hb_unicode_funcs_create(hb_icu_get_unicode_funcs()); @@ -211,26 +212,8 @@ public: hb_buffer_set_unicode_funcs(hbBuffer, unicodeFunctions); } - Layout* getCachedLayout(LayoutCacheKey& key, LayoutContext* ctx, - const std::shared_ptr& collection) { - assertLocked(gLock); - return layoutCache.get(key, ctx, collection); - } - - void clearLayoutCache() { - assertLocked(gLock); - layoutCache.clear(); - } - hb_buffer_t* hbBuffer; hb_unicode_funcs_t* unicodeFunctions; - - static LayoutEngine& getInstance() { - static LayoutEngine instance; - return instance; - } - -private: LayoutCache layoutCache; }; @@ -305,7 +288,8 @@ static hb_bool_t harfbuzzGetGlyphHorizontalOrigin(hb_font_t* /* hbFont */, void* } hb_font_funcs_t* getHbFontFuncs(bool forColorBitmapFont) { - assertLocked(gLock); + assertMinikinLocked(); + static hb_font_funcs_t* hbFuncs = nullptr; static hb_font_funcs_t* hbFuncsForColorBitmap = nullptr; @@ -601,7 +585,8 @@ BidiText::BidiText(const uint16_t* buf, size_t start, size_t count, size_t bufSi void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint) { - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); + LayoutContext ctx; ctx.style = style; ctx.paint = paint; @@ -619,7 +604,8 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu float Layout::measureText(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint, const std::shared_ptr& collection, float* advances) { - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); + LayoutContext ctx; ctx.style = style; ctx.paint = paint; @@ -691,6 +677,7 @@ float Layout::doLayoutRunCached(const uint16_t* buf, size_t start, size_t count, float Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size_t bufSize, bool isRtl, LayoutContext* ctx, size_t bufStart, const std::shared_ptr& collection, Layout* layout, float* advances) { + LayoutCache& cache = LayoutEngine::getInstance().layoutCache; LayoutCacheKey key(collection, ctx->paint, ctx->style, buf, start, count, bufSize, isRtl); float wordSpacing = count == 1 && isWordSpace(buf[start]) ? ctx->paint.wordSpacing : 0; @@ -707,7 +694,7 @@ float Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size } advance = layoutForWord.getAdvance(); } else { - Layout* layoutForWord = LayoutEngine::getInstance().getCachedLayout(key, ctx, collection); + Layout* layoutForWord = cache.get(key, ctx, collection); if (layout) { layout->appendLayout(layoutForWord, bufStart, wordSpacing); } @@ -960,7 +947,7 @@ void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t hb_buffer_set_script(buffer, script); hb_buffer_set_direction(buffer, isRtl? HB_DIRECTION_RTL : HB_DIRECTION_LTR); const FontLanguages& langList = - getFontLanguagesFromCacheLocked(ctx->style.getLanguageListId()); + FontLanguageListCache::getById(ctx->style.getLanguageListId()); if (langList.size() != 0) { const FontLanguage* hbLanguage = &langList[0]; for (size_t i = 0; i < langList.size(); ++i) { @@ -1162,9 +1149,17 @@ void Layout::getBounds(MinikinRect* bounds) const { } void Layout::purgeCaches() { - ScopedLock _l(gLock); - LayoutEngine::getInstance().clearLayoutCache(); + android::AutoMutex _l(gMinikinLock); + LayoutCache& layoutCache = LayoutEngine::getInstance().layoutCache; + layoutCache.clear(); purgeHbFontCacheLocked(); } } // namespace minikin + +// Unable to define the static data member outside of android. +// TODO: introduce our own Singleton to drop android namespace. +namespace android { +ANDROID_SINGLETON_STATIC_INSTANCE(minikin::LayoutEngine); +} // namespace android + diff --git a/engine/src/flutter/libs/minikin/MinikinFont.cpp b/engine/src/flutter/libs/minikin/MinikinFont.cpp index f8e0d5b2900..6bf6a4ae3b7 100644 --- a/engine/src/flutter/libs/minikin/MinikinFont.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFont.cpp @@ -21,7 +21,7 @@ namespace minikin { MinikinFont::~MinikinFont() { - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); purgeHbFontLocked(this); } diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index 1d06e03aa68..e766dce992d 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -25,8 +25,13 @@ namespace minikin { -std::mutex gMutex; -std::unique_lock gLock(gMutex, std::defer_lock); +android::Mutex gMinikinLock; + +void assertMinikinLocked() { +#ifdef ENABLE_RACE_DETECTION + LOG_ALWAYS_FATAL_IF(gMinikinLock.tryLock() == 0); +#endif +} bool isEmoji(uint32_t c) { // U+2695 U+2640 U+2642 are not in emoji category in Unicode 9 but they are now emoji category. @@ -81,7 +86,7 @@ bool isEmojiBase(uint32_t c) { } hb_blob_t* getFontTable(const MinikinFont* minikinFont, uint32_t tag) { - assertLocked(gLock); + assertMinikinLocked(); hb_font_t* font = getHbFontLocked(minikinFont); hb_face_t* face = hb_font_get_face(font); hb_blob_t* blob = hb_face_reference_table(face, tag); diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.h b/engine/src/flutter/libs/minikin/MinikinInternal.h index c374cb4656e..365f20cc0df 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.h +++ b/engine/src/flutter/libs/minikin/MinikinInternal.h @@ -21,27 +21,20 @@ #include -#include -#include +#include -#include +#include namespace minikin { // All external Minikin interfaces are designed to be thread-safe. -// Presently, that's implemented by a global lock, and having all external interfaces take that -// lock. -extern std::unique_lock gLock; -typedef std::unique_lock> ScopedLock; +// Presently, that's implemented by through a global lock, and having +// all external interfaces take that lock. -#ifdef ENABLE_RACE_DETECTION -inline void assertLocked(const std::unique_lock& lock) { - LOG_ALWAYS_FATAL_IF(!lock.owns_lock()); -} -#else -inline void assertLocked(const std::unique_lock&) {} -#endif +extern android::Mutex gMinikinLock; +// Aborts if gMinikinLock is not acquired. Do nothing on the release build. +void assertMinikinLocked(); // Returns true if c is emoji. bool isEmoji(uint32_t c); diff --git a/engine/src/flutter/tests/perftests/FontCollection.cpp b/engine/src/flutter/tests/perftests/FontCollection.cpp index 304708f6c77..6f9d636ca30 100644 --- a/engine/src/flutter/tests/perftests/FontCollection.cpp +++ b/engine/src/flutter/tests/perftests/FontCollection.cpp @@ -77,7 +77,7 @@ static void BM_FontCollection_itemize(benchmark::State& state) { std::vector result; FontStyle style(FontStyle::registerLanguageList(ITEMIZE_TEST_CASES[testIndex].languageTag)); - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); while (state.KeepRunning()) { result.clear(); collection->itemize(buffer, utf16_length, style, &result); diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 557458b80bd..aa142cccdcd 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -60,7 +60,7 @@ void itemize(const std::shared_ptr& collection, const char* str, result->clear(); ParseUnicode(buf, BUF_SIZE, str, &len, NULL); - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); collection->itemize(buf, len, style, result); } @@ -72,8 +72,8 @@ const std::string& getFontPath(const FontCollection::Run& run) { // Utility function to obtain FontLanguages from string. const FontLanguages& registerAndGetFontLanguages(const std::string& lang_string) { - ScopedLock _l(gLock); - return getFontLanguagesFromCacheLocked(putLanguageListToCacheLocked(lang_string)); + android::AutoMutex _l(gMinikinLock); + return FontLanguageListCache::getById(FontLanguageListCache::getId(lang_string)); } TEST_F(FontCollectionItemizeTest, itemize_latin) { diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 81f595694ca..5285f2642b4 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -30,15 +30,15 @@ typedef ICUTestBase FontLanguagesTest; typedef ICUTestBase FontLanguageTest; static const FontLanguages& createFontLanguages(const std::string& input) { - ScopedLock _l(gLock); - uint32_t langId = putLanguageListToCacheLocked(input); - return getFontLanguagesFromCacheLocked(langId); + android::AutoMutex _l(gMinikinLock); + uint32_t langId = FontLanguageListCache::getId(input); + return FontLanguageListCache::getById(langId); } static FontLanguage createFontLanguage(const std::string& input) { - ScopedLock _l(gLock); - uint32_t langId = putLanguageListToCacheLocked(input); - return getFontLanguagesFromCacheLocked(langId)[0]; + android::AutoMutex _l(gMinikinLock); + uint32_t langId = FontLanguageListCache::getId(input); + return FontLanguageListCache::getById(langId)[0]; } static FontLanguage createFontLanguageWithoutICUSanitization(const std::string& input) { @@ -533,7 +533,7 @@ TEST_F(FontFamilyTest, hasVariationSelectorTest) { std::shared_ptr family( new FontFamily(std::vector{ Font(minikinFont, FontStyle()) })); - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); const uint32_t kVS1 = 0xFE00; const uint32_t kVS2 = 0xFE01; @@ -586,7 +586,7 @@ TEST_F(FontFamilyTest, hasVSTableTest) { new MinikinFontForTest(testCase.fontPath)); std::shared_ptr family(new FontFamily( std::vector{ Font(minikinFont, FontStyle()) })); - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); EXPECT_EQ(testCase.hasVSTable, family->hasVSTable()); } } diff --git a/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp b/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp index bd82e0f9947..81d84a8a288 100644 --- a/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp @@ -31,43 +31,40 @@ TEST_F(FontLanguageListCacheTest, getId) { EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en,zh-Hans")); - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); + EXPECT_EQ(0UL, FontLanguageListCache::getId("")); - EXPECT_EQ(0UL, putLanguageListToCacheLocked("")); + EXPECT_EQ(FontLanguageListCache::getId("en"), FontLanguageListCache::getId("en")); + EXPECT_NE(FontLanguageListCache::getId("en"), FontLanguageListCache::getId("jp")); - EXPECT_EQ(putLanguageListToCacheLocked("en"), putLanguageListToCacheLocked("en")); - EXPECT_NE(putLanguageListToCacheLocked("en"), putLanguageListToCacheLocked("jp")); - - EXPECT_EQ(putLanguageListToCacheLocked("en,zh-Hans"), - putLanguageListToCacheLocked("en,zh-Hans")); - EXPECT_NE(putLanguageListToCacheLocked("en,zh-Hans"), - putLanguageListToCacheLocked("zh-Hans,en")); - EXPECT_NE(putLanguageListToCacheLocked("en,zh-Hans"), - putLanguageListToCacheLocked("jp")); - EXPECT_NE(putLanguageListToCacheLocked("en,zh-Hans"), - putLanguageListToCacheLocked("en")); - EXPECT_NE(putLanguageListToCacheLocked("en,zh-Hans"), - putLanguageListToCacheLocked("en,zh-Hant")); + EXPECT_EQ(FontLanguageListCache::getId("en,zh-Hans"), + FontLanguageListCache::getId("en,zh-Hans")); + EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), + FontLanguageListCache::getId("zh-Hans,en")); + EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), + FontLanguageListCache::getId("jp")); + EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), + FontLanguageListCache::getId("en")); + EXPECT_NE(FontLanguageListCache::getId("en,zh-Hans"), + FontLanguageListCache::getId("en,zh-Hant")); } TEST_F(FontLanguageListCacheTest, getById) { - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); + uint32_t enLangId = FontLanguageListCache::getId("en"); + uint32_t jpLangId = FontLanguageListCache::getId("jp"); + FontLanguage english = FontLanguageListCache::getById(enLangId)[0]; + FontLanguage japanese = FontLanguageListCache::getById(jpLangId)[0]; - uint32_t enLangId = putLanguageListToCacheLocked("en"); - uint32_t jpLangId = putLanguageListToCacheLocked("jp"); - FontLanguage english = getFontLanguagesFromCacheLocked(enLangId)[0]; - FontLanguage japanese = getFontLanguagesFromCacheLocked(jpLangId)[0]; - - const FontLanguages& defLangs = getFontLanguagesFromCacheLocked(0); + const FontLanguages& defLangs = FontLanguageListCache::getById(0); EXPECT_TRUE(defLangs.empty()); - const FontLanguages& langs = getFontLanguagesFromCacheLocked( - putLanguageListToCacheLocked("en")); + const FontLanguages& langs = FontLanguageListCache::getById(FontLanguageListCache::getId("en")); ASSERT_EQ(1UL, langs.size()); EXPECT_EQ(english, langs[0]); - const FontLanguages& langs2 = getFontLanguagesFromCacheLocked( - putLanguageListToCacheLocked("en,jp")); + const FontLanguages& langs2 = + FontLanguageListCache::getById(FontLanguageListCache::getId("en,jp")); ASSERT_EQ(2UL, langs2.size()); EXPECT_EQ(english, langs2[0]); EXPECT_EQ(japanese, langs2[1]); diff --git a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp index 7691b8421e9..a5581a27b88 100644 --- a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp @@ -18,6 +18,7 @@ #include #include +#include #include @@ -32,7 +33,7 @@ namespace minikin { class HbFontCacheTest : public testing::Test { public: virtual void TearDown() { - ScopedLock _l(gLock); + android::AutoMutex _l(gMinikinLock); purgeHbFontCacheLocked(); } }; @@ -47,8 +48,7 @@ TEST_F(HbFontCacheTest, getHbFontLockedTest) { std::shared_ptr fontC( new MinikinFontForTest(kTestFontDir "BoldItalic.ttf")); - ScopedLock _l(gLock); - + android::AutoMutex _l(gMinikinLock); // Never return NULL. EXPECT_NE(nullptr, getHbFontLocked(fontA.get())); EXPECT_NE(nullptr, getHbFontLocked(fontB.get())); @@ -70,8 +70,7 @@ TEST_F(HbFontCacheTest, purgeCacheTest) { std::shared_ptr minikinFont( new MinikinFontForTest(kTestFontDir "Regular.ttf")); - ScopedLock _l(gLock); - + android::AutoMutex _l(gMinikinLock); hb_font_t* font = getHbFontLocked(minikinFont.get()); ASSERT_NE(nullptr, font); From f4c0bd2e1b9cd2282bf5ac730a29203015f7c0d1 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Mon, 13 Mar 2017 21:52:52 -0700 Subject: [PATCH 244/364] Break grapheme clusters after viramas if they end a cluster Previously, we stayed on the conservative side and disallowed any grapheme breaks (and thus cursoring) where a virama was followed by a letter, since we did not know if the virama would be forming a cluster with the letter or not. This created problems with Indic languages with infrequent conjuncts, such as Tamil. Now we use the information in calculated advances to find if a cluster is formed. If there is no cluster, we break the grapheme and allow cursoring after the virama. Test: Unit tests added to GraphemeBreakTests and MeasurementTests. Test: Also manually tested Tamil sequences. Bug: 35721792 Change-Id: Ib159edb94b3ad6f693f0d3dad016b332b2cef447 --- .../flutter/include/minikin/GraphemeBreak.h | 12 ++-- .../flutter/libs/minikin/GraphemeBreak.cpp | 37 ++++++------ .../src/flutter/libs/minikin/Measurement.cpp | 7 ++- .../flutter/tests/perftests/GraphemeBreak.cpp | 6 +- engine/src/flutter/tests/unittest/Android.mk | 1 + .../tests/unittest/GraphemeBreakTests.cpp | 44 ++++++++++++-- .../tests/unittest/MeasurementTests.cpp | 60 +++++++++++++++++++ 7 files changed, 131 insertions(+), 36 deletions(-) create mode 100644 engine/src/flutter/tests/unittest/MeasurementTests.cpp diff --git a/engine/src/flutter/include/minikin/GraphemeBreak.h b/engine/src/flutter/include/minikin/GraphemeBreak.h index b501f6784fa..f1b5102a0c7 100644 --- a/engine/src/flutter/include/minikin/GraphemeBreak.h +++ b/engine/src/flutter/include/minikin/GraphemeBreak.h @@ -31,15 +31,15 @@ public: }; // Determine whether the given offset is a grapheme break. - // This implementation generally follows Unicode TR29 extended - // grapheme break, but with some tweaks to more closely match - // existing implementations. - static bool isGraphemeBreak(const uint16_t* buf, size_t start, size_t count, size_t offset); + // This implementation generally follows Unicode's UTR #29 extended + // grapheme break, with various tweaks. + static bool isGraphemeBreak(const float* advances, const uint16_t* buf, size_t start, + size_t count, size_t offset); // Matches Android's Java API. Note, return (size_t)-1 for AT to // signal non-break because unsigned return type. - static size_t getTextRunCursor(const uint16_t* buf, size_t start, size_t count, - size_t offset, MoveOpt opt); + static size_t getTextRunCursor(const float* advances, const uint16_t* buf, size_t start, + size_t count, size_t offset, MoveOpt opt); }; } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index 1b3d1ab33ba..56f3a52a5df 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -55,8 +55,8 @@ bool isPureKiller(uint32_t c) { || c == 0xA953 || c == 0xABED || c == 0x11134 || c == 0x112EA || c == 0x1172B); } -bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t count, - size_t offset) { +bool GraphemeBreak::isGraphemeBreak(const float* advances, const uint16_t* buf, size_t start, + size_t count, const size_t offset) { // This implementation closely follows Unicode Standard Annex #29 on // Unicode Text Segmentation (http://www.unicode.org/reports/tr29/), // implementing a tailored version of extended grapheme clusters. @@ -73,8 +73,9 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co uint32_t c1 = 0; uint32_t c2 = 0; size_t offset_back = offset; + size_t offset_forward = offset; U16_PREV(buf, start, offset_back, c1); - U16_NEXT(buf, offset, start + count, c2); + U16_NEXT(buf, offset_forward, start + count, c2); int32_t p1 = tailoredGraphemeClusterBreak(c1); int32_t p2 = tailoredGraphemeClusterBreak(c2); // Rule GB3, CR x LF @@ -117,25 +118,23 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co } } - // Note that the offset has moved forwared 2 code units by U16_NEXT. // The number 4 comes from the number of code units in a whole flag. - return (offset - 2 - offset_back) % 4 == 0; + return (offset - offset_back) % 4 == 0; } // Rule GB9, x (Extend | ZWJ); Rule GB9a, x SpacingMark; Rule GB9b, Prepend x if (p2 == U_GCB_EXTEND || p2 == U_GCB_ZWJ || p2 == U_GCB_SPACING_MARK || p1 == U_GCB_PREPEND) { return false; } - // Cluster indic syllables together (tailoring of UAX #29) - // Known limitation: this is overly conservative, and assumes that the virama may form a - // conjunct with the following letter, which doesn't always happen. - // - // There is no easy solution to do this correctly. Even querying the font does not help (with - // the current font technoloies), since the font may be creating the conjunct using multiple - // glyphs, while the user may be perceiving that sequence of glyphs as one conjunct or one - // letter. + // Cluster Indic syllables together (tailoring of UAX #29). + // Immediately after each virama (that is not just a pure killer) followed by a letter, we + // check to see if the next character has a non-zero width assigned to it in the advances + // array. A zero width means a cluster is formed with the virama (so there is no grapheme + // break), while a non-zero width means a new cluster is started (so there may be a grapheme + // break). if (u_getIntPropertyValue(c1, UCHAR_CANONICAL_COMBINING_CLASS) == 9 // virama && !isPureKiller(c1) - && u_getIntPropertyValue(c2, UCHAR_GENERAL_CATEGORY) == U_OTHER_LETTER) { + && u_getIntPropertyValue(c2, UCHAR_GENERAL_CATEGORY) == U_OTHER_LETTER + && (advances == nullptr || advances[offset - start] == 0)) { return false; } // Tailoring: make emoji sequences with ZWJ a single grapheme cluster @@ -170,8 +169,8 @@ bool GraphemeBreak::isGraphemeBreak(const uint16_t* buf, size_t start, size_t co return true; } -size_t GraphemeBreak::getTextRunCursor(const uint16_t* buf, size_t start, size_t count, - size_t offset, MoveOpt opt) { +size_t GraphemeBreak::getTextRunCursor(const float* advances, const uint16_t* buf, size_t start, + size_t count, size_t offset, MoveOpt opt) { switch (opt) { case AFTER: if (offset < start + count) { @@ -179,7 +178,7 @@ size_t GraphemeBreak::getTextRunCursor(const uint16_t* buf, size_t start, size_t } // fall through case AT_OR_AFTER: - while (!isGraphemeBreak(buf, start, count, offset)) { + while (!isGraphemeBreak(advances, buf, start, count, offset)) { offset++; } break; @@ -189,12 +188,12 @@ size_t GraphemeBreak::getTextRunCursor(const uint16_t* buf, size_t start, size_t } // fall through case AT_OR_BEFORE: - while (!isGraphemeBreak(buf, start, count, offset)) { + while (!isGraphemeBreak(advances, buf, start, count, offset)) { offset--; } break; case AT: - if (!isGraphemeBreak(buf, start, count, offset)) { + if (!isGraphemeBreak(advances, buf, start, count, offset)) { offset = (size_t)-1; } break; diff --git a/engine/src/flutter/libs/minikin/Measurement.cpp b/engine/src/flutter/libs/minikin/Measurement.cpp index 0ed7a670bfd..f0d15f24e80 100644 --- a/engine/src/flutter/libs/minikin/Measurement.cpp +++ b/engine/src/flutter/libs/minikin/Measurement.cpp @@ -54,7 +54,8 @@ static float getRunAdvance(const float* advances, const uint16_t* buf, size_t la int numGraphemeClustersAfter = 0; for (size_t i = lastCluster; i < nextCluster; i++) { bool isAfter = i >= offset; - if (GraphemeBreak::isGraphemeBreak(buf, start, count, i)) { + if (GraphemeBreak::isGraphemeBreak( + advances + (start - layoutStart), buf, start, count, i)) { numGraphemeClusters++; if (isAfter) { numGraphemeClustersAfter++; @@ -86,7 +87,7 @@ size_t getOffsetForAdvance(const float* advances, const uint16_t* buf, size_t st float x = 0.0f, xLastClusterStart = 0.0f, xSearchStart = 0.0f; size_t lastClusterStart = start, searchStart = start; for (size_t i = start; i < start + count; i++) { - if (GraphemeBreak::isGraphemeBreak(buf, start, count, i)) { + if (GraphemeBreak::isGraphemeBreak(advances, buf, start, count, i)) { searchStart = lastClusterStart; xSearchStart = xLastClusterStart; } @@ -103,7 +104,7 @@ size_t getOffsetForAdvance(const float* advances, const uint16_t* buf, size_t st size_t best = searchStart; float bestDist = FLT_MAX; for (size_t i = searchStart; i <= start + count; i++) { - if (GraphemeBreak::isGraphemeBreak(buf, start, count, i)) { + if (GraphemeBreak::isGraphemeBreak(advances, buf, start, count, i)) { // "getRunAdvance(layout, buf, start, count, i) - advance" but more efficient float delta = getRunAdvance(advances, buf, start, searchStart, count - searchStart, i) diff --git a/engine/src/flutter/tests/perftests/GraphemeBreak.cpp b/engine/src/flutter/tests/perftests/GraphemeBreak.cpp index cfee7c642c1..6d6cf5b1783 100644 --- a/engine/src/flutter/tests/perftests/GraphemeBreak.cpp +++ b/engine/src/flutter/tests/perftests/GraphemeBreak.cpp @@ -38,7 +38,7 @@ static void BM_GraphemeBreak_Ascii(benchmark::State& state) { LOG_ALWAYS_FATAL_IF(result_size != 12); const size_t testIndex = state.range(0); while (state.KeepRunning()) { - GraphemeBreak::isGraphemeBreak(buffer, 0, result_size, testIndex); + GraphemeBreak::isGraphemeBreak(nullptr, buffer, 0, result_size, testIndex); } } BENCHMARK(BM_GraphemeBreak_Ascii) @@ -53,7 +53,7 @@ static void BM_GraphemeBreak_Emoji(benchmark::State& state) { LOG_ALWAYS_FATAL_IF(result_size != 12); const size_t testIndex = state.range(0); while (state.KeepRunning()) { - GraphemeBreak::isGraphemeBreak(buffer, 0, result_size, testIndex); + GraphemeBreak::isGraphemeBreak(nullptr, buffer, 0, result_size, testIndex); } } BENCHMARK(BM_GraphemeBreak_Emoji) @@ -68,7 +68,7 @@ static void BM_GraphemeBreak_Emoji_Flags(benchmark::State& state) { LOG_ALWAYS_FATAL_IF(result_size != 12); const size_t testIndex = state.range(0); while (state.KeepRunning()) { - GraphemeBreak::isGraphemeBreak(buffer, 0, result_size, testIndex); + GraphemeBreak::isGraphemeBreak(nullptr, buffer, 0, result_size, testIndex); } } BENCHMARK(BM_GraphemeBreak_Emoji_Flags) diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index fdcc0c4e472..716fcc378d8 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -76,6 +76,7 @@ LOCAL_SRC_FILES += \ GraphemeBreakTests.cpp \ LayoutTest.cpp \ LayoutUtilsTest.cpp \ + MeasurementTests.cpp \ SparseBitSetTest.cpp \ UnicodeUtilsTest.cpp \ WordBreakerTests.cpp diff --git a/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp b/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp index 29b1669bd41..96bd8a8e79f 100644 --- a/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp +++ b/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp @@ -26,7 +26,16 @@ bool IsBreak(const char* src) { size_t offset; size_t size; ParseUnicode(buf, BUF_SIZE, src, &size, &offset); - return GraphemeBreak::isGraphemeBreak(buf, 0, size, offset); + return GraphemeBreak::isGraphemeBreak(nullptr, buf, 0, size, offset); +} + +bool IsBreakWithAdvances(const float* advances, const char* src) { + const size_t BUF_SIZE = 256; + uint16_t buf[BUF_SIZE]; + size_t offset; + size_t size; + ParseUnicode(buf, BUF_SIZE, src, &size, &offset); + return GraphemeBreak::isGraphemeBreak(advances, buf, 0, size, offset); } TEST(GraphemeBreak, utf16) { @@ -164,6 +173,31 @@ TEST(GraphemeBreak, tailoring) { EXPECT_FALSE(IsBreak("U+0E01 | U+0E3A U+0E01")); // thai phinthu = pure killer EXPECT_TRUE(IsBreak("U+0E01 U+0E3A | U+0E01")); // thai phinthu = pure killer + // Repetition of above tests, but with a given advances array that implies everything + // became just one cluster. + const float conjoined[] = {1.0, 0.0, 0.0}; + EXPECT_FALSE(IsBreakWithAdvances(conjoined, + "U+0915 | U+094D U+0915")); // Devanagari ka+virama+ka + EXPECT_FALSE(IsBreakWithAdvances(conjoined, + "U+0915 U+094D | U+0915")); // Devanagari ka+virama+ka + EXPECT_FALSE(IsBreakWithAdvances(conjoined, + "U+0E01 | U+0E3A U+0E01")); // thai phinthu = pure killer + EXPECT_TRUE(IsBreakWithAdvances(conjoined, + "U+0E01 U+0E3A | U+0E01")); // thai phinthu = pure killer + + // Repetition of above tests, but with a given advances array that the virama did not + // form a cluster with the following consonant. The difference is that there is now + // a grapheme break after the virama in ka+virama+ka. + const float separate[] = {1.0, 0.0, 1.0}; + EXPECT_FALSE(IsBreakWithAdvances(separate, + "U+0915 | U+094D U+0915")); // Devanagari ka+virama+ka + EXPECT_TRUE(IsBreakWithAdvances(separate, + "U+0915 U+094D | U+0915")); // Devanagari ka+virama+ka + EXPECT_FALSE(IsBreakWithAdvances(separate, + "U+0E01 | U+0E3A U+0E01")); // thai phinthu = pure killer + EXPECT_TRUE(IsBreakWithAdvances(separate, + "U+0E01 U+0E3A | U+0E01")); // thai phinthu = pure killer + // suppress grapheme breaks in zwj emoji sequences, see // http://www.unicode.org/emoji/charts/emoji-zwj-sequences.html EXPECT_FALSE(IsBreak("U+1F469 U+200D | U+2764 U+FE0F U+200D U+1F48B U+200D U+1F468")); @@ -222,10 +256,10 @@ TEST(GraphemeBreak, genderBalancedEmoji) { TEST(GraphemeBreak, offsets) { uint16_t string[] = { 0x0041, 0x06DD, 0x0045, 0x0301, 0x0049, 0x0301 }; - EXPECT_TRUE(GraphemeBreak::isGraphemeBreak(string, 2, 3, 2)); - EXPECT_FALSE(GraphemeBreak::isGraphemeBreak(string, 2, 3, 3)); - EXPECT_TRUE(GraphemeBreak::isGraphemeBreak(string, 2, 3, 4)); - EXPECT_TRUE(GraphemeBreak::isGraphemeBreak(string, 2, 3, 5)); + EXPECT_TRUE(GraphemeBreak::isGraphemeBreak(nullptr, string, 2, 3, 2)); + EXPECT_FALSE(GraphemeBreak::isGraphemeBreak(nullptr, string, 2, 3, 3)); + EXPECT_TRUE(GraphemeBreak::isGraphemeBreak(nullptr, string, 2, 3, 4)); + EXPECT_TRUE(GraphemeBreak::isGraphemeBreak(nullptr, string, 2, 3, 5)); } } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/MeasurementTests.cpp b/engine/src/flutter/tests/unittest/MeasurementTests.cpp new file mode 100644 index 00000000000..7fedecb5ea2 --- /dev/null +++ b/engine/src/flutter/tests/unittest/MeasurementTests.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2017 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 +#include +#include + +namespace minikin { + +float getAdvance(const float* advances, const char* src) { + const size_t BUF_SIZE = 256; + uint16_t buf[BUF_SIZE]; + size_t offset; + size_t size; + ParseUnicode(buf, BUF_SIZE, src, &size, &offset); + return getRunAdvance(advances, buf, 0, size, offset); +} + +// Latin fi +TEST(Measurement, getRunAdvance_fi) { + const float unligated[] = {30.0, 20.0}; + EXPECT_EQ(0.0, getAdvance(unligated, "| 'f' 'i'")); + EXPECT_EQ(30.0, getAdvance(unligated, "'f' | 'i'")); + EXPECT_EQ(50.0, getAdvance(unligated, "'f' 'i' |")); + + const float ligated[] = {40.0, 0.0}; + EXPECT_EQ(0.0, getAdvance(ligated, "| 'f' 'i'")); + EXPECT_EQ(20.0, getAdvance(ligated, "'f' | 'i'")); + EXPECT_EQ(40.0, getAdvance(ligated, "'f' 'i' |")); +} + +// Devanagari ka+virama+ka +TEST(Measurement, getRunAdvance_kka) { + const float unligated[] = {30.0, 0.0, 30.0}; + EXPECT_EQ(0.0, getAdvance(unligated, "| U+0915 U+094D U+0915")); + EXPECT_EQ(30.0, getAdvance(unligated, "U+0915 | U+094D U+0915")); + EXPECT_EQ(30.0, getAdvance(unligated, "U+0915 U+094D | U+0915")); + EXPECT_EQ(60.0, getAdvance(unligated, "U+0915 U+094D U+0915 |")); + + const float ligated[] = {30.0, 0.0, 0.0}; + EXPECT_EQ(0.0, getAdvance(ligated, "| U+0915 U+094D U+0915")); + EXPECT_EQ(30.0, getAdvance(ligated, "U+0915 | U+094D U+0915")); + EXPECT_EQ(30.0, getAdvance(ligated, "U+0915 U+094D | U+0915")); + EXPECT_EQ(30.0, getAdvance(ligated, "U+0915 U+094D U+0915 |")); +} + +} // namespace minikin From 8d9c9d7f20e621e6e49f9252128ab8a5d890c67d Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 9 Mar 2017 15:16:16 -0800 Subject: [PATCH 245/364] Expose supportedAxes to frameworks/base The list of supportedAxes are necessary for returning value of setFontVariationSettings. Bug: 35764323 Test: ran TextViewTest and PaintTest in cts Change-Id: I52f244146ea0ce335df02c841f89285be2ed746e --- engine/src/flutter/include/minikin/FontCollection.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/engine/src/flutter/include/minikin/FontCollection.h b/engine/src/flutter/include/minikin/FontCollection.h index 23645387997..545d43db802 100644 --- a/engine/src/flutter/include/minikin/FontCollection.h +++ b/engine/src/flutter/include/minikin/FontCollection.h @@ -53,6 +53,10 @@ public: std::shared_ptr createCollectionWithVariation(const std::vector& variations); + const std::unordered_set& getSupportedTags() const { + return mSupportedAxes; + } + uint32_t getId() const; private: From 3165aebe3bb0afb5f4197ad7955c67ef55c749b1 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 14 Mar 2017 15:34:06 -0700 Subject: [PATCH 246/364] Do not keep FontCollection reference in Layout. LayoutCache only keeps result of layout and can live after FontCollection is destructed by GC. This kind of failure will be captured by minikin_stress_tests in the subsequent CL (I1bf4ba43e6e97cd04e7d6dd42d388dd17ce64c7b) Test: ran minikin_tests Bug: 36223724 Change-Id: I639b73c0f1041549158c43212a901c82df4b02db --- engine/src/flutter/include/minikin/Layout.h | 9 ++- engine/src/flutter/libs/minikin/Layout.cpp | 22 +++--- .../src/flutter/tests/unittest/LayoutTest.cpp | 69 ++++++++++++------- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index e9849c382c3..8a6e7725d0a 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -75,8 +75,7 @@ enum { class Layout { public: - Layout(const std::shared_ptr& collection) - : mGlyphs(), mAdvances(), mCollection(collection), mFaces(), mAdvance(0), mBounds() { + Layout() : mGlyphs(), mAdvances(), mFaces(), mAdvance(0), mBounds() { mBounds.setEmpty(); } @@ -89,7 +88,8 @@ public: void dump() const; void doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - int bidiFlags, const FontStyle &style, const MinikinPaint &paint); + int bidiFlags, const FontStyle &style, const MinikinPaint &paint, + const std::shared_ptr& collection); static float measureText(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint, @@ -143,7 +143,7 @@ private: // Lay out a single bidi run void doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - bool isRtl, LayoutContext* ctx); + bool isRtl, LayoutContext* ctx, const std::shared_ptr& collection); // Append another layout (for example, cached value) into this one void appendLayout(Layout* src, size_t start, float extraAdvance); @@ -151,7 +151,6 @@ private: std::vector mGlyphs; std::vector mAdvances; - std::shared_ptr mCollection; std::vector mFaces; float mAdvance; MinikinRect mBounds; diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 743cb763aea..4032d4c9432 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -131,10 +131,11 @@ public: mChars = NULL; } - void doLayout(Layout* layout, LayoutContext* ctx) const { + void doLayout(Layout* layout, LayoutContext* ctx, + const std::shared_ptr& collection) const { layout->mAdvances.resize(mCount, 0); ctx->clearHbFonts(); - layout->doLayoutRun(mChars, mStart, mCount, mNchars, mIsRtl, ctx); + layout->doLayoutRun(mChars, mStart, mCount, mNchars, mIsRtl, ctx, collection); } private: @@ -173,8 +174,8 @@ public: Layout* layout = mCache.get(key); if (layout == NULL) { key.copyText(); - layout = new Layout(collection); - key.doLayout(layout, ctx); + layout = new Layout(); + key.doLayout(layout, ctx, collection); mCache.put(key, layout); } return layout; @@ -584,7 +585,8 @@ BidiText::BidiText(const uint16_t* buf, size_t start, size_t count, size_t bufSi } void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - int bidiFlags, const FontStyle &style, const MinikinPaint &paint) { + int bidiFlags, const FontStyle &style, const MinikinPaint &paint, + const std::shared_ptr& collection) { android::AutoMutex _l(gMinikinLock); LayoutContext ctx; @@ -596,7 +598,7 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu for (const BidiText::Iter::RunInfo& runInfo : BidiText(buf, start, count, bufSize, bidiFlags)) { doLayoutRunCached(buf, runInfo.mRunStart, runInfo.mRunLength, bufSize, runInfo.mIsRtl, &ctx, - start, mCollection, this, NULL); + start, collection, this, NULL); } ctx.clearHbFonts(); } @@ -684,8 +686,8 @@ float Layout::doLayoutWord(const uint16_t* buf, size_t start, size_t count, size float advance; if (ctx->paint.skipCache()) { - Layout layoutForWord(collection); - key.doLayout(&layoutForWord, ctx); + Layout layoutForWord; + key.doLayout(&layoutForWord, ctx, collection); if (layout) { layout->appendLayout(&layoutForWord, bufStart, wordSpacing); } @@ -863,10 +865,10 @@ static inline uint32_t addToHbBuffer(hb_buffer_t* buffer, void Layout::doLayoutRun(const uint16_t* buf, size_t start, size_t count, size_t bufSize, - bool isRtl, LayoutContext* ctx) { + bool isRtl, LayoutContext* ctx, const std::shared_ptr& collection) { hb_buffer_t* buffer = LayoutEngine::getInstance().hbBuffer; vector items; - mCollection->itemize(buf + start, count, ctx->style, &items); + collection->itemize(buf + start, count, ctx->style, &items); vector features; // Disable default-on non-required ligature features if letter-spacing diff --git a/engine/src/flutter/tests/unittest/LayoutTest.cpp b/engine/src/flutter/tests/unittest/LayoutTest.cpp index ed41ca45742..1770d3ac5e2 100644 --- a/engine/src/flutter/tests/unittest/LayoutTest.cpp +++ b/engine/src/flutter/tests/unittest/LayoutTest.cpp @@ -70,14 +70,15 @@ TEST_F(LayoutTest, doLayoutTest) { float advances[kMaxAdvanceLength]; std::vector expectedValues; - Layout layout(mCollection); + Layout layout; std::vector text; // The mock implementation returns 10.0f advance and 0,0-10x10 bounds for all glyph. { SCOPED_TRACE("one word"); text = utf8ToUtf16("oneword"); - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(70.0f, layout.getAdvance()); layout.getBounds(&rect); EXPECT_EQ(0.0f, rect.mLeft); @@ -95,7 +96,8 @@ TEST_F(LayoutTest, doLayoutTest) { { SCOPED_TRACE("two words"); text = utf8ToUtf16("two words"); - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(90.0f, layout.getAdvance()); layout.getBounds(&rect); EXPECT_EQ(0.0f, rect.mLeft); @@ -113,7 +115,8 @@ TEST_F(LayoutTest, doLayoutTest) { { SCOPED_TRACE("three words"); text = utf8ToUtf16("three words test"); - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(160.0f, layout.getAdvance()); layout.getBounds(&rect); EXPECT_EQ(0.0f, rect.mLeft); @@ -131,7 +134,8 @@ TEST_F(LayoutTest, doLayoutTest) { { SCOPED_TRACE("two spaces"); text = utf8ToUtf16("two spaces"); - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(110.0f, layout.getAdvance()); layout.getBounds(&rect); EXPECT_EQ(0.0f, rect.mLeft); @@ -156,7 +160,7 @@ TEST_F(LayoutTest, doLayoutTest_wordSpacing) { std::vector expectedValues; std::vector text; - Layout layout(mCollection); + Layout layout; paint.wordSpacing = 5.0f; @@ -164,7 +168,8 @@ TEST_F(LayoutTest, doLayoutTest_wordSpacing) { { SCOPED_TRACE("one word"); text = utf8ToUtf16("oneword"); - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(70.0f, layout.getAdvance()); layout.getBounds(&rect); EXPECT_EQ(0.0f, rect.mLeft); @@ -182,7 +187,8 @@ TEST_F(LayoutTest, doLayoutTest_wordSpacing) { { SCOPED_TRACE("two words"); text = utf8ToUtf16("two words"); - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(95.0f, layout.getAdvance()); layout.getBounds(&rect); EXPECT_EQ(0.0f, rect.mLeft); @@ -204,7 +210,8 @@ TEST_F(LayoutTest, doLayoutTest_wordSpacing) { { SCOPED_TRACE("three words test"); text = utf8ToUtf16("three words test"); - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(170.0f, layout.getAdvance()); layout.getBounds(&rect); EXPECT_EQ(0.0f, rect.mLeft); @@ -224,7 +231,8 @@ TEST_F(LayoutTest, doLayoutTest_wordSpacing) { { SCOPED_TRACE("two spaces"); text = utf8ToUtf16("two spaces"); - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(120.0f, layout.getAdvance()); layout.getBounds(&rect); EXPECT_EQ(0.0f, rect.mLeft); @@ -250,7 +258,7 @@ TEST_F(LayoutTest, doLayoutTest_negativeWordSpacing) { float advances[kMaxAdvanceLength]; std::vector expectedValues; - Layout layout(mCollection); + Layout layout; std::vector text; // Negative word spacing also should work. @@ -259,7 +267,8 @@ TEST_F(LayoutTest, doLayoutTest_negativeWordSpacing) { { SCOPED_TRACE("one word"); text = utf8ToUtf16("oneword"); - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(70.0f, layout.getAdvance()); layout.getBounds(&rect); EXPECT_EQ(0.0f, rect.mLeft); @@ -277,7 +286,8 @@ TEST_F(LayoutTest, doLayoutTest_negativeWordSpacing) { { SCOPED_TRACE("two words"); text = utf8ToUtf16("two words"); - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(85.0f, layout.getAdvance()); layout.getBounds(&rect); EXPECT_EQ(0.0f, rect.mLeft); @@ -296,7 +306,8 @@ TEST_F(LayoutTest, doLayoutTest_negativeWordSpacing) { { SCOPED_TRACE("three words"); text = utf8ToUtf16("three word test"); - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(140.0f, layout.getAdvance()); layout.getBounds(&rect); EXPECT_EQ(0.0f, rect.mLeft); @@ -316,7 +327,8 @@ TEST_F(LayoutTest, doLayoutTest_negativeWordSpacing) { { SCOPED_TRACE("two spaces"); text = utf8ToUtf16("two spaces"); - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(100.0f, layout.getAdvance()); layout.getBounds(&rect); EXPECT_EQ(0.0f, rect.mLeft); @@ -340,11 +352,13 @@ TEST_F(LayoutTest, doLayoutTest_rtlTest) { std::vector text = parseUnicodeString("'a' 'b' U+3042 U+3043 'c' 'd'"); - Layout ltrLayout(mCollection); - ltrLayout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + Layout ltrLayout; + ltrLayout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); - Layout rtlLayout(mCollection); - rtlLayout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_RTL, FontStyle(), paint); + Layout rtlLayout; + rtlLayout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_RTL, FontStyle(), paint, + mCollection); ASSERT_EQ(ltrLayout.nGlyphs(), rtlLayout.nGlyphs()); ASSERT_EQ(6u, ltrLayout.nGlyphs()); @@ -357,7 +371,7 @@ TEST_F(LayoutTest, doLayoutTest_rtlTest) { } TEST_F(LayoutTest, hyphenationTest) { - Layout layout(mCollection); + Layout layout; std::vector text; // The mock implementation returns 10.0f advance for all glyphs. @@ -366,7 +380,8 @@ TEST_F(LayoutTest, hyphenationTest) { text = utf8ToUtf16("oneword"); MinikinPaint paint; paint.hyphenEdit = HyphenEdit::NO_EDIT; - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(70.0f, layout.getAdvance()); } { @@ -374,7 +389,8 @@ TEST_F(LayoutTest, hyphenationTest) { text = utf8ToUtf16("oneword"); MinikinPaint paint; paint.hyphenEdit = HyphenEdit::INSERT_HYPHEN_AT_END; - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(80.0f, layout.getAdvance()); } { @@ -382,7 +398,8 @@ TEST_F(LayoutTest, hyphenationTest) { text = utf8ToUtf16("oneword"); MinikinPaint paint; paint.hyphenEdit = HyphenEdit::REPLACE_WITH_HYPHEN_AT_END; - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(70.0f, layout.getAdvance()); } { @@ -390,7 +407,8 @@ TEST_F(LayoutTest, hyphenationTest) { text = utf8ToUtf16("oneword"); MinikinPaint paint; paint.hyphenEdit = HyphenEdit::INSERT_HYPHEN_AT_START; - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(80.0f, layout.getAdvance()); } { @@ -398,7 +416,8 @@ TEST_F(LayoutTest, hyphenationTest) { text = utf8ToUtf16("oneword"); MinikinPaint paint; paint.hyphenEdit = HyphenEdit::INSERT_HYPHEN_AT_START | HyphenEdit::INSERT_HYPHEN_AT_END; - layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), paint, + mCollection); EXPECT_EQ(90.0f, layout.getAdvance()); } } From d2aaf3394aaf2f6c77f3b083c1621495673a4287 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Tue, 14 Mar 2017 14:59:58 -0700 Subject: [PATCH 247/364] In greedy line breaking, repeat breaks until the line fits Previously, in greedy line breaking, when a line overflowed, we found the best line breaking candidate before it and broke the line there. But we didn't check to see if the remaining part now fits in a line. With this change, we now repeat checking for overflows, and break again until we have no breaking opportunity or the remaining text now fits in a line. Also found an issue with greedy line breaking and keeping the hyphenation edit for the next line which is now fixed. Test: Manual. The issue reported in the bug is now fixed. Bug: 34185255 Bug: https://code.google.com/p/android/issues/detail?id=231437 Bug: 33560754 Change-Id: I93bdd341e4f8e1257710e453e4938f224cb2a1ff --- .../src/flutter/include/minikin/LineBreaker.h | 6 +- .../src/flutter/libs/minikin/LineBreaker.cpp | 56 +++++++++++++++---- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index ce8eb7d571a..c91c0b3da7f 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -191,8 +191,8 @@ class LineBreaker { struct Candidate { size_t offset; // offset to text buffer, in code units size_t prev; // index to previous break - ParaWidth preBreak; - ParaWidth postBreak; + ParaWidth preBreak; // width of text until this point, if we decide to not break here + ParaWidth postBreak; // width of text until this point, if we decide to break here float penalty; // penalty of this break (for example, hyphen penalty) float score; // best score found for this break size_t lineNumber; // only updated for non-constant line widths @@ -207,6 +207,7 @@ class LineBreaker { size_t preSpaceCount, size_t postSpaceCount, float penalty, HyphenationType hyph); void addCandidate(Candidate cand); + void pushGreedyBreak(); // push an actual break to the output. Takes care of setting flags for tab void pushBreak(int offset, float width, uint8_t hyphenEdit); @@ -248,6 +249,7 @@ class LineBreaker { size_t mBestBreak; float mBestScore; ParaWidth mPreBreak; // prebreak of last break + uint32_t mLastHyphenation; // hyphen edit of last break kept for next line int mFirstTabIndex; size_t mSpaceCount; }; diff --git a/engine/src/flutter/libs/minikin/LineBreaker.cpp b/engine/src/flutter/libs/minikin/LineBreaker.cpp index b8814b63d45..e75c7bf5238 100644 --- a/engine/src/flutter/libs/minikin/LineBreaker.cpp +++ b/engine/src/flutter/libs/minikin/LineBreaker.cpp @@ -84,6 +84,7 @@ void LineBreaker::setText() { mBestBreak = 0; mBestScore = SCORE_INFTY; mPreBreak = 0; + mLastHyphenation = HyphenEdit::NO_EDIT; mFirstTabIndex = INT_MAX; mSpaceCount = 0; } @@ -269,24 +270,59 @@ void LineBreaker::addWordBreak(size_t offset, ParaWidth preBreak, ParaWidth post addCandidate(cand); } +// Helper method for addCandidate() +void LineBreaker::pushGreedyBreak() { + const Candidate& bestCandidate = mCandidates[mBestBreak]; + pushBreak(bestCandidate.offset, bestCandidate.postBreak - mPreBreak, + mLastHyphenation | HyphenEdit::editForThisLine(bestCandidate.hyphenType)); + mBestScore = SCORE_INFTY; +#if VERBOSE_DEBUG + ALOGD("break: %d %g", mBreaks.back(), mWidths.back()); +#endif + mLastBreak = mBestBreak; + mPreBreak = bestCandidate.preBreak; + mLastHyphenation = HyphenEdit::editForNextLine(bestCandidate.hyphenType); +} + // TODO performance: could avoid populating mCandidates if greedy only void LineBreaker::addCandidate(Candidate cand) { - size_t candIndex = mCandidates.size(); + const size_t candIndex = mCandidates.size(); mCandidates.push_back(cand); + + // mLastBreak is the index of the last line break we decided to do in mCandidates, + // and mPreBreak is its preBreak value. mBestBreak is the index of the best line breaking candidate + // we have found since then, and mBestScore is its penalty. if (cand.postBreak - mPreBreak > currentLineWidth()) { // This break would create an overfull line, pick the best break and break there (greedy) if (mBestBreak == mLastBreak) { + // No good break has been found since last break. Break here. mBestBreak = candIndex; } - pushBreak(mCandidates[mBestBreak].offset, mCandidates[mBestBreak].postBreak - mPreBreak, - HyphenEdit::editForThisLine(mCandidates[mBestBreak].hyphenType)); - mBestScore = SCORE_INFTY; -#if VERBOSE_DEBUG - ALOGD("break: %d %g", mBreaks.back(), mWidths.back()); -#endif - mLastBreak = mBestBreak; - mPreBreak = mCandidates[mBestBreak].preBreak; + pushGreedyBreak(); } + + while (mLastBreak != candIndex && cand.postBreak - mPreBreak > currentLineWidth()) { + // We should rarely come here. But if we are here, we have broken the line, but the + // remaining part still doesn't fit. We now need to break at the second best place after the + // last break, but we have not kept that information, so we need to go back and find it. + // + // In some really rare cases, postBreak - preBreak of a candidate itself may be over the + // current line width. We protect ourselves against an infinite loop in that case by + // checking that we have not broken the line at this candidate already. + for (size_t i = mLastBreak + 1; i < candIndex; i++) { + const float penalty = mCandidates[i].penalty; + if (penalty <= mBestScore) { + mBestBreak = i; + mBestScore = penalty; + } + } + if (mBestBreak == mLastBreak) { + // We didn't find anything good. Break here. + mBestBreak = candIndex; + } + pushGreedyBreak(); + } + if (cand.penalty <= mBestScore) { mBestBreak = candIndex; mBestScore = cand.penalty; @@ -329,7 +365,7 @@ void LineBreaker::computeBreaksGreedy() { size_t nCand = mCandidates.size(); if (nCand == 1 || mLastBreak != nCand - 1) { pushBreak(mCandidates[nCand - 1].offset, mCandidates[nCand - 1].postBreak - mPreBreak, - HyphenEdit::NO_EDIT); + mLastHyphenation); // don't need to update mBestScore, because we're done #if VERBOSE_DEBUG ALOGD("final break: %d %g", mBreaks.back(), mWidths.back()); From aae6468815e9c1ee279d07853b8e11ac715d38c0 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 15 Mar 2017 14:13:58 -0700 Subject: [PATCH 248/364] Fallback from script-specific hyphens to normal hyphen first The previous code fell back directly from a script-specific hyphen to the ASCII hyphen-minus if the font didn't support the script-specific hyphen. Now we try the Unicode hyphen (U+2010) first before trying the ASCII hyphen-minus. Bug: 36201363 Test: Not needed Change-Id: I374234fd73fab7edd990ea86f8937c38761c90bf --- engine/src/flutter/libs/minikin/Layout.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 4032d4c9432..0a318bdccd7 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -736,12 +736,22 @@ static void addFeatures(const string &str, vector* features) { } } +static const hb_codepoint_t CHAR_HYPHEN = 0x2010; /* HYPHEN */ + static inline hb_codepoint_t determineHyphenChar(hb_codepoint_t preferredHyphen, hb_font_t* font) { - if (preferredHyphen == 0x2010 /* HYPHEN */ - || preferredHyphen == 0x058A /* ARMENIAN_HYPHEN */ + hb_codepoint_t glyph; + if (preferredHyphen == 0x058A /* ARMENIAN_HYPHEN */ || preferredHyphen == 0x05BE /* HEBREW PUNCTUATION MAQAF */ || preferredHyphen == 0x1400 /* CANADIAN SYLLABIC HYPHEN */) { - hb_codepoint_t glyph; + if (hb_font_get_nominal_glyph(font, preferredHyphen, &glyph)) { + return preferredHyphen; + } else { + // The original hyphen requested was not supported. Let's try and see if the + // Unicode hyphen is supported. + preferredHyphen = CHAR_HYPHEN; + } + } + if (preferredHyphen == CHAR_HYPHEN) { /* HYPHEN */ // Fallback to ASCII HYPHEN-MINUS if the font didn't have a glyph for the preferred hyphen. // Note that we intentionally don't do anything special if the font doesn't have a // HYPHEN-MINUS either, so a tofu could be shown, hinting towards something missing. From ca8ac8a9249979e0c5b46463195e1c61b2186ac8 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 14 Mar 2017 17:57:28 -0700 Subject: [PATCH 249/364] Serialize and deserialize supported axes. To avoid reading font files during FontFamily construction, serialize and deserialize supported axes and cmap coverage at the same time. Bug: 36232655 Test: ran minikin_tests Change-Id: I4086fb887e13f872390b533584bce6f1d5598ea0 --- .../src/flutter/include/minikin/FontFamily.h | 10 +++- .../src/flutter/libs/minikin/FontFamily.cpp | 57 +++++++++++++++---- .../flutter/tests/unittest/FontFamilyTest.cpp | 46 +++++++++++++++ 3 files changed, 99 insertions(+), 14 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 4186c2baabb..18a75ee8ec0 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -110,10 +110,8 @@ struct Font { std::shared_ptr typeface; FontStyle style; - std::unordered_set supportedAxes; -private: - void loadAxes(); + std::unordered_set getSupportedAxesLocked() const; }; struct FontVariation { @@ -181,6 +179,12 @@ private: void computeCoverage(); void readAcceleratorTable(const uint8_t* data, size_t size); + size_t writeSupportedAxes(uint8_t* out) const; + + // Reads supported axes values from 'in' buffer. This method reads up to + // 'inSize' bytes and returns the number of bytes read. + size_t readSupportedAxes(const uint8_t* in, size_t inSize); + uint32_t mLangId; int mVariant; std::vector mFonts; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 4097e8fb239..076dff2bcc9 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -67,36 +67,33 @@ uint32_t FontStyle::pack(int variant, int weight, bool italic) { Font::Font(const std::shared_ptr& typeface, FontStyle style) : typeface(typeface), style(style) { - loadAxes(); } Font::Font(std::shared_ptr&& typeface, FontStyle style) : typeface(typeface), style(style) { - loadAxes(); } -void Font::loadAxes() { - android::AutoMutex _l(gMinikinLock); +std::unordered_set Font::getSupportedAxesLocked() const { const uint32_t fvarTag = MinikinFont::MakeTag('f', 'v', 'a', 'r'); HbBlob fvarTable(getFontTable(typeface.get(), fvarTag)); if (fvarTable.size() == 0) { - return; + return std::unordered_set(); } + std::unordered_set supportedAxes; analyzeAxes(fvarTable.get(), fvarTable.size(), &supportedAxes); + return supportedAxes; } Font::Font(Font&& o) { typeface = std::move(o.typeface); style = o.style; o.typeface = nullptr; - supportedAxes = std::move(o.supportedAxes); } Font::Font(const Font& o) { typeface = o.typeface; style = o.style; - supportedAxes = o.supportedAxes; } // static @@ -201,7 +198,8 @@ void FontFamily::computeCoverage() { CmapCoverage::getCoverage(mCoverage, cmapTable.get(), cmapTable.size(), &mHasVSTable); for (size_t i = 0; i < mFonts.size(); ++i) { - mSupportedAxes.insert(mFonts[i].supportedAxes.begin(), mFonts[i].supportedAxes.end()); + std::unordered_set supportedAxes = mFonts[i].getSupportedAxesLocked(); + mSupportedAxes.insert(supportedAxes.begin(), supportedAxes.end()); } } @@ -242,9 +240,11 @@ std::shared_ptr FontFamily::createFamilyWithVariation( std::vector fonts; for (const Font& font : mFonts) { bool supportedVariations = false; - if (!font.supportedAxes.empty()) { + android::AutoMutex _l(gMinikinLock); + std::unordered_set supportedAxes = font.getSupportedAxesLocked(); + if (!supportedAxes.empty()) { for (const FontVariation& variation : variations) { - if (font.supportedAxes.find(variation.axisTag) != font.supportedAxes.end()) { + if (supportedAxes.find(variation.axisTag) != supportedAxes.end()) { supportedVariations = true; break; } @@ -264,11 +264,46 @@ std::shared_ptr FontFamily::createFamilyWithVariation( } size_t FontFamily::writeAcceleratorTable(uint8_t* out) const { - return mCoverage.writeToBuffer(out); + const size_t axesTableSize = writeSupportedAxes(out); + if (out != nullptr) { + out += axesTableSize; + } + const size_t coverageTableSize = mCoverage.writeToBuffer(out); + return axesTableSize + coverageTableSize; } void FontFamily::readAcceleratorTable(const uint8_t* data, size_t size) { + const size_t readSize = readSupportedAxes(data, size); + data += readSize; + size -= readSize; bool result = mCoverage.initFromBuffer(data, size); LOG_ALWAYS_FATAL_IF(!result, "Failed to reconstruct accelerator table from buffer"); } + +size_t FontFamily::writeSupportedAxes(uint8_t* out) const { + LOG_ALWAYS_FATAL_IF(mSupportedAxes.size() > 255, "System fonts may only use up to 255 axes."); + const uint8_t axesCount = static_cast(mSupportedAxes.size()); + if (out != nullptr) { + out[0] = axesCount; + AxisTag* axisTags = reinterpret_cast(out + 1); + for (const auto& tag : mSupportedAxes) { + *axisTags++ = tag; + } + } + const size_t axesSizeInbytes = sizeof(AxisTag) * axesCount; + return axesSizeInbytes + 1 /* 1 for axes count */; +} + +size_t FontFamily::readSupportedAxes(const uint8_t* in, size_t inSize) { + LOG_ALWAYS_FATAL_IF(inSize == 0); + const uint8_t axesCount = in[0]; + const size_t totalSize = sizeof(AxisTag) * axesCount + 1 /* 1 for axes Count */; + LOG_ALWAYS_FATAL_IF(inSize < totalSize); + const AxisTag* axisTags = reinterpret_cast(in + 1); + mSupportedAxes.clear(); + for (uint8_t i = 0; i < axesCount; ++i) { + mSupportedAxes.insert(axisTags[i]); + } + return totalSize; +} } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 5285f2642b4..58a7bab5f69 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -656,4 +656,50 @@ TEST_F(FontFamilyTest, createFamilyWithVariationTest) { } } +TEST_F(FontFamilyTest, supportedAxesRestoreFromSerializedBuffer) { + const char kFontPath[] = kTestFontDir "/MultiAxis.ttf"; + + std::shared_ptr font(new MinikinFontForTest(kFontPath)); + std::shared_ptr family = + std::make_shared(std::vector({Font(font, FontStyle())})); + + size_t necessaryBytes = family->writeAcceleratorTable(nullptr); + ASSERT_NE(0U, necessaryBytes); + std::vector buffer; + buffer.resize(necessaryBytes); + family->writeAcceleratorTable(buffer.data()); + + std::shared_ptr restoredMultiAxisFamily = + std::make_shared(std::vector({Font(font, FontStyle())}), + buffer.data(), buffer.size()); + + // This font has 'wdth' and 'wght' axes. + const std::unordered_set& supportedAxes = family->supportedAxes(); + ASSERT_EQ(2U, supportedAxes.size()); + EXPECT_NE(supportedAxes.end(), supportedAxes.find(MinikinFont::MakeTag('w', 'd', 't', 'h'))); + EXPECT_NE(supportedAxes.end(), supportedAxes.find(MinikinFont::MakeTag('w', 'g', 'h', 't'))); +} + +TEST_F(FontFamilyTest, supportedAxesRestoreFromSerializedBuffer_NoAxisFont) { + const char kFontPath[] = kTestFontDir "/Regular.ttf"; + + std::shared_ptr font(new MinikinFontForTest(kFontPath)); + std::shared_ptr family = + std::make_shared(std::vector({Font(font, FontStyle())})); + + size_t necessaryBytes = family->writeAcceleratorTable(nullptr); + ASSERT_NE(0U, necessaryBytes); + std::vector buffer; + buffer.resize(necessaryBytes); + family->writeAcceleratorTable(buffer.data()); + + std::shared_ptr restoredMultiAxisFamily = + std::make_shared(std::vector({Font(font, FontStyle())}), + buffer.data(), buffer.size()); + + // This font supports no axes. + const std::unordered_set& supportedAxes = family->supportedAxes(); + EXPECT_TRUE(supportedAxes.empty()); +} + } // namespace minikin From e64e9b217609148f704009ae878e36f5a3cb01f0 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Tue, 14 Mar 2017 18:10:48 -0700 Subject: [PATCH 250/364] Introduce minikin_stress_tests to find race condition. This is designed for catching race condition. The stress_tests is splited from unit test binary since this takes 30 seconds on angler. Bug: 36223724 Bug: 36208043 Test: ran minikin_stress_tests Change-Id: I1bf4ba43e6e97cd04e7d6dd42d388dd17ce64c7b --- .../src/flutter/tests/stresstest/Android.mk | 56 +++++++++ .../tests/stresstest/MultithreadTest.cpp | 109 ++++++++++++++++++ .../flutter/tests/stresstest/how_to_run.txt | 3 + 3 files changed, 168 insertions(+) create mode 100644 engine/src/flutter/tests/stresstest/Android.mk create mode 100644 engine/src/flutter/tests/stresstest/MultithreadTest.cpp create mode 100644 engine/src/flutter/tests/stresstest/how_to_run.txt diff --git a/engine/src/flutter/tests/stresstest/Android.mk b/engine/src/flutter/tests/stresstest/Android.mk new file mode 100644 index 00000000000..961978b5ccf --- /dev/null +++ b/engine/src/flutter/tests/stresstest/Android.mk @@ -0,0 +1,56 @@ +# Copyright (C) 2017 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. + +# see how_to_run.txt for instructions on running these tests + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_TEST_DATA := $(foreach f,$(LOCAL_TEST_DATA),frameworks/minikin/tests:$(f)) + +LOCAL_MODULE := minikin_stress_tests +LOCAL_MODULE_TAGS := tests +LOCAL_MODULE_CLASS := NATIVE_TESTS + +LOCAL_STATIC_LIBRARIES := libminikin + +# Shared libraries which are dependencies of minikin; these are not automatically +# pulled in by the build system (and thus sadly must be repeated). + +LOCAL_SHARED_LIBRARIES := \ + libskia \ + libft2 \ + libharfbuzz_ng \ + libicuuc \ + liblog \ + libutils \ + libz + +LOCAL_STATIC_LIBRARIES += \ + libxml2 + +LOCAL_SRC_FILES += \ + ../util/FontTestUtils.cpp \ + ../util/MinikinFontForTest.cpp \ + MultithreadTest.cpp \ + +LOCAL_C_INCLUDES := \ + $(LOCAL_PATH)/../../libs/minikin/ \ + $(LOCAL_PATH)/../util \ + external/libxml2/include \ + +LOCAL_CPPFLAGS += -Werror -Wall -Wextra + +include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/stresstest/MultithreadTest.cpp b/engine/src/flutter/tests/stresstest/MultithreadTest.cpp new file mode 100644 index 00000000000..08c94b99fe5 --- /dev/null +++ b/engine/src/flutter/tests/stresstest/MultithreadTest.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2017 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 + +#include +#include +#include +#include + +#include + +#include "MinikinInternal.h" +#include "minikin/FontCollection.h" +#include "minikin/Layout.h" +#include "../util/FontTestUtils.h" + +namespace minikin { + +const char* SYSTEM_FONT_PATH = "/system/fonts/"; +const char* SYSTEM_FONT_XML = "/system/etc/fonts.xml"; + +constexpr int LAYOUT_COUNT_PER_COLLECTION = 500; +constexpr int COLLECTION_COUNT_PER_THREAD = 15; +constexpr int NUM_THREADS = 10; + +std::mutex gMutex; +std::condition_variable gCv; +bool gReady = false; + +static std::vector generateTestText( + std::mt19937* mt, int lettersInWord, int wordsInText) { + std::uniform_int_distribution dist('A', 'Z'); + + std::vector text; + text.reserve((lettersInWord + 1) * wordsInText - 1); + for (int i = 0; i < wordsInText; ++i) { + if (i != 0) { + text.emplace_back(' '); + } + for (int j = 0; j < lettersInWord; ++j) { + text.emplace_back(dist(*mt)); + } + } + return text; +} + +static void thread_main(int tid) { + { + // Wait until all threads are created. + std::unique_lock lock(gMutex); + gCv.wait(lock, [] { return gReady; }); + } + + std::mt19937 mt(tid); + MinikinPaint paint; + + for (int i = 0; i < COLLECTION_COUNT_PER_THREAD; ++i) { + std::shared_ptr collection( + getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); + + for (int j = 0; j < LAYOUT_COUNT_PER_COLLECTION; ++j) { + // Generates 10 of 3-letter words so that the word sometimes hit the cache. + Layout layout; + std::vector text = generateTestText(&mt, 3, 10); + layout.doLayout(text.data(), 0, text.size(), text.size(), kBidi_LTR, FontStyle(), + paint, collection); + std::vector advances(text.size()); + layout.getAdvances(advances.data()); + for (size_t k = 0; k < advances.size(); ++k) { + // MinikinFontForTest always returns 10.0f for horizontal advance. + LOG_ALWAYS_FATAL_IF(advances[k] != 10.0f, "Memory corruption detected."); + } + } + } +} + +TEST(MultithreadTest, ThreadSafeStressTest) { + std::vector threads; + + { + std::unique_lock lock(gMutex); + threads.reserve(NUM_THREADS); + for (int i = 0; i < NUM_THREADS; ++i) { + threads.emplace_back(&thread_main, i); + } + gReady = true; + } + gCv.notify_all(); + + for (auto& thread : threads) { + thread.join(); + } +} + +} // namespace minikin diff --git a/engine/src/flutter/tests/stresstest/how_to_run.txt b/engine/src/flutter/tests/stresstest/how_to_run.txt new file mode 100644 index 00000000000..ba4dbdf1f73 --- /dev/null +++ b/engine/src/flutter/tests/stresstest/how_to_run.txt @@ -0,0 +1,3 @@ +mmm -j8 frameworks/minikin/tests/stresstest && +adb sync data && +adb shell /data/nativetest/minikin_tests/minikin_stress_tests From f3399b503e4f4beafe1f689a2ba56332097203fb Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Thu, 16 Mar 2017 12:23:08 -0700 Subject: [PATCH 251/364] Refactor WordBreaker Refactor WordBreaker to make it ready for more complex behavior. Test: existing unit tests continue to pass Change-Id: Ife758f3e2cf48922ab56109e6c5d3cffa3673feb --- .../src/flutter/include/minikin/WordBreaker.h | 4 + .../src/flutter/libs/minikin/WordBreaker.cpp | 115 ++++++++++-------- 2 files changed, 69 insertions(+), 50 deletions(-) diff --git a/engine/src/flutter/include/minikin/WordBreaker.h b/engine/src/flutter/include/minikin/WordBreaker.h index 0f95bb208a5..6971ce2013c 100644 --- a/engine/src/flutter/include/minikin/WordBreaker.h +++ b/engine/src/flutter/include/minikin/WordBreaker.h @@ -55,6 +55,10 @@ public: void finish(); private: + int32_t iteratorNext(); + void detectEmailOrUrl(); + ssize_t findNextBreakInEmailOrUrl(); + std::unique_ptr mBreakIterator; UText mUText = UTEXT_INITIALIZER; const uint16_t* mText = nullptr; diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index 7ad7242dff6..36a3e88b23e 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -58,14 +58,6 @@ ssize_t WordBreaker::current() const { return mCurrent; } -enum ScanState { - START, - SAW_AT, - SAW_COLON, - SAW_COLON_SLASH, - SAW_COLON_SLASH_SLASH, -}; - /** * Determine whether a line break at position i within the buffer buf is valid. This * represents customization beyond the ICU behavior, because plain ICU provides some @@ -120,6 +112,22 @@ static bool isBreakValid(const uint16_t* buf, size_t bufEnd, size_t i) { return true; } +// Customized iteratorNext that takes care of both resets and our modifications +// to ICU's behavior. +int32_t WordBreaker::iteratorNext() { + int32_t result; + do { + if (mIteratorWasReset) { + result = mBreakIterator->following(mCurrent); + mIteratorWasReset = false; + } else { + result = mBreakIterator->next(); + } + } while (!(result == icu::BreakIterator::DONE || (size_t)result == mTextSize + || isBreakValid(mText, mTextSize, result))); + return result; +} + // Chicago Manual of Style recommends breaking after these characters in URLs and email addresses static bool breakAfter(uint16_t c) { return c == ':' || c == '=' || c == '&'; @@ -131,9 +139,15 @@ static bool breakBefore(uint16_t c) { || c == '%' || c == '=' || c == '&'; } -ssize_t WordBreaker::next() { - mLast = mCurrent; +enum ScanState { + START, + SAW_AT, + SAW_COLON, + SAW_COLON_SLASH, + SAW_COLON_SLASH_SLASH, +}; +void WordBreaker::detectEmailOrUrl() { // scan forward from current ICU position for email address or URL if (mLast >= mScanOffset) { ScanState state = START; @@ -158,6 +172,9 @@ ssize_t WordBreaker::next() { } if (state == SAW_AT || state == SAW_COLON_SLASH_SLASH) { if (!mBreakIterator->isBoundary(i)) { + // If there are combining marks or such at the end of the URL or the email address, + // consider them a part of the URL or the email, and skip to the next actual + // boundary. i = mBreakIterator->following(i); } mInEmailOrUrl = true; @@ -167,48 +184,46 @@ ssize_t WordBreaker::next() { } mScanOffset = i; } +} - if (mInEmailOrUrl) { - // special rules for email addresses and URL's as per Chicago Manual of Style (16th ed.) - uint16_t lastChar = mText[mLast]; - ssize_t i; - for (i = mLast + 1; i < mScanOffset; i++) { - if (breakAfter(lastChar)) { - break; - } - // break after double slash - if (lastChar == '/' && i >= mLast + 2 && mText[i - 2] == '/') { - break; - } - uint16_t thisChar = mText[i]; - // never break after hyphen - if (lastChar != '-') { - if (breakBefore(thisChar)) { - break; - } - // break before single slash - if (thisChar == '/' && lastChar != '/' && - !(i + 1 < mScanOffset && mText[i + 1] == '/')) { - break; - } - } - lastChar = thisChar; +ssize_t WordBreaker::findNextBreakInEmailOrUrl() { + // special rules for email addresses and URL's as per Chicago Manual of Style (16th ed.) + uint16_t lastChar = mText[mLast]; + ssize_t i; + for (i = mLast + 1; i < mScanOffset; i++) { + if (breakAfter(lastChar)) { + break; } - mCurrent = i; - return mCurrent; + // break after double slash + if (lastChar == '/' && i >= mLast + 2 && mText[i - 2] == '/') { + break; + } + const uint16_t thisChar = mText[i]; + // never break after hyphen + if (lastChar != '-') { + if (breakBefore(thisChar)) { + break; + } + // break before single slash + if (thisChar == '/' && lastChar != '/' && + !(i + 1 < mScanOffset && mText[i + 1] == '/')) { + break; + } + } + lastChar = thisChar; } + return i; +} - int32_t result; - do { - if (mIteratorWasReset) { - result = mBreakIterator->following(mCurrent); - mIteratorWasReset = false; - } else { - result = mBreakIterator->next(); - } - } while (result != icu::BreakIterator::DONE && (size_t)result != mTextSize - && !isBreakValid(mText, mTextSize, result)); - mCurrent = (ssize_t)result; +ssize_t WordBreaker::next() { + mLast = mCurrent; + + detectEmailOrUrl(); + if (mInEmailOrUrl) { + mCurrent = findNextBreakInEmailOrUrl(); + } else { // Business as usual + mCurrent = (ssize_t) iteratorNext(); + } return mCurrent; } @@ -221,7 +236,7 @@ ssize_t WordBreaker::wordStart() const { UChar32 c; ssize_t ix = result; U16_NEXT(mText, ix, mCurrent, c); - int32_t lb = u_getIntPropertyValue(c, UCHAR_LINE_BREAK); + const int32_t lb = u_getIntPropertyValue(c, UCHAR_LINE_BREAK); // strip leading punctuation, defined as OP and QU line breaking classes, // see UAX #14 if (!(lb == U_LB_OPEN_PUNCTUATION || lb == U_LB_QUOTATION)) { @@ -241,7 +256,7 @@ ssize_t WordBreaker::wordEnd() const { UChar32 c; ssize_t ix = result; U16_PREV(mText, mLast, ix, c); - int32_t gc_mask = U_GET_GC_MASK(c); + const int32_t gc_mask = U_GET_GC_MASK(c); // strip trailing space and punctuation if ((gc_mask & (U_GC_ZS_MASK | U_GC_P_MASK)) == 0) { break; From f2fd20ec540cd6db8eb96daa55727e87dec5a47c Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Wed, 15 Mar 2017 16:35:36 -0700 Subject: [PATCH 252/364] Update emoji grapheme breaking rules The rules are updated to the latest UAX #29, with tailorings based on the font in use: we can now use the clustering information calculated by Layout, so we will only disallow a grapheme break if an emoji ligature is actually formed. Test: Unit tests have been updated and pass. Bug: 30917298 Bug: 34211654 Change-Id: Idc0ef9f1f4f45dc45a50ed69e45c43ebfaea0306 --- .../flutter/libs/minikin/GraphemeBreak.cpp | 126 +++++++++++------- .../tests/unittest/GraphemeBreakTests.cpp | 68 ++++++++-- 2 files changed, 139 insertions(+), 55 deletions(-) diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index 56f3a52a5df..b1188e8d88e 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -102,70 +102,102 @@ bool GraphemeBreak::isGraphemeBreak(const float* advances, const uint16_t* buf, if ((p1 == U_GCB_LVT || p1 == U_GCB_T) && p2 == U_GCB_T) { return false; } - // Rule GB8a that looks at even-off cases. - // - // sot (RI RI)* RI x RI - // [^RI] (RI RI)* RI x RI - // RI ÷ RI - if (p1 == U_GCB_REGIONAL_INDICATOR && p2 == U_GCB_REGIONAL_INDICATOR) { - // Look at up to 1000 code units. - start = std::max((ssize_t)start, (ssize_t)offset_back - 1000); - while (offset_back > start) { - U16_PREV(buf, start, offset_back, c1); - if (tailoredGraphemeClusterBreak(c1) != U_GCB_REGIONAL_INDICATOR) { - offset_back += U16_LENGTH(c1); - break; - } - } - - // The number 4 comes from the number of code units in a whole flag. - return (offset - offset_back) % 4 == 0; - } // Rule GB9, x (Extend | ZWJ); Rule GB9a, x SpacingMark; Rule GB9b, Prepend x if (p2 == U_GCB_EXTEND || p2 == U_GCB_ZWJ || p2 == U_GCB_SPACING_MARK || p1 == U_GCB_PREPEND) { return false; } - // Cluster Indic syllables together (tailoring of UAX #29). - // Immediately after each virama (that is not just a pure killer) followed by a letter, we - // check to see if the next character has a non-zero width assigned to it in the advances - // array. A zero width means a cluster is formed with the virama (so there is no grapheme - // break), while a non-zero width means a new cluster is started (so there may be a grapheme - // break). - if (u_getIntPropertyValue(c1, UCHAR_CANONICAL_COMBINING_CLASS) == 9 // virama - && !isPureKiller(c1) - && u_getIntPropertyValue(c2, UCHAR_GENERAL_CATEGORY) == U_OTHER_LETTER - && (advances == nullptr || advances[offset - start] == 0)) { - return false; + + // This is used to decide font-dependent grapheme clusters. If we don't have the advance + // information, we become conservative in grapheme breaking and assume that it has no advance. + const bool c2_has_advance = (advances != nullptr && advances[offset - start] != 0.0); + + // All the following rules are font-dependent, in the way that if we know c2 has an advance, + // we definitely know that it cannot form a grapheme with the character(s) before it. So we + // make the decision in favor a grapheme break early. + if (c2_has_advance) { + return true; } - // Tailoring: make emoji sequences with ZWJ a single grapheme cluster + + // Note: For Rule GB10 and GB11 below, we do not use the Unicode line breaking properties for + // determining emoji-ness and carry our own data, because our data could be more fresh than what + // ICU provides. + // + // Tailored version of Rule GB10, (E_Base | EBG) Extend* × E_Modifier. + // The rule itself says do not break between emoji base and emoji modifiers, skipping all Extend + // characters. Variation selectors are considered Extend, so they are handled fine. + // + // We tailor this by requiring that an actual ligature is formed. If the font doesn't form a + // ligature, we allow a break before the modifier. + if (isEmojiModifier(c2)) { + uint32_t c0 = c1; + size_t offset_backback = offset_back; + int32_t p0 = p1; + if (p0 == U_GCB_EXTEND && offset_backback > start) { + // skip over emoji variation selector + U16_PREV(buf, start, offset_backback, c0); + p0 = tailoredGraphemeClusterBreak(c0); + } + if (isEmojiBase(c0)) { + return false; + } + } + // Tailored version of Rule GB11, ZWJ × (Glue_After_Zwj | EBG) + // We try to make emoji sequences with ZWJ a single grapheme cluster, but only if they actually + // merge to one cluster. So we are more relaxed than the UAX #29 rules in accepting any emoji + // character after the ZWJ, but are tighter in that we only treat it as one cluster if a + // ligature is actually formed and we also require the character before the ZWJ to also be an + // emoji. if (p1 == U_GCB_ZWJ && isEmoji(c2) && offset_back > start) { // look at character before ZWJ to see that both can participate in an emoji zwj sequence uint32_t c0 = 0; - U16_PREV(buf, start, offset_back, c0); - if (c0 == 0xFE0F && offset_back > start) { + size_t offset_backback = offset_back; + U16_PREV(buf, start, offset_backback, c0); + if (c0 == 0xFE0F && offset_backback > start) { // skip over emoji variation selector - U16_PREV(buf, start, offset_back, c0); + U16_PREV(buf, start, offset_backback, c0); } if (isEmoji(c0)) { return false; } } - // Proposed Rule GB9c from http://www.unicode.org/L2/L2016/16011r3-break-prop-emoji.pdf - // E_Base x E_Modifier - // TODO: Migrate to Rule GB10 and Rule GB11 with fixing following test cases in - // GraphemeBreak.tailoring and GraphemeBreak.emojiModifiers (Bug: 34211654) - // U+0628 U+200D U+2764 is expected to have grapheme boundary after U+200D. - // U+270C U+FE0E U+1F3FB is expected to have grapheme boundary after U+200D. - if (isEmojiModifier(c2)) { - if (c1 == 0xFE0F && offset_back > start) { - // skip over emoji variation selector - U16_PREV(buf, start, offset_back, c1); - } - if (isEmojiBase(c1)) { + // Tailored version of Rule GB12 and Rule GB13 that look at even-odd cases. + // sot (RI RI)* RI x RI + // [^RI] (RI RI)* RI x RI + // + // If we have font information, we have already broken the cluster if and only if the second + // character had no advance, which means a ligature was formed. If we don't, we look back like + // UAX #29 recommends, but only up to 1000 code units. + if (p1 == U_GCB_REGIONAL_INDICATOR && p2 == U_GCB_REGIONAL_INDICATOR) { + if (advances != nullptr) { + // We have advances information. But if we are here, we already know c2 has no advance. + // So we should definitely disallow a break. return false; + } else { + // Look at up to 1000 code units. + const size_t lookback_barrier = std::max((ssize_t)start, (ssize_t)offset_back - 1000); + size_t offset_backback = offset_back; + while (offset_backback > lookback_barrier) { + uint32_t c0 = 0; + U16_PREV(buf, lookback_barrier, offset_backback, c0); + if (tailoredGraphemeClusterBreak(c0) != U_GCB_REGIONAL_INDICATOR) { + offset_backback += U16_LENGTH(c0); + break; + } + } + // The number 4 comes from the number of code units in a whole flag. + return (offset - offset_backback) % 4 == 0; } } - // Rule GB10, Any ÷ Any + // Cluster Indic syllables together (tailoring of UAX #29). + // Immediately after each virama (that is not just a pure killer) followed by a letter, we + // disallow grapheme breaks (if we are here, we don't know about advances, or we already know + // that c2 has no advance). + if (u_getIntPropertyValue(c1, UCHAR_CANONICAL_COMBINING_CLASS) == 9 // virama + && !isPureKiller(c1) + && u_getIntPropertyValue(c2, UCHAR_GENERAL_CATEGORY) == U_OTHER_LETTER) { + return false; + } + // Rule GB999, Any ÷ Any return true; } diff --git a/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp b/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp index 96bd8a8e79f..6720df6befa 100644 --- a/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp +++ b/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp @@ -91,7 +91,7 @@ TEST(GraphemeBreak, rules) { EXPECT_TRUE(IsBreak("U+11A8 | U+AC00")); // T x LV EXPECT_TRUE(IsBreak("U+11A8 | U+AC01")); // T x LVT - // Rule GB8a, Regional_Indicator x Regional_Indicator + // Rule GB12 and Rule GB13, Regional_Indicator x Regional_Indicator EXPECT_FALSE(IsBreak("U+1F1FA | U+1F1F8")); EXPECT_TRUE(IsBreak("U+1F1FA U+1F1F8 | U+1F1FA U+1F1F8")); // Regional indicator pair (flag) EXPECT_FALSE(IsBreak("U+1F1FA | U+1F1F8 U+1F1FA U+1F1F8")); // Regional indicator pair (flag) @@ -99,6 +99,17 @@ TEST(GraphemeBreak, rules) { EXPECT_TRUE(IsBreak("U+1F1FA U+1F1F8 | U+1F1FA")); // Regional indicator pair (flag) EXPECT_FALSE(IsBreak("U+1F1FA | U+1F1F8 U+1F1FA")); // Regional indicator pair (flag) + // Same case as the two above, knowing that the first two characters ligate, which is what + // would typically happen. + const float firstPairLigated[] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0}; // Two entries per codepoint + EXPECT_TRUE(IsBreakWithAdvances(firstPairLigated, "U+1F1FA U+1F1F8 | U+1F1FA")); + EXPECT_FALSE(IsBreakWithAdvances(firstPairLigated, "U+1F1FA | U+1F1F8 U+1F1FA")); + // Repeat the tests, But now the font doesn't have a ligature for the first two characters, + // while it does have a ligature for the last two. This could happen for fonts that do not + // support some (potentially encoded later than they were developed) flags. + const float secondPairLigated[] = {1.0, 0.0, 1.0, 0.0, 0.0, 0.0}; + EXPECT_FALSE(IsBreakWithAdvances(secondPairLigated, "U+1F1FA U+1F1F8 | U+1F1FA")); + EXPECT_TRUE(IsBreakWithAdvances(secondPairLigated, "U+1F1FA | U+1F1F8 U+1F1FA")); EXPECT_TRUE(IsBreak("'a' U+1F1FA U+1F1F8 | U+1F1FA")); // Regional indicator pair (flag) EXPECT_FALSE(IsBreak("'a' U+1F1FA | U+1F1F8 U+1F1FA")); // Regional indicator pair (flag) @@ -110,14 +121,15 @@ TEST(GraphemeBreak, rules) { EXPECT_FALSE( IsBreak("'a' U+1F1FA U+1F1F8 U+1F1FA | U+1F1F8")); // Regional indicator pair (flag) - // Rule GB9, x Extend + // Rule GB9, x (Extend | ZWJ) EXPECT_FALSE(IsBreak("'a' | U+0301")); // combining accent + EXPECT_FALSE(IsBreak("'a' | U+200D")); // ZWJ // Rule GB9a, x SpacingMark EXPECT_FALSE(IsBreak("U+0915 | U+093E")); // KA, AA (spacing mark) // Rule GB9b, Prepend x // see tailoring test for prepend, as current ICU doesn't have any characters in the class - // Rule GB10, Any ÷ Any + // Rule GB999, Any ÷ Any EXPECT_TRUE(IsBreak("'a' | 'b'")); EXPECT_TRUE(IsBreak("'f' | 'i'")); // probable ligature EXPECT_TRUE(IsBreak("U+0644 | U+0627")); // probable ligature, lam + alef @@ -198,8 +210,7 @@ TEST(GraphemeBreak, tailoring) { EXPECT_TRUE(IsBreakWithAdvances(separate, "U+0E01 U+0E3A | U+0E01")); // thai phinthu = pure killer - // suppress grapheme breaks in zwj emoji sequences, see - // http://www.unicode.org/emoji/charts/emoji-zwj-sequences.html + // suppress grapheme breaks in zwj emoji sequences EXPECT_FALSE(IsBreak("U+1F469 U+200D | U+2764 U+FE0F U+200D U+1F48B U+200D U+1F468")); EXPECT_FALSE(IsBreak("U+1F469 U+200D U+2764 U+FE0F U+200D | U+1F48B U+200D U+1F468")); EXPECT_FALSE(IsBreak("U+1F469 U+200D U+2764 U+FE0F U+200D U+1F48B U+200D | U+1F468")); @@ -228,10 +239,42 @@ TEST(GraphemeBreak, emojiModifiers) { EXPECT_FALSE(IsBreak("U+1F466 | U+1F3FF")); // boy + modifier EXPECT_FALSE(IsBreak("U+1F918 | U+1F3FF")); // sign of the horns + modifier EXPECT_FALSE(IsBreak("U+1F933 | U+1F3FF")); // selfie (Unicode 9) + modifier + // Reptition of the tests above, with the knowledge that they are ligated. + const float ligated1_2[] = {1.0, 0.0, 0.0}; + const float ligated2_2[] = {1.0, 0.0, 0.0, 0.0}; + EXPECT_FALSE(IsBreakWithAdvances(ligated1_2, "U+261D | U+1F3FB")); + EXPECT_FALSE(IsBreakWithAdvances(ligated1_2, "U+270C | U+1F3FB")); + EXPECT_FALSE(IsBreakWithAdvances(ligated2_2, "U+1F466 | U+1F3FB")); + EXPECT_FALSE(IsBreakWithAdvances(ligated2_2, "U+1F466 | U+1F3FC")); + EXPECT_FALSE(IsBreakWithAdvances(ligated2_2, "U+1F466 | U+1F3FD")); + EXPECT_FALSE(IsBreakWithAdvances(ligated2_2, "U+1F466 | U+1F3FE")); + EXPECT_FALSE(IsBreakWithAdvances(ligated2_2, "U+1F466 | U+1F3FF")); + EXPECT_FALSE(IsBreakWithAdvances(ligated2_2, "U+1F918 | U+1F3FF")); + EXPECT_FALSE(IsBreakWithAdvances(ligated2_2, "U+1F933 | U+1F3FF")); + // Reptition of the tests above, with the knowledge that they are not ligated. + const float unligated1_2[] = {1.0, 1.0, 0.0}; + const float unligated2_2[] = {1.0, 0.0, 1.0, 0.0}; + EXPECT_TRUE(IsBreakWithAdvances(unligated1_2, "U+261D | U+1F3FB")); + EXPECT_TRUE(IsBreakWithAdvances(unligated1_2, "U+270C | U+1F3FB")); + EXPECT_TRUE(IsBreakWithAdvances(unligated2_2, "U+1F466 | U+1F3FB")); + EXPECT_TRUE(IsBreakWithAdvances(unligated2_2, "U+1F466 | U+1F3FC")); + EXPECT_TRUE(IsBreakWithAdvances(unligated2_2, "U+1F466 | U+1F3FD")); + EXPECT_TRUE(IsBreakWithAdvances(unligated2_2, "U+1F466 | U+1F3FE")); + EXPECT_TRUE(IsBreakWithAdvances(unligated2_2, "U+1F466 | U+1F3FF")); + EXPECT_TRUE(IsBreakWithAdvances(unligated2_2, "U+1F918 | U+1F3FF")); + EXPECT_TRUE(IsBreakWithAdvances(unligated2_2, "U+1F933 | U+1F3FF")); - // adding emoji style variation selector doesn't affect grapheme cluster - EXPECT_TRUE(IsBreak("U+270C U+FE0E | U+1F3FB")); // victory hand + text style + modifier + // adding extend characters between emoji base and modifier doesn't affect grapheme cluster + EXPECT_FALSE(IsBreak("U+270C U+FE0E | U+1F3FB")); // victory hand + text style + modifier EXPECT_FALSE(IsBreak("U+270C U+FE0F | U+1F3FB")); // heart + emoji style + modifier + // Reptition of the two tests above, with the knowledge that they are ligated. + const float ligated1_1_2[] = {1.0, 0.0, 0.0, 0.0}; + EXPECT_FALSE(IsBreakWithAdvances(ligated1_1_2, "U+270C U+FE0E | U+1F3FB")); + EXPECT_FALSE(IsBreakWithAdvances(ligated1_1_2, "U+270C U+FE0F | U+1F3FB")); + // Reptition of the first two tests, with the knowledge that they are not ligated. + const float unligated1_1_2[] = {1.0, 0.0, 1.0, 0.0}; + EXPECT_TRUE(IsBreakWithAdvances(unligated1_1_2, "U+270C U+FE0E | U+1F3FB")); + EXPECT_TRUE(IsBreakWithAdvances(unligated1_1_2, "U+270C U+FE0F | U+1F3FB")); // heart is not an emoji base EXPECT_TRUE(IsBreak("U+2764 | U+1F3FB")); // heart + modifier @@ -241,17 +284,26 @@ TEST(GraphemeBreak, emojiModifiers) { // rat is not an emoji modifer EXPECT_TRUE(IsBreak("U+1F466 | U+1F400")); // boy + rat - } TEST(GraphemeBreak, genderBalancedEmoji) { // U+1F469 is WOMAN, U+200D is ZWJ, U+1F4BC is BRIEFCASE. EXPECT_FALSE(IsBreak("U+1F469 | U+200D U+1F4BC")); EXPECT_FALSE(IsBreak("U+1F469 U+200D | U+1F4BC")); + // The above two cases, when the ligature is not supported in the font. We now expect a break + // between them. + const float unligated2_1_2[] = {1.0, 0.0, 0.0, 1.0, 0.0}; + EXPECT_FALSE(IsBreakWithAdvances(unligated2_1_2, "U+1F469 | U+200D U+1F4BC")); + EXPECT_TRUE(IsBreakWithAdvances(unligated2_1_2, "U+1F469 U+200D | U+1F4BC")); // U+2695 has now emoji property, so should be part of ZWJ sequence. EXPECT_FALSE(IsBreak("U+1F469 | U+200D U+2695")); EXPECT_FALSE(IsBreak("U+1F469 U+200D | U+2695")); + // The above two cases, when the ligature is not supported in the font. We now expect a break + // between them. + const float unligated2_1_1[] = {1.0, 0.0, 0.0, 1.0}; + EXPECT_FALSE(IsBreakWithAdvances(unligated2_1_1, "U+1F469 | U+200D U+2695")); + EXPECT_TRUE(IsBreakWithAdvances(unligated2_1_1, "U+1F469 U+200D | U+2695")); } TEST(GraphemeBreak, offsets) { From 3d10a1ed4f69df9dbadefa0d28a2de6f99eb0e1c Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Thu, 16 Mar 2017 14:18:59 -0700 Subject: [PATCH 253/364] Update emoji character data in Minikin Update emoji character data to Unicode 10.0 / Emoji 5.0 (which also removes U+1F93B MODERN PENATHLON from the emoji base letters). Also add unit tests for line breaking for new characters (based on earlier work by Seigo Nonaka). Test: All new and existing unit tests pass; Test: Manually tested line breaking of new emojis in TextView. Bug: 28364892 Bug: 28678294 Bug: 30874706 Change-Id: I367cdab09187dc08a66a3112a5181a2b7fb338a5 --- .../flutter/libs/minikin/MinikinInternal.cpp | 36 ++++++++----- .../tests/unittest/WordBreakerTests.cpp | 51 ++++++++++++++++++- 2 files changed, 74 insertions(+), 13 deletions(-) diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index e766dce992d..60fa9636f8f 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -34,29 +34,39 @@ void assertMinikinLocked() { } bool isEmoji(uint32_t c) { - // U+2695 U+2640 U+2642 are not in emoji category in Unicode 9 but they are now emoji category. - // TODO: remove once emoji database is updated. - if (c == 0x2695 || c == 0x2640 || c == 0x2642) { + // Emoji characters new in Unicode emoji 5.0. + // From http://www.unicode.org/Public/emoji/5.0/emoji-data.txt + // TODO: Remove once emoji-data.text 5.0 is in the tree. + if ((0x1F6F7 <= c && c <= 0x1F6F8) + || c == 0x1F91F + || (0x1F928 <= c && c <= 0x1F92F) + || (0x1F931 <= c && c <= 0x1F932) + || c == 0x1F94C + || (0x1F95F <= c && c <= 0x1F96B) + || (0x1F992 <= c && c <= 0x1F997) + || (0x1F9D0 <= c && c <= 0x1F9E6)) { return true; } + const size_t length = sizeof(generated::EMOJI_LIST) / sizeof(generated::EMOJI_LIST[0]); return std::binary_search(generated::EMOJI_LIST, generated::EMOJI_LIST + length, c); } -// Based on Modifiers from http://www.unicode.org/L2/L2016/16011-data-file.txt +// Based on Emoji_Modifier from http://www.unicode.org/Public/emoji/5.0/emoji-data.txt bool isEmojiModifier(uint32_t c) { return (0x1F3FB <= c && c <= 0x1F3FF); } // Based on Emoji_Modifier_Base from -// http://www.unicode.org/Public/emoji/3.0/emoji-data.txt +// http://www.unicode.org/Public/emoji/5.0/emoji-data.txt bool isEmojiBase(uint32_t c) { if (0x261D <= c && c <= 0x270D) { return (c == 0x261D || c == 0x26F9 || (0x270A <= c && c <= 0x270D)); } else if (0x1F385 <= c && c <= 0x1F93E) { return (c == 0x1F385 - || (0x1F3C3 <= c && c <= 0x1F3C4) - || (0x1F3CA <= c && c <= 0x1F3CB) + || (0x1F3C2 <= c && c <= 0x1F3C4) + || c == 0x1F3C7 + || (0x1F3CA <= c && c <= 0x1F3CC) || (0x1F442 <= c && c <= 0x1F443) || (0x1F446 <= c && c <= 0x1F450) || (0x1F466 <= c && c <= 0x1F469) @@ -66,7 +76,7 @@ bool isEmojiBase(uint32_t c) { || (0x1F481 <= c && c <= 0x1F483) || (0x1F485 <= c && c <= 0x1F487) || c == 0x1F4AA - || c == 0x1F575 + || (0x1F574 <= c && c <= 0x1F575) || c == 0x1F57A || c == 0x1F590 || (0x1F595 <= c && c <= 0x1F596) @@ -75,11 +85,13 @@ bool isEmojiBase(uint32_t c) { || c == 0x1F6A3 || (0x1F6B4 <= c && c <= 0x1F6B6) || c == 0x1F6C0 - || (0x1F918 <= c && c <= 0x1F91E) + || c == 0x1F6CC + || (0x1F918 <= c && c <= 0x1F91C) + || (0x1F91E <= c && c <= 0x1F91F) || c == 0x1F926 - || c == 0x1F930 - || (0x1F933 <= c && c <= 0x1F939) - || (0x1F93B <= c && c <= 0x1F93E)); + || (0x1F930 <= c && c <= 0x1F939) + || (0x1F93D <= c && c <= 0x1F93E) + || (0x1F9D1 <= c && c <= 0x1F9DD)); } else { return false; } diff --git a/engine/src/flutter/tests/unittest/WordBreakerTests.cpp b/engine/src/flutter/tests/unittest/WordBreakerTests.cpp index 7971b490703..13e0420c8af 100644 --- a/engine/src/flutter/tests/unittest/WordBreakerTests.cpp +++ b/engine/src/flutter/tests/unittest/WordBreakerTests.cpp @@ -99,7 +99,7 @@ TEST_F(WordBreakerTest, postfixAndPrefix) { EXPECT_EQ((ssize_t)NELEM(buf), breaker.wordEnd()); } -TEST_F(WordBreakerTest, MyanmarKinzi) { +TEST_F(WordBreakerTest, myanmarKinzi) { uint16_t buf[] = {0x1004, 0x103A, 0x1039, 0x1000, 0x102C}; // NGA, ASAT, VIRAMA, KA, UU WordBreaker breaker; icu::Locale burmese("my"); @@ -158,6 +158,55 @@ TEST_F(WordBreakerTest, emojiWithModifier) { EXPECT_EQ(8, breaker.wordEnd()); } +TEST_F(WordBreakerTest, unicode10Emoji) { + // Should break between emojis. + uint16_t buf[] = { + // SLED + SLED + UTF16(0x1F6F7), UTF16(0x1F6F7), + // SLED + VS15 + SLED + UTF16(0x1F6F7), 0xFE0E, UTF16(0x1F6F7), + // WHITE SMILING FACE + SLED + 0x263A, UTF16(0x1F6F7), + // WHITE SMILING FACE + VS16 + SLED + 0x263A, 0xFE0F, UTF16(0x1F6F7), + }; + WordBreaker breaker; + breaker.setLocale(icu::Locale::getEnglish()); + breaker.setText(buf, NELEM(buf)); + EXPECT_EQ(0, breaker.current()); + EXPECT_EQ(2, breaker.next()); + EXPECT_EQ(0, breaker.wordStart()); + EXPECT_EQ(2, breaker.wordEnd()); + + EXPECT_EQ(4, breaker.next()); + EXPECT_EQ(2, breaker.wordStart()); + EXPECT_EQ(4, breaker.wordEnd()); + + EXPECT_EQ(7, breaker.next()); + EXPECT_EQ(4, breaker.wordStart()); + EXPECT_EQ(7, breaker.wordEnd()); + + EXPECT_EQ(9, breaker.next()); + EXPECT_EQ(7, breaker.wordStart()); + EXPECT_EQ(9, breaker.wordEnd()); + + EXPECT_EQ(10, breaker.next()); + EXPECT_EQ(9, breaker.wordStart()); + EXPECT_EQ(10, breaker.wordEnd()); + + EXPECT_EQ(12, breaker.next()); + EXPECT_EQ(10, breaker.wordStart()); + EXPECT_EQ(12, breaker.wordEnd()); + + EXPECT_EQ(14, breaker.next()); + EXPECT_EQ(12, breaker.wordStart()); + EXPECT_EQ(14, breaker.wordEnd()); + + EXPECT_EQ(16, breaker.next()); + EXPECT_EQ(14, breaker.wordStart()); + EXPECT_EQ(16, breaker.wordEnd()); +} + TEST_F(WordBreakerTest, flagsSequenceSingleFlag) { const std::string kFlag = "U+1F3F4"; const std::string flags = kFlag + " " + kFlag; From 2d0bfff20317fcd083de6b3c1c9a2dbfcd317499 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 16 Mar 2017 15:55:25 -0700 Subject: [PATCH 254/364] Introduce FontCollection construct perf test Test: ran minikin_perftest Bug: 36232655 Change-Id: Ic4d88663d522be17540e2ac17c9b7ae64210275f --- .../tests/perftests/FontCollection.cpp | 10 ++++++++++ .../src/flutter/tests/util/FontTestUtils.cpp | 19 +++++++++++-------- engine/src/flutter/tests/util/FontTestUtils.h | 17 ++++++++++++++--- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/engine/src/flutter/tests/perftests/FontCollection.cpp b/engine/src/flutter/tests/perftests/FontCollection.cpp index 6f9d636ca30..fd95cf1a60c 100644 --- a/engine/src/flutter/tests/perftests/FontCollection.cpp +++ b/engine/src/flutter/tests/perftests/FontCollection.cpp @@ -27,6 +27,16 @@ namespace minikin { const char* SYSTEM_FONT_PATH = "/system/fonts/"; const char* SYSTEM_FONT_XML = "/system/etc/fonts.xml"; +static void BM_FontCollection_construct(benchmark::State& state) { + std::vector> families = + getFontFamilies(SYSTEM_FONT_PATH, SYSTEM_FONT_XML); + while (state.KeepRunning()) { + std::make_shared(families); + } +} + +BENCHMARK(BM_FontCollection_construct); + static void BM_FontCollection_hasVariationSelector(benchmark::State& state) { std::shared_ptr collection( getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); diff --git a/engine/src/flutter/tests/util/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp index 27a693e16dc..13360d4aa24 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.cpp +++ b/engine/src/flutter/tests/util/FontTestUtils.cpp @@ -28,7 +28,7 @@ namespace minikin { -FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { +std::vector> getFontFamilies(const char* fontDir, const char* fontXml) { xmlDoc* doc = xmlReadFile(fontXml, NULL, 0); xmlNode* familySet = xmlDocGetRootElement(doc); @@ -69,11 +69,12 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { } if (index == nullptr) { - std::shared_ptr minikinFont(new MinikinFontForTest(fontPath)); + std::shared_ptr minikinFont = + std::make_shared(fontPath); fonts.push_back(Font(minikinFont, FontStyle(weight, italic))); } else { - std::shared_ptr minikinFont( - new MinikinFontForTest(fontPath, atoi((const char*)index))); + std::shared_ptr minikinFont = + std::make_shared(fontPath, atoi((const char*)index)); fonts.push_back(Font(minikinFont, FontStyle(weight, italic))); } } @@ -81,17 +82,19 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); std::shared_ptr family; if (lang == nullptr) { - family.reset(new FontFamily(variant, std::move(fonts))); + family = std::make_shared(variant, std::move(fonts)); } else { uint32_t langId = FontStyle::registerLanguageList( std::string((const char*)lang, xmlStrlen(lang))); - family.reset(new FontFamily(langId, variant, std::move(fonts))); + family = std::make_shared(langId, variant, std::move(fonts)); } families.push_back(family); } xmlFreeDoc(doc); - - return new FontCollection(families); + return families; +} +std::shared_ptr getFontCollection(const char* fontDir, const char* fontXml) { + return std::make_shared(getFontFamilies(fontDir, fontXml)); } } // namespace minikin diff --git a/engine/src/flutter/tests/util/FontTestUtils.h b/engine/src/flutter/tests/util/FontTestUtils.h index 69ba841b438..dd5e5860e4b 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.h +++ b/engine/src/flutter/tests/util/FontTestUtils.h @@ -19,17 +19,28 @@ #include +#include + namespace minikin { +/** + * Returns list of FontFamily from installed fonts. + * + * This function reads an XML file and makes font families. + * + * Caller must unref the returned pointer. + */ +std::vector> getFontFamilies(const char* fontDir, const char* fontXml); + /** * Returns FontCollection from installed fonts. * - * This function reads /system/etc/fonts.xml and make font families and - * collections of them. MinikinFontForTest is used for FontFamily creation. + * This function reads an XML file and makes font families and collections of them. + * MinikinFontForTest is used for FontFamily creation. * * Caller must unref the returned pointer. */ -FontCollection* getFontCollection(const char* fontDir, const char* fontXml); +std::shared_ptr getFontCollection(const char* fontDir, const char* fontXml); } // namespace minikin #endif // MINIKIN_FONT_TEST_UTILS_H From 215f7ff8d061952135689e8fdaed31d2dd904dff Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Fri, 17 Mar 2017 14:29:09 -0700 Subject: [PATCH 255/364] Update Minikin to use ICU's emoji data Certain differences are still needed, since ICU appears to support Emoji 4.0 only, while we need Emoji 5.0. But the bulk of the data is now carried by ICU. We no longer need the script that generates the tables, so that's also removed. Test: Comprehensive unit tests added. Bug: 27365282 Bug: 30874706 Change-Id: I011443fbca9bb202deff7fffb40043f89e1f1fb1 --- engine/src/flutter/libs/minikin/Android.mk | 12 -- .../flutter/libs/minikin/MinikinInternal.cpp | 63 ++++------- .../libs/minikin/unicode_emoji_h_gen.py | 105 ------------------ .../tests/unittest/MinikinInternalTest.cpp | 46 ++++++++ 4 files changed, 66 insertions(+), 160 deletions(-) delete mode 100644 engine/src/flutter/libs/minikin/unicode_emoji_h_gen.py diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 603638e754d..be5301218ac 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -15,18 +15,6 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -# Generate unicode emoji data from UCD. -UNICODE_EMOJI_H_GEN_PY := $(LOCAL_PATH)/unicode_emoji_h_gen.py -UNICODE_EMOJI_DATA := $(TOP)/external/unicode/emoji-data.txt - -UNICODE_EMOJI_H := $(intermediates)/generated/UnicodeData.h -$(UNICODE_EMOJI_H): $(UNICODE_EMOJI_H_GEN_PY) $(UNICODE_EMOJI_DATA) -$(LOCAL_PATH)/MinikinInternal.cpp: $(UNICODE_EMOJI_H) -$(UNICODE_EMOJI_H): PRIVATE_CUSTOM_TOOL := python $(UNICODE_EMOJI_H_GEN_PY) \ - -i $(UNICODE_EMOJI_DATA) \ - -o $(UNICODE_EMOJI_H) -$(UNICODE_EMOJI_H): - $(transform-generated-source) include $(CLEAR_VARS) minikin_src_files := \ diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index 60fa9636f8f..212ee26c0f8 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -19,8 +19,8 @@ #include "MinikinInternal.h" #include "HbFontCache.h" -#include "generated/UnicodeData.h" +#include #include namespace minikin { @@ -36,7 +36,7 @@ void assertMinikinLocked() { bool isEmoji(uint32_t c) { // Emoji characters new in Unicode emoji 5.0. // From http://www.unicode.org/Public/emoji/5.0/emoji-data.txt - // TODO: Remove once emoji-data.text 5.0 is in the tree. + // TODO: Remove once emoji-data.text 5.0 is in ICU or update to 6.0. if ((0x1F6F7 <= c && c <= 0x1F6F8) || c == 0x1F91F || (0x1F928 <= c && c <= 0x1F92F) @@ -47,54 +47,31 @@ bool isEmoji(uint32_t c) { || (0x1F9D0 <= c && c <= 0x1F9E6)) { return true; } - - const size_t length = sizeof(generated::EMOJI_LIST) / sizeof(generated::EMOJI_LIST[0]); - return std::binary_search(generated::EMOJI_LIST, generated::EMOJI_LIST + length, c); + return u_hasBinaryProperty(c, UCHAR_EMOJI); } -// Based on Emoji_Modifier from http://www.unicode.org/Public/emoji/5.0/emoji-data.txt bool isEmojiModifier(uint32_t c) { - return (0x1F3FB <= c && c <= 0x1F3FF); + // Emoji modifier are not expected to change, so there's a small change we need to customize + // this. + return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER); } -// Based on Emoji_Modifier_Base from -// http://www.unicode.org/Public/emoji/5.0/emoji-data.txt bool isEmojiBase(uint32_t c) { - if (0x261D <= c && c <= 0x270D) { - return (c == 0x261D || c == 0x26F9 || (0x270A <= c && c <= 0x270D)); - } else if (0x1F385 <= c && c <= 0x1F93E) { - return (c == 0x1F385 - || (0x1F3C2 <= c && c <= 0x1F3C4) - || c == 0x1F3C7 - || (0x1F3CA <= c && c <= 0x1F3CC) - || (0x1F442 <= c && c <= 0x1F443) - || (0x1F446 <= c && c <= 0x1F450) - || (0x1F466 <= c && c <= 0x1F469) - || c == 0x1F46E - || (0x1F470 <= c && c <= 0x1F478) - || c == 0x1F47C - || (0x1F481 <= c && c <= 0x1F483) - || (0x1F485 <= c && c <= 0x1F487) - || c == 0x1F4AA - || (0x1F574 <= c && c <= 0x1F575) - || c == 0x1F57A - || c == 0x1F590 - || (0x1F595 <= c && c <= 0x1F596) - || (0x1F645 <= c && c <= 0x1F647) - || (0x1F64B <= c && c <= 0x1F64F) - || c == 0x1F6A3 - || (0x1F6B4 <= c && c <= 0x1F6B6) - || c == 0x1F6C0 - || c == 0x1F6CC - || (0x1F918 <= c && c <= 0x1F91C) - || (0x1F91E <= c && c <= 0x1F91F) - || c == 0x1F926 - || (0x1F930 <= c && c <= 0x1F939) - || (0x1F93D <= c && c <= 0x1F93E) - || (0x1F9D1 <= c && c <= 0x1F9DD)); - } else { - return false; + // These two characters were removed from Emoji_Modifier_Base in Emoji 4.0, but we need to keep + // them as emoji modifier bases since there are fonts and user-generated text out there that + // treats these as potential emoji bases. + if (c == 0x1F91D || c == 0x1F93C) { + return true; } + // Emoji Modifier Base characters new in Unicode emoji 5.0. + // From http://www.unicode.org/Public/emoji/5.0/emoji-data.txt + // TODO: Remove once emoji-data.text 5.0 is in ICU or update to 6.0. + if (c == 0x1F91F + || (0x1F931 <= c && c <= 0x1F932) + || (0x1F9D1 <= c && c <= 0x1F9DD)) { + return true; + } + return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER_BASE); } hb_blob_t* getFontTable(const MinikinFont* minikinFont, uint32_t tag) { diff --git a/engine/src/flutter/libs/minikin/unicode_emoji_h_gen.py b/engine/src/flutter/libs/minikin/unicode_emoji_h_gen.py deleted file mode 100644 index 51864551884..00000000000 --- a/engine/src/flutter/libs/minikin/unicode_emoji_h_gen.py +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env python -# -# Copyright (C) 2016 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. -# -"""Generate header file for unicode data.""" - -import optparse -import sys - - -UNICODE_EMOJI_TEMPLATE=""" -/* file generated by frameworks/minikin/lib/minikin/Android.mk */ -#ifndef MINIKIN_UNICODE_EMOJI_H -#define MINIKIN_UNICODE_EMOJI_H - -#include - -namespace minikin { -namespace generated { - -int32_t EMOJI_LIST[] = { -@@@EMOJI_DATA@@@ -}; - -} // namespace generated -} // namespace minikin - -#endif // MINIKIN_UNICODE_EMOJI_H -""" - - -def _create_opt_parser(): - parser = optparse.OptionParser() - parser.add_option('-i', '--input', type='str', action='store', - help='path to input emoji-data.txt') - parser.add_option('-o', '--output', type='str', action='store', - help='path to output UnicodeEmoji.h') - return parser - - -def _read_emoji_data(emoji_data_file_path): - result = [] - with open(emoji_data_file_path) as emoji_data_file: - for line in emoji_data_file: - if '#' in line: - line = line[:line.index('#')] # Drop comments. - if not line.strip(): - continue # Skip empty line. - - code_points, prop = line.split(';') - code_points = code_points.strip() - prop = prop.strip() - if prop != 'Emoji': - break # Only collect Emoji property code points - - if '..' in code_points: # code point range - cp_start, cp_end = code_points.split('..') - result.extend(xrange(int(cp_start, 16), int(cp_end, 16) + 1)) - else: - code_point = int(code_points, 16) - result.append(code_point) - return result - - -def _generate_header_contents(emoji_list): - INDENT = ' ' * 4 - JOINER = ', ' - - hex_list = ['0x%04X' % x for x in emoji_list] - lines = [] - tmp_line = '%s%s' % (INDENT, hex_list[0]) - for hex_str in hex_list[1:]: - if len(tmp_line) + len(JOINER) + len(hex_str) >= 100: - lines.append(tmp_line + ',') - tmp_line = '%s%s' % (INDENT, hex_str) - else: - tmp_line = '%s%s%s' % (tmp_line, JOINER, hex_str) - lines.append(tmp_line) - - template = UNICODE_EMOJI_TEMPLATE - template = template.replace('@@@EMOJI_DATA@@@', '\n'.join(lines)) - return template - - -if __name__ == '__main__': - opt_parser = _create_opt_parser() - opts, _ = opt_parser.parse_args() - - emoji_list = _read_emoji_data(opts.input) - header = _generate_header_contents(emoji_list) - with open(opts.output, 'w') as header_file: - header_file.write(header) - diff --git a/engine/src/flutter/tests/unittest/MinikinInternalTest.cpp b/engine/src/flutter/tests/unittest/MinikinInternalTest.cpp index e314dd1be5c..1d3ecd76b8a 100644 --- a/engine/src/flutter/tests/unittest/MinikinInternalTest.cpp +++ b/engine/src/flutter/tests/unittest/MinikinInternalTest.cpp @@ -16,6 +16,8 @@ #include +#include + #include "MinikinInternal.h" namespace minikin { @@ -23,12 +25,56 @@ namespace minikin { TEST(MinikinInternalTest, isEmojiTest) { EXPECT_TRUE(isEmoji(0x0023)); // NUMBER SIGN EXPECT_TRUE(isEmoji(0x0035)); // DIGIT FIVE + EXPECT_TRUE(isEmoji(0x2640)); // FEMALE SIGN + EXPECT_TRUE(isEmoji(0x2642)); // MALE SIGN + EXPECT_TRUE(isEmoji(0x2695)); // STAFF OF AESCULAPIUS EXPECT_TRUE(isEmoji(0x1F0CF)); // PLAYING CARD BLACK JOKER EXPECT_TRUE(isEmoji(0x1F1E9)); // REGIONAL INDICATOR SYMBOL LETTER D + EXPECT_TRUE(isEmoji(0x1F6F7)); // SLED + EXPECT_TRUE(isEmoji(0x1F9E6)); // SOCKS EXPECT_FALSE(isEmoji(0x0000)); // EXPECT_FALSE(isEmoji(0x0061)); // LATIN SMALL LETTER A + EXPECT_FALSE(isEmoji(0x1F93B)); // MODERN PENTATHLON + EXPECT_FALSE(isEmoji(0x1F946)); // RIFLE EXPECT_FALSE(isEmoji(0x29E3D)); // A han character. } +TEST(MinikinInternalTest, isEmojiModifierTest) { + EXPECT_TRUE(isEmojiModifier(0x1F3FB)); // EMOJI MODIFIER FITZPATRICK TYPE-1-2 + EXPECT_TRUE(isEmojiModifier(0x1F3FC)); // EMOJI MODIFIER FITZPATRICK TYPE-3 + EXPECT_TRUE(isEmojiModifier(0x1F3FD)); // EMOJI MODIFIER FITZPATRICK TYPE-4 + EXPECT_TRUE(isEmojiModifier(0x1F3FE)); // EMOJI MODIFIER FITZPATRICK TYPE-5 + EXPECT_TRUE(isEmojiModifier(0x1F3FF)); // EMOJI MODIFIER FITZPATRICK TYPE-6 + + EXPECT_FALSE(isEmojiModifier(0x0000)); // + EXPECT_FALSE(isEmojiModifier(0x1F3FA)); // AMPHORA + EXPECT_FALSE(isEmojiModifier(0x1F400)); // RAT + EXPECT_FALSE(isEmojiModifier(0x29E3D)); // A han character. +} + +TEST(MinikinInternalTest, isEmojiBaseTest) { + EXPECT_TRUE(isEmojiBase(0x261D)); // WHITE UP POINTING INDEX + EXPECT_TRUE(isEmojiBase(0x270D)); // WRITING HAND + EXPECT_TRUE(isEmojiBase(0x1F385)); // FATHER CHRISTMAS + EXPECT_TRUE(isEmojiBase(0x1F3C2)); // SNOWBOARDER + EXPECT_TRUE(isEmojiBase(0x1F3C7)); // HORSE RACING + EXPECT_TRUE(isEmojiBase(0x1F3CC)); // GOLFER + EXPECT_TRUE(isEmojiBase(0x1F574)); // MAN IN BUSINESS SUIT LEVITATING + EXPECT_TRUE(isEmojiBase(0x1F6CC)); // SLEEPING ACCOMMODATION + EXPECT_TRUE(isEmojiBase(0x1F91D)); // HANDSHAKE (removed from Emoji 4.0, but we need it) + EXPECT_TRUE(isEmojiBase(0x1F91F)); // I LOVE YOU HAND SIGN + EXPECT_TRUE(isEmojiBase(0x1F931)); // BREAST-FEEDING + EXPECT_TRUE(isEmojiBase(0x1F932)); // PALMS UP TOGETHER + EXPECT_TRUE(isEmojiBase(0x1F93C)); // WRESTLERS (removed from Emoji 4.0, but we need it) + EXPECT_TRUE(isEmojiBase(0x1F9D1)); // ADULT + EXPECT_TRUE(isEmojiBase(0x1F9DD)); // ELF + + EXPECT_FALSE(isEmojiBase(0x0000)); // + EXPECT_FALSE(isEmojiBase(0x261C)); // WHITE LEFT POINTING INDEX + EXPECT_FALSE(isEmojiBase(0x1F384)); // CHRISTMAS TREE + EXPECT_FALSE(isEmojiBase(0x1F9DE)); // GENIE + EXPECT_FALSE(isEmojiBase(0x29E3D)); // A han character. +} + } // namespace minikin From 8eb2df1a8e9d59b6914eca9691f1bab8f4efadce Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Fri, 17 Mar 2017 15:42:49 -0700 Subject: [PATCH 256/364] Remove workaround for line breaks around currency symbols This is now done properly in ICU so we no longer need to do it ourselves. Also updated some comments about emoji line-breaking. Test: Existings tests for this in Minikin continue to pass. Bug: 24959657 Bug: 27365282 Change-Id: I865ea9ba1e79a64409d84d2d30c121f740e35ad6 --- engine/src/flutter/libs/minikin/WordBreaker.cpp | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index 36a3e88b23e..3b9e956fe1d 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -83,23 +83,13 @@ static bool isBreakValid(const uint16_t* buf, size_t bufEnd, size_t i) { size_t next_offset = i; U16_NEXT(buf, next_offset, bufEnd, next_codepoint); - // Proposed change to LB24 from http://www.unicode.org/L2/L2016/16043r-line-break-pr-po.txt - // (AL | HL) × (PR | PO) - int32_t lineBreak = u_getIntPropertyValue(codePoint, UCHAR_LINE_BREAK); - if (lineBreak == U_LB_ALPHABETIC || lineBreak == U_LB_HEBREW_LETTER) { - lineBreak = u_getIntPropertyValue(next_codepoint, UCHAR_LINE_BREAK); - if (lineBreak == U_LB_PREFIX_NUMERIC || lineBreak == U_LB_POSTFIX_NUMERIC) { - return false; - } - } - - // Emoji ZWJ sequences. + // Rule LB8 for Emoji ZWJ sequences. We need to do this ourselves since we may have fresher + // emoji data than ICU does. if (codePoint == CHAR_ZWJ && isEmoji(next_codepoint)) { return false; } - // Proposed Rule LB30b from http://www.unicode.org/L2/L2016/16011r3-break-prop-emoji.pdf - // EB x EM + // Rule LB30b. We need to this ourselves since we may have fresher emoji data than ICU does. if (isEmojiModifier(next_codepoint)) { if (codePoint == 0xFE0F && prev_offset > 0) { // skip over emoji variation selector From aa928e61b75b0017f260f4a2994f6132318fd35e Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Fri, 17 Mar 2017 16:54:42 -0700 Subject: [PATCH 257/364] Relax requirement for text variation sequences Previously, we insisted that in order for us to claim that a text variation sequence is supported or to display it, it needs to be standardized already. Now we accept any character as the base of a text variation sequence and support it as far the font used to display it is not an emoji font. Also fix a typo in a font name. Test: Unit tests are updated and pass. Bug: 30874706 Change-Id: I9660ec43aeee84303cfb825352a7f5029d036dd6 --- .../flutter/libs/minikin/FontCollection.cpp | 46 +++---------------- engine/src/flutter/tests/unittest/Android.mk | 2 +- .../unittest/FontCollectionItemizeTest.cpp | 4 +- .../tests/unittest/FontCollectionTest.cpp | 13 ++++-- .../flutter/tests/unittest/FontFamilyTest.cpp | 2 +- 5 files changed, 18 insertions(+), 49 deletions(-) diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index a3d2d974e0e..962b95b4afc 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -41,42 +41,6 @@ static inline T max(T a, T b) { const uint32_t EMOJI_STYLE_VS = 0xFE0F; const uint32_t TEXT_STYLE_VS = 0xFE0E; -// See http://www.unicode.org/Public/9.0.0/ucd/StandardizedVariants.txt -// U+2640, U+2642, U+2695 are now in emoji category but not listed in above file, so added them by -// manual. -// Must be sorted. -const uint32_t EMOJI_STYLE_VS_BASES[] = { - 0x0023, 0x002A, 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, - 0x00A9, 0x00AE, 0x203C, 0x2049, 0x2122, 0x2139, 0x2194, 0x2195, 0x2196, 0x2197, 0x2198, 0x2199, - 0x21A9, 0x21AA, 0x231A, 0x231B, 0x2328, 0x23CF, 0x23ED, 0x23EE, 0x23EF, 0x23F1, 0x23F2, 0x23F8, - 0x23F9, 0x23FA, 0x24C2, 0x25AA, 0x25AB, 0x25B6, 0x25C0, 0x25FB, 0x25FC, 0x25FD, 0x25FE, 0x2600, - 0x2601, 0x2602, 0x2603, 0x2604, 0x260E, 0x2611, 0x2614, 0x2615, 0x2618, 0x261D, 0x2620, 0x2622, - 0x2623, 0x2626, 0x262A, 0x262E, 0x262F, 0x2638, 0x2639, 0x263A, 0x2640, 0x2642, 0x2648, 0x2649, - 0x264A, 0x264B, 0x264C, 0x264D, 0x264E, 0x264F, 0x2650, 0x2651, 0x2652, 0x2653, 0x2660, 0x2663, - 0x2665, 0x2666, 0x2668, 0x267B, 0x267F, 0x2692, 0x2693, 0x2694, 0x2695, 0x2696, 0x2697, 0x2699, - 0x269B, 0x269C, 0x26A0, 0x26A1, 0x26AA, 0x26AB, 0x26B0, 0x26B1, 0x26BD, 0x26BE, 0x26C4, 0x26C5, - 0x26C8, 0x26CF, 0x26D1, 0x26D3, 0x26D4, 0x26E9, 0x26EA, 0x26F0, 0x26F1, 0x26F2, 0x26F3, 0x26F4, - 0x26F5, 0x26F7, 0x26F8, 0x26F9, 0x26FA, 0x26FD, 0x2702, 0x2708, 0x2709, 0x270C, 0x270D, 0x270F, - 0x2712, 0x2714, 0x2716, 0x271D, 0x2721, 0x2733, 0x2734, 0x2744, 0x2747, 0x2757, 0x2763, 0x2764, - 0x27A1, 0x2934, 0x2935, 0x2B05, 0x2B06, 0x2B07, 0x2B1B, 0x2B1C, 0x2B50, 0x2B55, 0x3030, 0x303D, - 0x3297, 0x3299, 0x1F004, 0x1F170, 0x1F171, 0x1F17E, 0x1F17F, 0x1F202, 0x1F21A, 0x1F22F, 0x1F237, - 0x1F321, 0x1F324, 0x1F325, 0x1F326, 0x1F327, 0x1F328, 0x1F329, 0x1F32A, 0x1F32B, 0x1F32C, - 0x1F336, 0x1F37D, 0x1F396, 0x1F397, 0x1F399, 0x1F39A, 0x1F39B, 0x1F39E, 0x1F39F, 0x1F3CB, - 0x1F3CC, 0x1F3CD, 0x1F3CE, 0x1F3D4, 0x1F3D5, 0x1F3D6, 0x1F3D7, 0x1F3D8, 0x1F3D9, 0x1F3DA, - 0x1F3DB, 0x1F3DC, 0x1F3DD, 0x1F3DE, 0x1F3DF, 0x1F3F3, 0x1F3F5, 0x1F3F7, 0x1F43F, 0x1F441, - 0x1F4FD, 0x1F549, 0x1F54A, 0x1F56F, 0x1F570, 0x1F573, 0x1F574, 0x1F575, 0x1F576, 0x1F577, - 0x1F578, 0x1F579, 0x1F587, 0x1F58A, 0x1F58B, 0x1F58C, 0x1F58D, 0x1F590, 0x1F5A5, 0x1F5A8, - 0x1F5B1, 0x1F5B2, 0x1F5BC, 0x1F5C2, 0x1F5C3, 0x1F5C4, 0x1F5D1, 0x1F5D2, 0x1F5D3, 0x1F5DC, - 0x1F5DD, 0x1F5DE, 0x1F5E1, 0x1F5E3, 0x1F5E8, 0x1F5EF, 0x1F5F3, 0x1F5FA, 0x1F6CB, 0x1F6CD, - 0x1F6CE, 0x1F6CF, 0x1F6E0, 0x1F6E1, 0x1F6E2, 0x1F6E3, 0x1F6E4, 0x1F6E5, 0x1F6E9, 0x1F6F0, - 0x1F6F3, -}; - -static bool isEmojiStyleVSBase(uint32_t cp) { - const size_t length = sizeof(EMOJI_STYLE_VS_BASES) / sizeof(EMOJI_STYLE_VS_BASES[0]); - return std::binary_search(EMOJI_STYLE_VS_BASES, EMOJI_STYLE_VS_BASES + length, cp); -} - uint32_t FontCollection::sNextId = 0; FontCollection::FontCollection(std::shared_ptr&& typeface) : mMaxChar(0) { @@ -378,11 +342,13 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, } // Even if there is no cmap format 14 subtable entry for the given sequence, should return true - // for emoji + U+FE0E case since we have special fallback rule for the sequence. - if (isEmojiStyleVSBase(baseCodepoint) && variationSelector == TEXT_STYLE_VS) { + // for case since we have special fallback rule for the + // sequence. Note that we don't need to restrict this to already standardized variation + // sequences, since Unicode is adding variation sequences more frequently now and may even move + // towards allowing text and emoji variation selectors on any character. + if (variationSelector == TEXT_STYLE_VS) { for (size_t i = 0; i < mFamilies.size(); ++i) { - if (!mFamilies[i]->isColorEmojiFamily() && variationSelector == TEXT_STYLE_VS && - mFamilies[i]->hasGlyph(baseCodepoint, 0)) { + if (!mFamilies[i]->isColorEmojiFamily() && mFamilies[i]->hasGlyph(baseCodepoint, 0)) { return true; } } diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index 716fcc378d8..25406d08223 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -32,7 +32,7 @@ LOCAL_TEST_DATA := \ data/NoGlyphFont.ttf \ data/Regular.ttf \ data/TextEmojiFont.ttf \ - data/VarioationSelectorTest-Regular.ttf \ + data/VariationSelectorTest-Regular.ttf \ data/ZhHans.ttf \ data/ZhHant.ttf \ data/itemize.xml \ diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index aa142cccdcd..78bfa3b94d4 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -47,7 +47,7 @@ const char kTextEmojiFont[] = kTestFontDir "TextEmojiFont.ttf"; const char kMixedEmojiFont[] = kTestFontDir "ColorTextMixedEmojiFont.ttf"; const char kHasCmapFormat14Font[] = kTestFontDir "NoCmapFormat14.ttf"; -const char kNoCmapFormat14Font[] = kTestFontDir "VarioationSelectorTest-Regular.ttf"; +const char kNoCmapFormat14Font[] = kTestFontDir "VariationSelectorTest-Regular.ttf"; typedef ICUTestBase FontCollectionItemizeTest; @@ -667,7 +667,7 @@ TEST_F(FontCollectionItemizeTest, itemize_vs_sequence_but_no_base_char) { // kVSTestFont supports U+717D U+FE02 but doesn't support U+717D. // kVSTestFont should be selected for U+717D U+FE02 even if it does not support the base code // point. - const std::string kVSTestFont = kTestFontDir "VarioationSelectorTest-Regular.ttf"; + const std::string kVSTestFont = kTestFontDir "VariationSelectorTest-Regular.ttf"; std::vector> families; std::shared_ptr font(new MinikinFontForTest(kLatinFont)); diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index 100e2069752..bef1c63088e 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -38,7 +38,7 @@ namespace minikin { // U+717D U+FE02 (VS3) // U+717D U+E0102 (VS19) // U+717D U+E0103 (VS20) -const char kVsTestFont[] = kTestFontDir "/VarioationSelectorTest-Regular.ttf"; +const char kVsTestFont[] = kTestFontDir "/VariationSelectorTest-Regular.ttf"; void expectVSGlyphs(const FontCollection* fc, uint32_t codepoint, const std::set& vsSet) { for (uint32_t vs = 0xFE00; vs <= 0xE01EF; ++vs) { @@ -64,13 +64,13 @@ TEST(FontCollectionTest, hasVariationSelectorTest) { std::shared_ptr fc(new FontCollection(families)); EXPECT_FALSE(fc->hasVariationSelector(0x82A6, 0)); - expectVSGlyphs(fc.get(), 0x82A6, std::set({0xFE00, 0xE0100, 0xE0101, 0xE0102})); + expectVSGlyphs(fc.get(), 0x82A6, std::set({0xFE00, 0xFE0E, 0xE0100, 0xE0101, 0xE0102})); EXPECT_FALSE(fc->hasVariationSelector(0x845B, 0)); - expectVSGlyphs(fc.get(), 0x845B, std::set({0xFE01, 0xE0101, 0xE0102, 0xE0103})); + expectVSGlyphs(fc.get(), 0x845B, std::set({0xFE01, 0xFE0E, 0xE0101, 0xE0102, 0xE0103})); EXPECT_FALSE(fc->hasVariationSelector(0x537F, 0)); - expectVSGlyphs(fc.get(), 0x537F, std::set({})); + expectVSGlyphs(fc.get(), 0x537F, std::set({0xFE0E})); EXPECT_FALSE(fc->hasVariationSelector(0x717D, 0)); expectVSGlyphs(fc.get(), 0x717D, std::set({0xFE02, 0xE0102, 0xE0103})); @@ -99,10 +99,13 @@ TEST(FontCollectionTest, hasVariationSelectorTest_emoji) { EXPECT_TRUE(collection->hasVariationSelector(0x262E, 0xFE0E)); EXPECT_FALSE(collection->hasVariationSelector(0x262E, 0xFE0F)); + // Text font doesn't support U+1F3FD. Only the color emoji fonts has. So VS15 is not supported. + EXPECT_FALSE(collection->hasVariationSelector(0x1F3FD, 0xFE0E)); + // Text font doesn't have U+262F U+FE0E or even its base code point U+262F. EXPECT_FALSE(collection->hasVariationSelector(0x262F, 0xFE0E)); - // VS15/VS16 is only for emoji, should return false for not an emoji code point. + // None of the fonts support U+2229. EXPECT_FALSE(collection->hasVariationSelector(0x2229, 0xFE0E)); EXPECT_FALSE(collection->hasVariationSelector(0x2229, 0xFE0F)); diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 58a7bab5f69..0769aa43124 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -495,7 +495,7 @@ TEST_F(FontLanguagesTest, registerLanguageListTest) { // U+717D U+FE02 (VS3) // U+717D U+E0102 (VS19) // U+717D U+E0103 (VS20) -const char kVsTestFont[] = kTestFontDir "VarioationSelectorTest-Regular.ttf"; +const char kVsTestFont[] = kTestFontDir "VariationSelectorTest-Regular.ttf"; class FontFamilyTest : public ICUTestBase { public: From 6a5534a4373d441cae6f61663115fd784ba57b6d Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Wed, 22 Mar 2017 15:58:46 -0700 Subject: [PATCH 258/364] Remove unused functions. This CL is essentially reverting following changes: - "Serialize and deserialize supported axes." I4086fb887e13f872390b533584bce6f1d5598ea0 - "Make SparseBitSet serializable." I0463138adcf234739bb3ce1cdadf382021921f3e Bug: 36232655 Test: N/A Change-Id: I25c701e1805e92b01034142147a9925f86533819 --- .../src/flutter/include/minikin/FontFamily.h | 24 ------ .../flutter/include/minikin/SparseBitSet.h | 11 --- .../src/flutter/libs/minikin/FontFamily.cpp | 62 -------------- .../src/flutter/libs/minikin/SparseBitSet.cpp | 67 --------------- .../flutter/tests/perftests/FontFamily.cpp | 19 ----- .../flutter/tests/unittest/FontFamilyTest.cpp | 46 ---------- .../tests/unittest/SparseBitSetTest.cpp | 85 ------------------- 7 files changed, 314 deletions(-) diff --git a/engine/src/flutter/include/minikin/FontFamily.h b/engine/src/flutter/include/minikin/FontFamily.h index 18a75ee8ec0..babed732f51 100644 --- a/engine/src/flutter/include/minikin/FontFamily.h +++ b/engine/src/flutter/include/minikin/FontFamily.h @@ -126,23 +126,6 @@ public: FontFamily(int variant, std::vector&& fonts); FontFamily(uint32_t langId, int variant, std::vector&& fonts); - // The accelerator table won't be copied. Do not release the memory until the created FontFamily - // is destructed. - FontFamily(std::vector&& fonts, const uint8_t* acceleratorTable, size_t tableSize); - FontFamily(int variant, std::vector&& fonts, const uint8_t* acceleratorTable, - size_t tableSize); - FontFamily(uint32_t langId, int variant, std::vector&& fonts, - const uint8_t* acceleratorTable, size_t tableSize); - - ~FontFamily(); - - // Writes internal accelerator tables into the 'out' buffer. - // - // This method returns the number of bytes written to the buffer. By calling the method with - // 'out' set to nullptr, the method just returns the size needed, which the caller can then use - // for allocating a buffer for a second call. - size_t writeAcceleratorTable(uint8_t* out) const; - // TODO: Good to expose FontUtil.h. static bool analyzeStyle(const std::shared_ptr& typeface, int* weight, bool* italic); @@ -177,13 +160,6 @@ public: private: void computeCoverage(); - void readAcceleratorTable(const uint8_t* data, size_t size); - - size_t writeSupportedAxes(uint8_t* out) const; - - // Reads supported axes values from 'in' buffer. This method reads up to - // 'inSize' bytes and returns the number of bytes read. - size_t readSupportedAxes(const uint8_t* in, size_t inSize); uint32_t mLangId; int mVariant; diff --git a/engine/src/flutter/include/minikin/SparseBitSet.h b/engine/src/flutter/include/minikin/SparseBitSet.h index 491e68ae7fb..ba9d7797fb0 100644 --- a/engine/src/flutter/include/minikin/SparseBitSet.h +++ b/engine/src/flutter/include/minikin/SparseBitSet.h @@ -45,17 +45,6 @@ public: // inclusive of start, exclusive of end, laid out in a uint32 array. void initFromRanges(const uint32_t* ranges, size_t nRanges); - // Initializes the set with pre-calculted data. Returns false if the serialized data is invalid. - // Even if this function returns false, the internal data is cleared. - bool initFromBuffer(const uint8_t* data, size_t size); - - // Serialize the set and write into out. - // - // This method returns the number of bytes written to the buffer. By calling the method with - // 'out' set to nullptr, the method just returns the size needed, which the caller can then use - // for allocating a buffer for a second call. - size_t writeToBuffer(uint8_t* out) const; - // Determine whether the value is included in the set bool get(uint32_t ch) const { if (ch >= mMaxVal) return false; diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 076dff2bcc9..492db1e4f45 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -109,25 +109,6 @@ FontFamily::FontFamily(uint32_t langId, int variant, std::vector&& fonts) computeCoverage(); } -FontFamily::FontFamily(std::vector&& fonts, const uint8_t* acceleratorTable, size_t tableSize) - : FontFamily(0 /* variant */, std::move(fonts), acceleratorTable, tableSize) { -} - -FontFamily::FontFamily(int variant, std::vector&& fonts, const uint8_t* acceleratorTable, - size_t tableSize) - : FontFamily(FontLanguageListCache::kEmptyListId, variant, std::move(fonts), acceleratorTable, - tableSize) { -} - -FontFamily::FontFamily(uint32_t langId, int variant, std::vector&& fonts, - const uint8_t* acceleratorTable, size_t tableSize) - : mLangId(langId), mVariant(variant), mFonts(std::move(fonts)), mHasVSTable(false) { - readAcceleratorTable(acceleratorTable, tableSize); -} - -FontFamily::~FontFamily() { -} - bool FontFamily::analyzeStyle(const std::shared_ptr& typeface, int* weight, bool* italic) { android::AutoMutex _l(gMinikinLock); @@ -263,47 +244,4 @@ std::shared_ptr FontFamily::createFamilyWithVariation( return std::shared_ptr(new FontFamily(mLangId, mVariant, std::move(fonts))); } -size_t FontFamily::writeAcceleratorTable(uint8_t* out) const { - const size_t axesTableSize = writeSupportedAxes(out); - if (out != nullptr) { - out += axesTableSize; - } - const size_t coverageTableSize = mCoverage.writeToBuffer(out); - return axesTableSize + coverageTableSize; -} - -void FontFamily::readAcceleratorTable(const uint8_t* data, size_t size) { - const size_t readSize = readSupportedAxes(data, size); - data += readSize; - size -= readSize; - bool result = mCoverage.initFromBuffer(data, size); - LOG_ALWAYS_FATAL_IF(!result, "Failed to reconstruct accelerator table from buffer"); -} - -size_t FontFamily::writeSupportedAxes(uint8_t* out) const { - LOG_ALWAYS_FATAL_IF(mSupportedAxes.size() > 255, "System fonts may only use up to 255 axes."); - const uint8_t axesCount = static_cast(mSupportedAxes.size()); - if (out != nullptr) { - out[0] = axesCount; - AxisTag* axisTags = reinterpret_cast(out + 1); - for (const auto& tag : mSupportedAxes) { - *axisTags++ = tag; - } - } - const size_t axesSizeInbytes = sizeof(AxisTag) * axesCount; - return axesSizeInbytes + 1 /* 1 for axes count */; -} - -size_t FontFamily::readSupportedAxes(const uint8_t* in, size_t inSize) { - LOG_ALWAYS_FATAL_IF(inSize == 0); - const uint8_t axesCount = in[0]; - const size_t totalSize = sizeof(AxisTag) * axesCount + 1 /* 1 for axes Count */; - LOG_ALWAYS_FATAL_IF(inSize < totalSize); - const AxisTag* axisTags = reinterpret_cast(in + 1); - mSupportedAxes.clear(); - for (uint8_t i = 0; i < axesCount; ++i) { - mSupportedAxes.insert(axisTags[i]); - } - return totalSize; -} } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/SparseBitSet.cpp b/engine/src/flutter/libs/minikin/SparseBitSet.cpp index a95af4d716f..51557df9af4 100644 --- a/engine/src/flutter/libs/minikin/SparseBitSet.cpp +++ b/engine/src/flutter/libs/minikin/SparseBitSet.cpp @@ -118,73 +118,6 @@ void SparseBitSet::initFromRanges(const uint32_t* ranges, size_t nRanges) { mIndices = indices; } -struct SparseBitSetHeader { - uint32_t maxValue; - uint32_t zeroPageIndex; - uint32_t indexSize; - uint32_t bitmapSize; -}; - -bool SparseBitSet::initFromBuffer(const uint8_t* data, size_t size) { - // No need to be concerned about endianness here since Intel x86 CPUs are little-endian. ARM - // CPUs are bi-endian but the endianness is only changeable at reset time and is impossible to - // change at runtime. Thus incoming data is guaranteed to have the same endianness as when it - // was created. - - if (data == nullptr || size < sizeof(SparseBitSetHeader)) { - clear(); - return false; - } - - // The serialized data starts with SparseBitSetHeader. - const SparseBitSetHeader* header = reinterpret_cast(data); - mMaxVal = header->maxValue; - mZeroPageIndex = header->zeroPageIndex; - mIndexSize = header->indexSize; - mBitmapSize = header->bitmapSize; - - mOwnIndicesAndBitmaps = false; - if (mIndexSize == 0 || mBitmapSize == 0 || mMaxVal == 0) { - const bool isValidEmptyBitSet = (mIndexSize == 0 && mBitmapSize == 0 && mMaxVal == 0); - if (!isValidEmptyBitSet) { - clear(); - } - return isValidEmptyBitSet; - } - - const size_t indicesSizeInBytes = sizeof(mIndices[0]) * mIndexSize; - const size_t bitmapsSizeInBytes = sizeof(mBitmaps[0]) * mBitmapSize; - if (size != sizeof(SparseBitSetHeader) + indicesSizeInBytes + bitmapsSizeInBytes) { - clear(); - return false; - } - data += sizeof(SparseBitSetHeader); - mIndices = reinterpret_cast(data); - data += indicesSizeInBytes; - mBitmaps = reinterpret_cast(data); - return true; -} - -size_t SparseBitSet::writeToBuffer(uint8_t* out) const{ - // See comments in SparseBitSet::initFromBuffer for the data structure. - const size_t indicesSizeInBytes = sizeof(mIndices[0]) * mIndexSize; - const size_t bitmapsSizeInBytes = sizeof(mBitmaps[0]) * mBitmapSize; - size_t necessarySize = sizeof(SparseBitSetHeader) + indicesSizeInBytes + bitmapsSizeInBytes; - if (out != nullptr) { - SparseBitSetHeader* header = reinterpret_cast(out); - header->maxValue = mMaxVal; - header->zeroPageIndex = mZeroPageIndex; - header->indexSize = mIndexSize; - header->bitmapSize = mBitmapSize; - - out += sizeof(SparseBitSetHeader); - memcpy(out, mIndices, indicesSizeInBytes); - out += indicesSizeInBytes; - memcpy(out, mBitmaps, bitmapsSizeInBytes); - } - return necessarySize; -} - int SparseBitSet::CountLeadingZeros(element x) { // Note: GCC / clang builtin return sizeof(element) <= sizeof(int) ? __builtin_clz(x) : __builtin_clzl(x); diff --git a/engine/src/flutter/tests/perftests/FontFamily.cpp b/engine/src/flutter/tests/perftests/FontFamily.cpp index a731ef640f3..9ab61e1fa7c 100644 --- a/engine/src/flutter/tests/perftests/FontFamily.cpp +++ b/engine/src/flutter/tests/perftests/FontFamily.cpp @@ -32,23 +32,4 @@ static void BM_FontFamily_create(benchmark::State& state) { BENCHMARK(BM_FontFamily_create); -static void BM_FontFamily_create_fromBuffer(benchmark::State& state) { - std::shared_ptr minikinFont = - std::make_shared("/system/fonts/NotoSansCJK-Regular.ttc", 0); - - std::shared_ptr family = std::make_shared( - std::vector({Font(minikinFont, FontStyle())})); - - size_t bufSize = family->writeAcceleratorTable(nullptr); - std::unique_ptr buffer(new uint8_t[bufSize]); - family->writeAcceleratorTable(buffer.get()); - - while (state.KeepRunning()) { - std::shared_ptr family = std::make_shared( - std::vector({Font(minikinFont, FontStyle())}), buffer.get(), bufSize); - } -} - -BENCHMARK(BM_FontFamily_create_fromBuffer); - } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 0769aa43124..90cc794083f 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -656,50 +656,4 @@ TEST_F(FontFamilyTest, createFamilyWithVariationTest) { } } -TEST_F(FontFamilyTest, supportedAxesRestoreFromSerializedBuffer) { - const char kFontPath[] = kTestFontDir "/MultiAxis.ttf"; - - std::shared_ptr font(new MinikinFontForTest(kFontPath)); - std::shared_ptr family = - std::make_shared(std::vector({Font(font, FontStyle())})); - - size_t necessaryBytes = family->writeAcceleratorTable(nullptr); - ASSERT_NE(0U, necessaryBytes); - std::vector buffer; - buffer.resize(necessaryBytes); - family->writeAcceleratorTable(buffer.data()); - - std::shared_ptr restoredMultiAxisFamily = - std::make_shared(std::vector({Font(font, FontStyle())}), - buffer.data(), buffer.size()); - - // This font has 'wdth' and 'wght' axes. - const std::unordered_set& supportedAxes = family->supportedAxes(); - ASSERT_EQ(2U, supportedAxes.size()); - EXPECT_NE(supportedAxes.end(), supportedAxes.find(MinikinFont::MakeTag('w', 'd', 't', 'h'))); - EXPECT_NE(supportedAxes.end(), supportedAxes.find(MinikinFont::MakeTag('w', 'g', 'h', 't'))); -} - -TEST_F(FontFamilyTest, supportedAxesRestoreFromSerializedBuffer_NoAxisFont) { - const char kFontPath[] = kTestFontDir "/Regular.ttf"; - - std::shared_ptr font(new MinikinFontForTest(kFontPath)); - std::shared_ptr family = - std::make_shared(std::vector({Font(font, FontStyle())})); - - size_t necessaryBytes = family->writeAcceleratorTable(nullptr); - ASSERT_NE(0U, necessaryBytes); - std::vector buffer; - buffer.resize(necessaryBytes); - family->writeAcceleratorTable(buffer.data()); - - std::shared_ptr restoredMultiAxisFamily = - std::make_shared(std::vector({Font(font, FontStyle())}), - buffer.data(), buffer.size()); - - // This font supports no axes. - const std::unordered_set& supportedAxes = family->supportedAxes(); - EXPECT_TRUE(supportedAxes.empty()); -} - } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp b/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp index ab38f6ca755..cfb437f3f5b 100644 --- a/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp +++ b/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp @@ -52,89 +52,4 @@ TEST(SparseBitSetTest, randomTest) { } } -TEST(SparseBitSetTest, randomTest_restoredFromBuffer) { - const uint32_t kTestRangeNum = 4096; - - std::mt19937 mt; // Fix seeds to be able to reproduce the result. - std::uniform_int_distribution distribution(1, 512); - - std::vector range { distribution(mt) }; - for (size_t i = 1; i < kTestRangeNum * 2; ++i) { - range.push_back((range.back() - 1) + distribution(mt)); - } - - SparseBitSet tmpBitset; - tmpBitset.initFromRanges(range.data(), range.size() / 2); - - size_t bufSize = tmpBitset.writeToBuffer(nullptr); - ASSERT_NE(0U, bufSize); - std::vector buffer(bufSize); - tmpBitset.writeToBuffer(buffer.data()); - - SparseBitSet bitset; - bitset.initFromBuffer(buffer.data(), buffer.size()); - - uint32_t ch = 0; - for (size_t i = 0; i < range.size() / 2; ++i) { - uint32_t start = range[i * 2]; - uint32_t end = range[i * 2 + 1]; - - for (; ch < start; ch++) { - ASSERT_FALSE(bitset.get(ch)) << std::hex << ch; - } - for (; ch < end; ch++) { - ASSERT_TRUE(bitset.get(ch)) << std::hex << ch; - } - } - for (; ch < 0x1FFFFFF; ++ch) { - ASSERT_FALSE(bitset.get(ch)) << std::hex << ch; - } -} - -TEST(SparseBitSetTest, emptyBitSet) { - SparseBitSet bitset; - uint32_t empty_bitset[4] = { - 0 /* max value */, 0 /* zero page index */, 0 /* index size */, 0 /* bitmap size */ - }; - EXPECT_TRUE(bitset.initFromBuffer( - reinterpret_cast(empty_bitset), sizeof(empty_bitset))); -} - -TEST(SparseBitSetTest, invalidData) { - SparseBitSet bitset; - EXPECT_FALSE(bitset.initFromBuffer(nullptr, 0)); - - // Buffer is too small. - uint32_t small_buffer[3] = { 0, 0, 0 }; - EXPECT_FALSE(bitset.initFromBuffer( - reinterpret_cast(small_buffer), sizeof(small_buffer))); - - // Buffer size does not match with necessary size. - uint32_t invalid_size_buffer[4] = { - 0x12345678 /* max value */, 0 /* zero page index */, 0x50 /* index size*/, - 0x80 /* bitmap size */ - }; - EXPECT_FALSE(bitset.initFromBuffer( - reinterpret_cast(invalid_size_buffer), sizeof(invalid_size_buffer))); - - // max value, index size, bitmap size must be zero if the bitset is empty. - uint32_t invalid_empty_bitset1[4] = { - 1 /* max value */, 0 /* zero page index */, 0 /* index size */, 0 /* bitmap size */ - }; - EXPECT_FALSE(bitset.initFromBuffer( - reinterpret_cast(invalid_empty_bitset1), sizeof(invalid_empty_bitset1))); - - uint32_t invalid_empty_bitset2[4] = { - 0 /* max value */, 0 /* zero page index */, 1 /* index size */, 0 /* bitmap size */ - }; - EXPECT_FALSE(bitset.initFromBuffer( - reinterpret_cast(invalid_empty_bitset2), sizeof(invalid_empty_bitset2))); - - uint32_t invalid_empty_bitset3[4] = { - 0 /* max value */, 0 /* zero page index */, 0 /* index size */, 1 /* bitmap size */ - }; - EXPECT_FALSE(bitset.initFromBuffer( - reinterpret_cast(invalid_empty_bitset3), sizeof(invalid_empty_bitset3))); -} - } // namespace minikin From bbffea58c5f6149e64868767b61f4d7fe3b8ea8e Mon Sep 17 00:00:00 2001 From: Dan Shi Date: Tue, 28 Mar 2017 16:10:05 -0700 Subject: [PATCH 259/364] Add test config to minikin_tests Design doc: Generalized Suites & the Unification of APCT & CTS Workflows Design/Roadmap https://docs.google.com/document/d/1eabK3srlBLouMiBMrNP3xJPiRRdcoCquNxC8gBWPvx8/edit#heading=h.78vup5eivwzo Details about test configs changes are tracked in doc https://docs.google.com/document/d/1EWUjJ7fjy8ge_Nk0YQbFdRp8DSHo3z6GU0R8jLgrAcw/edit# Bug: 35882476 Test: local test Change-Id: I0b1e0dc39975bc373685eb8adf1e297dc8f4c07a --- engine/src/flutter/tests/unittest/Android.mk | 1 + .../flutter/tests/unittest/AndroidTest.xml | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 engine/src/flutter/tests/unittest/AndroidTest.xml diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index 25406d08223..06ce61b8ee3 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -41,6 +41,7 @@ LOCAL_TEST_DATA := \ LOCAL_TEST_DATA := $(foreach f,$(LOCAL_TEST_DATA),frameworks/minikin/tests:$(f)) LOCAL_MODULE := minikin_tests +LOCAL_COMPATIBILITY_SUITE := device-tests LOCAL_MODULE_TAGS := tests LOCAL_MODULE_CLASS := NATIVE_TESTS diff --git a/engine/src/flutter/tests/unittest/AndroidTest.xml b/engine/src/flutter/tests/unittest/AndroidTest.xml new file mode 100644 index 00000000000..a0731014f1e --- /dev/null +++ b/engine/src/flutter/tests/unittest/AndroidTest.xml @@ -0,0 +1,26 @@ + + + + + + \ No newline at end of file From f0d9c2f52d2e01b9c77867ca05d5c501ccbf5d1e Mon Sep 17 00:00:00 2001 From: Dan Shi Date: Wed, 29 Mar 2017 12:11:51 -0700 Subject: [PATCH 260/364] Add test config to minikin_perftests Design doc: Generalized Suites & the Unification of APCT & CTS Workflows Design/Roadmap https://docs.google.com/document/d/1eabK3srlBLouMiBMrNP3xJPiRRdcoCquNxC8gBWPvx8/edit#heading=h.78vup5eivwzo Details about test configs changes are tracked in doc https://docs.google.com/document/d/1EWUjJ7fjy8ge_Nk0YQbFdRp8DSHo3z6GU0R8jLgrAcw/edit# Bug: 35882476 Test: local test Change-Id: I23366d56aaa7fbd22ed8233df0969a17e371c5a5 --- engine/src/flutter/tests/perftests/Android.mk | 1 + .../flutter/tests/perftests/AndroidTest.xml | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 engine/src/flutter/tests/perftests/AndroidTest.xml diff --git a/engine/src/flutter/tests/perftests/Android.mk b/engine/src/flutter/tests/perftests/Android.mk index c60123a83d7..aa18f8b27aa 100644 --- a/engine/src/flutter/tests/perftests/Android.mk +++ b/engine/src/flutter/tests/perftests/Android.mk @@ -31,6 +31,7 @@ perftest_src_files := \ include $(CLEAR_VARS) LOCAL_MODULE := minikin_perftests +LOCAL_COMPATIBILITY_SUITE := device-tests LOCAL_CPPFLAGS := -Werror -Wall -Wextra LOCAL_SRC_FILES := $(perftest_src_files) LOCAL_STATIC_LIBRARIES := \ diff --git a/engine/src/flutter/tests/perftests/AndroidTest.xml b/engine/src/flutter/tests/perftests/AndroidTest.xml new file mode 100644 index 00000000000..dcbdcf11cef --- /dev/null +++ b/engine/src/flutter/tests/perftests/AndroidTest.xml @@ -0,0 +1,26 @@ + + + + + + From 7708c89648451a69f6287c7dbc419865769fff59 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Thu, 30 Mar 2017 16:24:42 -0700 Subject: [PATCH 261/364] Remove unused classes and methods Removed Bitmap and MinikinFontFreeType classes, as well as the Layout::draw() method. The code was there for debugging purposes and for potential third-party users. We no longer support third-party uses of Minikin, since we don't know of any. Test: mmma -j frameworks/minikin builds with no errors Change-Id: Iddc9e8d35334053bd5255bccf3dbe5ba1eecf814 --- engine/src/flutter/include/minikin/Layout.h | 18 ---- .../src/flutter/include/minikin/MinikinFont.h | 2 - .../include/minikin/MinikinFontFreeType.h | 75 ------------- engine/src/flutter/libs/minikin/Android.mk | 2 - engine/src/flutter/libs/minikin/Layout.cpp | 67 ------------ .../libs/minikin/MinikinFontFreeType.cpp | 100 ------------------ engine/src/flutter/tests/unittest/Android.mk | 1 - 7 files changed, 265 deletions(-) delete mode 100644 engine/src/flutter/include/minikin/MinikinFontFreeType.h delete mode 100644 engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp diff --git a/engine/src/flutter/include/minikin/Layout.h b/engine/src/flutter/include/minikin/Layout.h index 8a6e7725d0a..6d1de2fbd2c 100644 --- a/engine/src/flutter/include/minikin/Layout.h +++ b/engine/src/flutter/include/minikin/Layout.h @@ -23,25 +23,9 @@ #include #include -#include namespace minikin { -// The Bitmap class is for debugging. We'll probably move it out -// of here into a separate lightweight software rendering module -// (optional, as we'd hope most clients would do their own) -class Bitmap { -public: - Bitmap(int width, int height); - ~Bitmap(); - void writePnm(std::ofstream& o) const; - void drawGlyph(const GlyphBitmap& bitmap, int x, int y); -private: - int width; - int height; - uint8_t* buf; -}; - struct LayoutGlyph { // index into mFaces and mHbFonts vectors. We could imagine // moving this into a run length representation, because it's @@ -95,8 +79,6 @@ public: int bidiFlags, const FontStyle &style, const MinikinPaint &paint, const std::shared_ptr& collection, float* advances); - void draw(minikin::Bitmap*, int x0, int y0, float size) const; - // public accessors size_t nGlyphs() const; const MinikinFont* getFont(int i) const; diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 52263f529a2..01af786aa68 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -81,8 +81,6 @@ struct MinikinRect { void join(const MinikinRect& r); }; -class MinikinFontFreeType; - // Callback for freeing data typedef void (*MinikinDestroyFunc) (void* data); diff --git a/engine/src/flutter/include/minikin/MinikinFontFreeType.h b/engine/src/flutter/include/minikin/MinikinFontFreeType.h deleted file mode 100644 index 37333e5f379..00000000000 --- a/engine/src/flutter/include/minikin/MinikinFontFreeType.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2013 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_FREETYPE_H -#define MINIKIN_FONT_FREETYPE_H - -#include -#include FT_FREETYPE_H -#include FT_TRUETYPE_TABLES_H - -#include - -// An abstraction for platform fonts, allowing Minikin to be used with -// multiple actual implementations of fonts. - -namespace minikin { - -struct GlyphBitmap { - uint8_t *buffer; - int width; - int height; - int left; - int top; -}; - -class MinikinFontFreeType : public MinikinFont { -public: - explicit MinikinFontFreeType(FT_Face typeface); - - ~MinikinFontFreeType(); - - float GetHorizontalAdvance(uint32_t glyph_id, - const MinikinPaint &paint) const; - - void GetBounds(MinikinRect* bounds, uint32_t glyph_id, - const MinikinPaint& paint) const; - - const void* GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy); - - const std::vector& GetAxes() const { - return mAxes; - } - - // TODO: provide access to raw data, as an optimization. - - // Not a virtual method, as the protocol to access rendered - // glyph bitmaps is probably different depending on the - // backend. - bool Render(uint32_t glyph_id, - const MinikinPaint &paint, GlyphBitmap *result); - - MinikinFontFreeType* GetFreeType(); - -private: - FT_Face mTypeface; - static int32_t sIdCounter; - std::vector mAxes; -}; - -} // namespace minikin - -#endif // MINIKIN_FONT_FREETYPE_H diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index be5301218ac..67a478a7c78 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -33,13 +33,11 @@ minikin_src_files := \ Measurement.cpp \ MinikinInternal.cpp \ MinikinFont.cpp \ - MinikinFontFreeType.cpp \ SparseBitSet.cpp \ WordBreaker.cpp minikin_c_includes := \ external/harfbuzz_ng/src \ - external/freetype/include \ frameworks/minikin/include \ $(intermediates) diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 0a318bdccd7..1f2fbc44570 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -39,7 +39,6 @@ #include "HbFontCache.h" #include "LayoutUtils.h" #include "MinikinInternal.h" -#include #include using std::string; @@ -47,44 +46,6 @@ using std::vector; namespace minikin { -Bitmap::Bitmap(int width, int height) : width(width), height(height) { - buf = new uint8_t[width * height](); -} - -Bitmap::~Bitmap() { - delete[] buf; -} - -void Bitmap::writePnm(std::ofstream &o) const { - o << "P5" << std::endl; - o << width << " " << height << std::endl; - o << "255" << std::endl; - o.write((const char *)buf, width * height); - o.close(); -} - -void Bitmap::drawGlyph(const GlyphBitmap& bitmap, int x, int y) { - int bmw = bitmap.width; - int bmh = bitmap.height; - x += bitmap.left; - y -= bitmap.top; - int x0 = std::max(0, x); - int x1 = std::min(width, x + bmw); - int y0 = std::max(0, y); - int y1 = std::min(height, y + bmh); - const unsigned char* src = bitmap.buffer + (y0 - y) * bmw + (x0 - x); - uint8_t* dst = buf + y0 * width; - for (int yy = y0; yy < y1; yy++) { - for (int xx = x0; xx < x1; xx++) { - int pixel = (int)dst[xx] + (int)src[xx - x]; - pixel = pixel > 0xff ? 0xff : pixel; - dst[xx] = pixel; - } - src += bmw; - dst += width; - } -} - const int kDirection_Mask = 0x1; struct LayoutContext { @@ -1091,34 +1052,6 @@ void Layout::appendLayout(Layout* src, size_t start, float extraAdvance) { } } -void Layout::draw(minikin::Bitmap* surface, int x0, int y0, float size) const { - /* - TODO: redo as MinikinPaint settings - if (mProps.hasTag(minikinHinting)) { - int hintflags = mProps.value(minikinHinting).getIntValue(); - if (hintflags & 1) load_flags |= FT_LOAD_NO_HINTING; - if (hintflags & 2) load_flags |= FT_LOAD_NO_AUTOHINT; - } - */ - for (size_t i = 0; i < mGlyphs.size(); i++) { - const LayoutGlyph& glyph = mGlyphs[i]; - MinikinFont* mf = mFaces[glyph.font_ix].font; - MinikinFontFreeType* face = static_cast(mf); - GlyphBitmap glyphBitmap; - MinikinPaint paint; - paint.size = size; - bool ok = face->Render(glyph.glyph_id, paint, &glyphBitmap); -#ifdef VERBOSE_DEBUG - ALOGD("glyphBitmap.width=%d, glyphBitmap.height=%d (%d, %d) x=%f, y=%f, ok=%d", - glyphBitmap.width, glyphBitmap.height, glyphBitmap.left, glyphBitmap.top, glyph.x, glyph.y, ok); -#endif - if (ok) { - surface->drawGlyph(glyphBitmap, - x0 + int(floor(glyph.x + 0.5)), y0 + int(floor(glyph.y + 0.5))); - } - } -} - size_t Layout::nGlyphs() const { return mGlyphs.size(); } diff --git a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp b/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp deleted file mode 100644 index 6f56a8dd55a..00000000000 --- a/engine/src/flutter/libs/minikin/MinikinFontFreeType.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2013 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. - */ - -// Implementation of MinikinFont abstraction specialized for FreeType - -#include - -#include -#include FT_FREETYPE_H -#include FT_TRUETYPE_TABLES_H -#include FT_ADVANCES_H - -#include - -namespace minikin { - -int32_t MinikinFontFreeType::sIdCounter = 0; - -MinikinFontFreeType::MinikinFontFreeType(FT_Face typeface) : - MinikinFont(sIdCounter++), - mTypeface(typeface) { -} - -MinikinFontFreeType::~MinikinFontFreeType() { - FT_Done_Face(mTypeface); -} - -float MinikinFontFreeType::GetHorizontalAdvance(uint32_t glyph_id, - const MinikinPaint &paint) const { - FT_Set_Pixel_Sizes(mTypeface, 0, paint.size); - FT_UInt32 flags = FT_LOAD_DEFAULT; // TODO: respect hinting settings - FT_Fixed advance; - FT_Get_Advance(mTypeface, glyph_id, flags, &advance); - return advance * (1.0 / 65536); -} - -void MinikinFontFreeType::GetBounds(MinikinRect* /* bounds */, uint32_t /* glyph_id*/, - const MinikinPaint& /* paint */) const { - // TODO: NYI -} - -const void* MinikinFontFreeType::GetTable(uint32_t tag, size_t* size, MinikinDestroyFunc* destroy) { - FT_ULong ftsize = 0; - FT_Error error = FT_Load_Sfnt_Table(mTypeface, tag, 0, nullptr, &ftsize); - if (error != 0) { - return nullptr; - } - FT_Byte* buf = reinterpret_cast(malloc(ftsize)); - if (buf == nullptr) { - return nullptr; - } - error = FT_Load_Sfnt_Table(mTypeface, tag, 0, buf, &ftsize); - if (error != 0) { - free(buf); - return nullptr; - } - *destroy = free; - *size = ftsize; - return buf; -} - -bool MinikinFontFreeType::Render(uint32_t glyph_id, const MinikinPaint& /* paint */, - GlyphBitmap *result) { - FT_Error error; - FT_Int32 load_flags = FT_LOAD_DEFAULT; // TODO: respect hinting settings - error = FT_Load_Glyph(mTypeface, glyph_id, load_flags); - if (error != 0) { - return false; - } - error = FT_Render_Glyph(mTypeface->glyph, FT_RENDER_MODE_NORMAL); - if (error != 0) { - return false; - } - FT_Bitmap &bitmap = mTypeface->glyph->bitmap; - result->buffer = bitmap.buffer; - result->width = bitmap.width; - result->height = bitmap.rows; - result->left = mTypeface->glyph->bitmap_left; - result->top = mTypeface->glyph->bitmap_top; - return true; -} - -MinikinFontFreeType* MinikinFontFreeType::GetFreeType() { - return this; -} - -} // namespace minikin diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index 25406d08223..eca0107397b 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -84,7 +84,6 @@ LOCAL_SRC_FILES += \ LOCAL_C_INCLUDES := \ $(LOCAL_PATH)/../../libs/minikin/ \ $(LOCAL_PATH)/../util \ - external/freetype/include \ external/harfbuzz_ng/src \ external/libxml2/include \ external/skia/src/core From d01462f7a1affe4d863e97d9d1f0986cf50af626 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Thu, 30 Mar 2017 19:54:00 -0700 Subject: [PATCH 262/364] Override the bidi properties of new emojis Test: new Minikin tests are added, and pass Bug: 32952475 Change-Id: Ibcae60d18d0cd5efd7556aaf58a716b6b59c8ee0 --- engine/src/flutter/include/minikin/Emoji.h | 34 ++++++++ engine/src/flutter/libs/minikin/Android.mk | 1 + engine/src/flutter/libs/minikin/Emoji.cpp | 77 +++++++++++++++++++ .../flutter/libs/minikin/FontCollection.cpp | 1 + .../flutter/libs/minikin/GraphemeBreak.cpp | 1 + engine/src/flutter/libs/minikin/Layout.cpp | 8 ++ .../flutter/libs/minikin/MinikinInternal.cpp | 42 ---------- .../flutter/libs/minikin/MinikinInternal.h | 9 --- .../src/flutter/libs/minikin/WordBreaker.cpp | 3 +- engine/src/flutter/tests/unittest/Android.mk | 2 +- ...{MinikinInternalTest.cpp => EmojiTest.cpp} | 16 +++- 11 files changed, 137 insertions(+), 57 deletions(-) create mode 100644 engine/src/flutter/include/minikin/Emoji.h create mode 100644 engine/src/flutter/libs/minikin/Emoji.cpp rename engine/src/flutter/tests/unittest/{MinikinInternalTest.cpp => EmojiTest.cpp} (85%) diff --git a/engine/src/flutter/include/minikin/Emoji.h b/engine/src/flutter/include/minikin/Emoji.h new file mode 100644 index 00000000000..28261735aaa --- /dev/null +++ b/engine/src/flutter/include/minikin/Emoji.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2014 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 + +namespace minikin { + +// Returns true if c is emoji. +bool isEmoji(uint32_t c); + +// Returns true if c is emoji modifier base. +bool isEmojiBase(uint32_t c); + +// Returns true if c is emoji modifier. +bool isEmojiModifier(uint32_t c); + +// Bidi override for ICU that knows about new emoji. +UCharDirection emojiBidiOverride(const void* context, UChar32 c); + +} // namespace minikin + diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk index 67a478a7c78..bb6234a123e 100644 --- a/engine/src/flutter/libs/minikin/Android.mk +++ b/engine/src/flutter/libs/minikin/Android.mk @@ -19,6 +19,7 @@ include $(CLEAR_VARS) include $(CLEAR_VARS) minikin_src_files := \ CmapCoverage.cpp \ + Emoji.cpp \ FontCollection.cpp \ FontFamily.cpp \ FontLanguage.cpp \ diff --git a/engine/src/flutter/libs/minikin/Emoji.cpp b/engine/src/flutter/libs/minikin/Emoji.cpp new file mode 100644 index 00000000000..fbe68ca8432 --- /dev/null +++ b/engine/src/flutter/libs/minikin/Emoji.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2014 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 + +namespace minikin { + +bool isNewEmoji(uint32_t c) { + // Emoji characters new in Unicode emoji 5.0. + // From http://www.unicode.org/Public/emoji/5.0/emoji-data.txt + // TODO: Remove once emoji-data.text 5.0 is in ICU or update to 6.0. + if (c < 0x1F6F7 || c > 0x1F9E6) { + // Optimization for characters outside the new emoji range. + return false; + } + return (0x1F6F7 <= c && c <= 0x1F6F8) + || c == 0x1F91F + || (0x1F928 <= c && c <= 0x1F92F) + || (0x1F931 <= c && c <= 0x1F932) + || c == 0x1F94C + || (0x1F95F <= c && c <= 0x1F96B) + || (0x1F992 <= c && c <= 0x1F997) + || (0x1F9D0 <= c && c <= 0x1F9E6); +} + +bool isEmoji(uint32_t c) { + return isNewEmoji(c) || u_hasBinaryProperty(c, UCHAR_EMOJI); +} + +bool isEmojiModifier(uint32_t c) { + // Emoji modifier are not expected to change, so there's a small change we need to customize + // this. + return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER); +} + +bool isEmojiBase(uint32_t c) { + // These two characters were removed from Emoji_Modifier_Base in Emoji 4.0, but we need to keep + // them as emoji modifier bases since there are fonts and user-generated text out there that + // treats these as potential emoji bases. + if (c == 0x1F91D || c == 0x1F93C) { + return true; + } + // Emoji Modifier Base characters new in Unicode emoji 5.0. + // From http://www.unicode.org/Public/emoji/5.0/emoji-data.txt + // TODO: Remove once emoji-data.text 5.0 is in ICU or update to 6.0. + if (c == 0x1F91F + || (0x1F931 <= c && c <= 0x1F932) + || (0x1F9D1 <= c && c <= 0x1F9DD)) { + return true; + } + return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER_BASE); +} + +UCharDirection emojiBidiOverride(const void* /* context */, UChar32 c) { + if (isNewEmoji(c)) { + // All new emoji characters in Unicode 10.0 are of the bidi class ON. + return U_OTHER_NEUTRAL; + } else { + return u_charDirection(c); + } +} + +} // namespace minikin + diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 962b95b4afc..02ed9dc623f 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -27,6 +27,7 @@ #include "FontLanguage.h" #include "FontLanguageListCache.h" #include "MinikinInternal.h" +#include #include using std::vector; diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index b1188e8d88e..87de4213f9c 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "MinikinInternal.h" namespace minikin { diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 1f2fbc44570..568e03876b6 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -39,6 +39,7 @@ #include "HbFontCache.h" #include "LayoutUtils.h" #include "MinikinInternal.h" +#include #include using std::string; @@ -522,6 +523,13 @@ BidiText::BidiText(const uint16_t* buf, size_t start, size_t count, size_t bufSi return; } UErrorCode status = U_ZERO_ERROR; + // Set callbacks to override bidi classes of new emoji + ubidi_setClassCallback(mBidi, emojiBidiOverride, nullptr, nullptr, nullptr, &status); + if (!U_SUCCESS(status)) { + ALOGE("error setting bidi callback function, status = %d", status); + return; + } + UBiDiLevel bidiReq = bidiFlags; if (bidiFlags == kBidi_Default_LTR) { bidiReq = UBIDI_DEFAULT_LTR; diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index 212ee26c0f8..88acc5061b0 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -20,7 +20,6 @@ #include "MinikinInternal.h" #include "HbFontCache.h" -#include #include namespace minikin { @@ -33,47 +32,6 @@ void assertMinikinLocked() { #endif } -bool isEmoji(uint32_t c) { - // Emoji characters new in Unicode emoji 5.0. - // From http://www.unicode.org/Public/emoji/5.0/emoji-data.txt - // TODO: Remove once emoji-data.text 5.0 is in ICU or update to 6.0. - if ((0x1F6F7 <= c && c <= 0x1F6F8) - || c == 0x1F91F - || (0x1F928 <= c && c <= 0x1F92F) - || (0x1F931 <= c && c <= 0x1F932) - || c == 0x1F94C - || (0x1F95F <= c && c <= 0x1F96B) - || (0x1F992 <= c && c <= 0x1F997) - || (0x1F9D0 <= c && c <= 0x1F9E6)) { - return true; - } - return u_hasBinaryProperty(c, UCHAR_EMOJI); -} - -bool isEmojiModifier(uint32_t c) { - // Emoji modifier are not expected to change, so there's a small change we need to customize - // this. - return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER); -} - -bool isEmojiBase(uint32_t c) { - // These two characters were removed from Emoji_Modifier_Base in Emoji 4.0, but we need to keep - // them as emoji modifier bases since there are fonts and user-generated text out there that - // treats these as potential emoji bases. - if (c == 0x1F91D || c == 0x1F93C) { - return true; - } - // Emoji Modifier Base characters new in Unicode emoji 5.0. - // From http://www.unicode.org/Public/emoji/5.0/emoji-data.txt - // TODO: Remove once emoji-data.text 5.0 is in ICU or update to 6.0. - if (c == 0x1F91F - || (0x1F931 <= c && c <= 0x1F932) - || (0x1F9D1 <= c && c <= 0x1F9DD)) { - return true; - } - return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER_BASE); -} - hb_blob_t* getFontTable(const MinikinFont* minikinFont, uint32_t tag) { assertMinikinLocked(); hb_font_t* font = getHbFontLocked(minikinFont); diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.h b/engine/src/flutter/libs/minikin/MinikinInternal.h index 365f20cc0df..250f63d74b2 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.h +++ b/engine/src/flutter/libs/minikin/MinikinInternal.h @@ -36,15 +36,6 @@ extern android::Mutex gMinikinLock; // Aborts if gMinikinLock is not acquired. Do nothing on the release build. void assertMinikinLocked(); -// Returns true if c is emoji. -bool isEmoji(uint32_t c); - -// Returns true if c is emoji modifier base. -bool isEmojiBase(uint32_t c); - -// Returns true if c is emoji modifier. -bool isEmojiModifier(uint32_t c); - hb_blob_t* getFontTable(const MinikinFont* minikinFont, uint32_t tag); // An RAII wrapper for hb_blob_t diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index 3b9e956fe1d..16edca7d6e8 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -18,8 +18,9 @@ #include -#include +#include #include +#include #include "MinikinInternal.h" #include diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index eca0107397b..d30c1062cec 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -66,13 +66,13 @@ LOCAL_SRC_FILES += \ ../util/FontTestUtils.cpp \ ../util/MinikinFontForTest.cpp \ ../util/UnicodeUtils.cpp \ + EmojiTest.cpp \ FontCollectionTest.cpp \ FontCollectionItemizeTest.cpp \ FontFamilyTest.cpp \ FontLanguageListCacheTest.cpp \ HbFontCacheTest.cpp \ HyphenatorTest.cpp \ - MinikinInternalTest.cpp \ GraphemeBreakTests.cpp \ LayoutTest.cpp \ LayoutUtilsTest.cpp \ diff --git a/engine/src/flutter/tests/unittest/MinikinInternalTest.cpp b/engine/src/flutter/tests/unittest/EmojiTest.cpp similarity index 85% rename from engine/src/flutter/tests/unittest/MinikinInternalTest.cpp rename to engine/src/flutter/tests/unittest/EmojiTest.cpp index 1d3ecd76b8a..e7d0f56f499 100644 --- a/engine/src/flutter/tests/unittest/MinikinInternalTest.cpp +++ b/engine/src/flutter/tests/unittest/EmojiTest.cpp @@ -18,11 +18,11 @@ #include -#include "MinikinInternal.h" +#include namespace minikin { -TEST(MinikinInternalTest, isEmojiTest) { +TEST(EmojiTest, isEmojiTest) { EXPECT_TRUE(isEmoji(0x0023)); // NUMBER SIGN EXPECT_TRUE(isEmoji(0x0035)); // DIGIT FIVE EXPECT_TRUE(isEmoji(0x2640)); // FEMALE SIGN @@ -40,7 +40,7 @@ TEST(MinikinInternalTest, isEmojiTest) { EXPECT_FALSE(isEmoji(0x29E3D)); // A han character. } -TEST(MinikinInternalTest, isEmojiModifierTest) { +TEST(EmojiTest, isEmojiModifierTest) { EXPECT_TRUE(isEmojiModifier(0x1F3FB)); // EMOJI MODIFIER FITZPATRICK TYPE-1-2 EXPECT_TRUE(isEmojiModifier(0x1F3FC)); // EMOJI MODIFIER FITZPATRICK TYPE-3 EXPECT_TRUE(isEmojiModifier(0x1F3FD)); // EMOJI MODIFIER FITZPATRICK TYPE-4 @@ -53,7 +53,7 @@ TEST(MinikinInternalTest, isEmojiModifierTest) { EXPECT_FALSE(isEmojiModifier(0x29E3D)); // A han character. } -TEST(MinikinInternalTest, isEmojiBaseTest) { +TEST(EmojiTest, isEmojiBaseTest) { EXPECT_TRUE(isEmojiBase(0x261D)); // WHITE UP POINTING INDEX EXPECT_TRUE(isEmojiBase(0x270D)); // WRITING HAND EXPECT_TRUE(isEmojiBase(0x1F385)); // FATHER CHRISTMAS @@ -77,4 +77,12 @@ TEST(MinikinInternalTest, isEmojiBaseTest) { EXPECT_FALSE(isEmojiBase(0x29E3D)); // A han character. } +TEST(EmojiTest, emojiBidiOverrideTest) { + EXPECT_EQ(U_RIGHT_TO_LEFT, emojiBidiOverride(nullptr, 0x05D0)); // HEBREW LETTER ALEF + EXPECT_EQ(U_LEFT_TO_RIGHT, + emojiBidiOverride(nullptr, 0x1F170)); // NEGATIVE SQUARED LATIN CAPITAL LETTER A + EXPECT_EQ(U_OTHER_NEUTRAL, emojiBidiOverride(nullptr, 0x1F6F7)); // SLED + EXPECT_EQ(U_OTHER_NEUTRAL, emojiBidiOverride(nullptr, 0x1F9E6)); // SOCKS +} + } // namespace minikin From cc8f7117d33f0b80cd11e4d189eba3861ef8b380 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Fri, 24 Mar 2017 16:57:20 -0700 Subject: [PATCH 263/364] Support cmap tables with platform ID == 0 Some fonts don't have cmap subtables of Microsoft Platform ID (3) and only have cmap subtables of Unicode Platform ID (0). Bug: 32505843 Test: minikin_unittest passed Test: android.graphics.cts.TypefaceTest passed Change-Id: I24aa49860790c0ae8d8e578efd728b95ec0f93ae --- .../flutter/include/minikin/CmapCoverage.h | 2 +- .../flutter/include/minikin/SparseBitSet.h | 33 +- .../src/flutter/libs/minikin/CmapCoverage.cpp | 180 ++++-- .../src/flutter/libs/minikin/FontFamily.cpp | 3 +- .../src/flutter/libs/minikin/SparseBitSet.cpp | 36 +- engine/src/flutter/tests/unittest/Android.mk | 8 +- .../tests/unittest/CmapCoverageTest.cpp | 586 ++++++++++++++++++ .../flutter/tests/unittest/FontFamilyTest.cpp | 44 +- .../tests/unittest/SparseBitSetTest.cpp | 3 +- 9 files changed, 780 insertions(+), 115 deletions(-) create mode 100644 engine/src/flutter/tests/unittest/CmapCoverageTest.cpp diff --git a/engine/src/flutter/include/minikin/CmapCoverage.h b/engine/src/flutter/include/minikin/CmapCoverage.h index 19b43f38de7..5136d8692a5 100644 --- a/engine/src/flutter/include/minikin/CmapCoverage.h +++ b/engine/src/flutter/include/minikin/CmapCoverage.h @@ -23,7 +23,7 @@ namespace minikin { class CmapCoverage { public: - static bool getCoverage(SparseBitSet &coverage, const uint8_t* cmap_data, size_t cmap_size, + static SparseBitSet getCoverage(const uint8_t* cmap_data, size_t cmap_size, bool* has_cmap_format14_subtable); }; diff --git a/engine/src/flutter/include/minikin/SparseBitSet.h b/engine/src/flutter/include/minikin/SparseBitSet.h index ba9d7797fb0..91288988ac7 100644 --- a/engine/src/flutter/include/minikin/SparseBitSet.h +++ b/engine/src/flutter/include/minikin/SparseBitSet.h @@ -31,19 +31,20 @@ namespace minikin { // of thousands to millions. It is particularly efficient when there are // large gaps. The motivating example is Unicode coverage of a font, but // the abstraction itself is fully general. - class SparseBitSet { public: - SparseBitSet(): mMaxVal(0), mOwnIndicesAndBitmaps(false) { - } - - // Clear the set - void clear(); + // Create an empty bit set. + SparseBitSet() : mMaxVal(0) {} // Initialize the set to a new value, represented by ranges. For // simplicity, these ranges are arranged as pairs of values, // inclusive of start, exclusive of end, laid out in a uint32 array. - void initFromRanges(const uint32_t* ranges, size_t nRanges); + SparseBitSet(const uint32_t* ranges, size_t nRanges) : SparseBitSet() { + initFromRanges(ranges, nRanges); + } + + SparseBitSet(SparseBitSet&&) = default; + SparseBitSet& operator=(SparseBitSet&&) = default; // Determine whether the value is included in the set bool get(uint32_t ch) const { @@ -65,6 +66,8 @@ public: static const uint32_t kNotFound = ~0u; private: + void initFromRanges(const uint32_t* ranges, size_t nRanges); + static const int kLogValuesPerPage = 8; static const int kPageMask = (1 << kLogValuesPerPage) - 1; static const int kLogBytesPerEl = 2; @@ -81,18 +84,14 @@ private: uint32_t mMaxVal; - // True if this SparseBitSet is responsible for freeing mIndices and mBitamps. - bool mOwnIndicesAndBitmaps; - - uint32_t mIndexSize; - const uint32_t* mIndices; - uint32_t mBitmapSize; - const element* mBitmaps; + std::unique_ptr mIndices; + std::unique_ptr mBitmaps; uint32_t mZeroPageIndex; -}; -// Note: this thing cannot be used in vectors yet. If that were important, we'd need to -// make the copy constructor work, and probably set up move traits as well. + // Forbid copy and assign. + SparseBitSet(const SparseBitSet&) = delete; + void operator=(const SparseBitSet&) = delete; +}; } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/CmapCoverage.cpp b/engine/src/flutter/libs/minikin/CmapCoverage.cpp index 6fa67155b45..ed053da7880 100644 --- a/engine/src/flutter/libs/minikin/CmapCoverage.cpp +++ b/engine/src/flutter/libs/minikin/CmapCoverage.cpp @@ -132,76 +132,146 @@ static bool getCoverageFormat12(vector& coverage, const uint8_t* data, return true; } -bool CmapCoverage::getCoverage(SparseBitSet& coverage, const uint8_t* cmap_data, size_t cmap_size, +// Lower value has higher priority. 0 for the highest priority table. +// kLowestPriority for unsupported tables. +// This order comes from HarfBuzz's hb-ot-font.cc and needs to be kept in sync with it. +constexpr uint8_t kLowestPriority = 255; +uint8_t getTablePriority(uint16_t platformId, uint16_t encodingId) { + if (platformId == 3 && encodingId == 10) { + return 0; + } + if (platformId == 0 && encodingId == 6) { + return 1; + } + if (platformId == 0 && encodingId == 4) { + return 2; + } + if (platformId == 3 && encodingId == 1) { + return 3; + } + if (platformId == 0 && encodingId == 3) { + return 4; + } + if (platformId == 0 && encodingId == 2) { + return 5; + } + if (platformId == 0 && encodingId == 1) { + return 6; + } + if (platformId == 0 && encodingId == 0) { + return 7; + } + // Tables other than above are not supported. + return kLowestPriority; +} + +SparseBitSet CmapCoverage::getCoverage(const uint8_t* cmap_data, size_t cmap_size, bool* has_cmap_format14_subtable) { - vector coverageVec; - const size_t kHeaderSize = 4; - const size_t kNumTablesOffset = 2; - const size_t kTableSize = 8; - const size_t kPlatformIdOffset = 0; - const size_t kEncodingIdOffset = 2; - const size_t kOffsetOffset = 4; - const uint16_t kUnicodePlatformId = 0; - const uint16_t kMicrosoftPlatformId = 3; - const uint16_t kUnicodeBmpEncodingId = 1; - const uint16_t kVariationSequencesEncodingId = 5; - const uint16_t kUnicodeUcs4EncodingId = 10; - const uint32_t kNoTable = UINT32_MAX; + constexpr size_t kHeaderSize = 4; + constexpr size_t kNumTablesOffset = 2; + constexpr size_t kTableSize = 8; + constexpr size_t kPlatformIdOffset = 0; + constexpr size_t kEncodingIdOffset = 2; + constexpr size_t kOffsetOffset = 4; + constexpr size_t kFormatOffset = 0; + constexpr uint32_t kInvalidOffset = UINT32_MAX; + if (kHeaderSize > cmap_size) { - return false; + return SparseBitSet(); } uint32_t numTables = readU16(cmap_data, kNumTablesOffset); if (kHeaderSize + numTables * kTableSize > cmap_size) { - return false; + return SparseBitSet(); } - uint32_t bestTable = kNoTable; - bool hasCmapFormat14Subtable = false; - for (uint32_t i = 0; i < numTables; i++) { - uint16_t platformId = readU16(cmap_data, kHeaderSize + i * kTableSize + kPlatformIdOffset); - uint16_t encodingId = readU16(cmap_data, kHeaderSize + i * kTableSize + kEncodingIdOffset); - if (platformId == kMicrosoftPlatformId && encodingId == kUnicodeUcs4EncodingId) { - bestTable = i; - break; - } else if (platformId == kMicrosoftPlatformId && encodingId == kUnicodeBmpEncodingId) { - bestTable = i; - } else if (platformId == kUnicodePlatformId && - encodingId == kVariationSequencesEncodingId) { - uint32_t offset = readU32(cmap_data, kHeaderSize + i * kTableSize + kOffsetOffset); - if (offset <= cmap_size - 2 && readU16(cmap_data, offset) == 14) { - hasCmapFormat14Subtable = true; + + uint32_t bestTableOffset = kInvalidOffset; + uint16_t bestTableFormat = 0; + uint8_t bestTablePriority = kLowestPriority; + *has_cmap_format14_subtable = false; + for (uint32_t i = 0; i < numTables; ++i) { + const uint32_t tableHeadOffset = kHeaderSize + i * kTableSize; + const uint16_t platformId = readU16(cmap_data, tableHeadOffset + kPlatformIdOffset); + const uint16_t encodingId = readU16(cmap_data, tableHeadOffset + kEncodingIdOffset); + const uint32_t offset = readU32(cmap_data, tableHeadOffset + kOffsetOffset); + + if (offset > cmap_size - 2) { + continue; // Invalid table: not enough space to read. + } + const uint16_t format = readU16(cmap_data, offset + kFormatOffset); + + if (platformId == 0 /* Unicode */ && encodingId == 5 /* Variation Sequences */) { + if (!(*has_cmap_format14_subtable) && format == 14) { + *has_cmap_format14_subtable = true; + } else { + // Ignore the (0, 5) table if we have already seen another valid one or it's in a + // format we don't understand. + } + } else { + uint32_t length; + uint32_t language; + + if (format == 4) { + constexpr size_t lengthOffset = 2; + constexpr size_t languageOffset = 4; + constexpr size_t minTableSize = languageOffset + 2; + if (offset > cmap_size - minTableSize) { + continue; // Invalid table: not enough space to read. + } + length = readU16(cmap_data, offset + lengthOffset); + language = readU16(cmap_data, offset + languageOffset); + } else if (format == 12) { + constexpr size_t lengthOffset = 4; + constexpr size_t languageOffset = 8; + constexpr size_t minTableSize = languageOffset + 4; + if (offset > cmap_size - minTableSize) { + continue; // Invalid table: not enough space to read. + } + length = readU32(cmap_data, offset + lengthOffset); + language = readU32(cmap_data, offset + languageOffset); + } else { + continue; + } + + if (length > cmap_size - offset) { + continue; // Invalid table: table length is larger than whole cmap data size. + } + if (language != 0) { + // Unsupported or invalid table: this is either a subtable for the Macintosh + // platform (which we don't support), or an invalid subtable since language field + // should be zero for non-Macintosh subtables. + continue; + } + const uint8_t priority = getTablePriority(platformId, encodingId); + if (priority < bestTablePriority) { + bestTableOffset = offset; + bestTablePriority = priority; + bestTableFormat = format; } } + if (*has_cmap_format14_subtable && bestTablePriority == 0 /* highest priority */) { + // Already found the highest priority table and variation sequences table. No need to + // look at remaining tables. + break; + } } - *has_cmap_format14_subtable = hasCmapFormat14Subtable; -#ifdef VERBOSE_DEBUG - ALOGD("best table = %d\n", bestTable); -#endif - if (bestTable == kNoTable) { - return false; + if (bestTableOffset == kInvalidOffset) { + return SparseBitSet(); } - uint32_t offset = readU32(cmap_data, kHeaderSize + bestTable * kTableSize + kOffsetOffset); - if (offset > cmap_size - 2) { - return false; - } - uint16_t format = readU16(cmap_data, offset); - bool success = false; - const uint8_t* tableData = cmap_data + offset; - const size_t tableSize = cmap_size - offset; - if (format == 4) { + const uint8_t* tableData = cmap_data + bestTableOffset; + const size_t tableSize = cmap_size - bestTableOffset; + vector coverageVec; + bool success; + if (bestTableFormat == 4) { success = getCoverageFormat4(coverageVec, tableData, tableSize); - } else if (format == 12) { + } else { success = getCoverageFormat12(coverageVec, tableData, tableSize); } if (success) { - coverage.initFromRanges(&coverageVec.front(), coverageVec.size() >> 1); + return SparseBitSet(&coverageVec.front(), coverageVec.size() >> 1); + } else { + return SparseBitSet(); } -#ifdef VERBOSE_DEBUG - for (size_t i = 0; i < coverageVec.size(); i += 2) { - ALOGD("%x:%x\n", coverageVec[i], coverageVec[i + 1]); - } - ALOGD("success = %d", success); -#endif - return success; + } } // namespace minikin diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 492db1e4f45..39d374b99db 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -175,8 +175,7 @@ void FontFamily::computeCoverage() { ALOGE("Could not get cmap table size!\n"); return; } - // TODO: Error check? - CmapCoverage::getCoverage(mCoverage, cmapTable.get(), cmapTable.size(), &mHasVSTable); + mCoverage = CmapCoverage::getCoverage(cmapTable.get(), cmapTable.size(), &mHasVSTable); for (size_t i = 0; i < mFonts.size(); ++i) { std::unordered_set supportedAxes = mFonts[i].getSupportedAxesLocked(); diff --git a/engine/src/flutter/libs/minikin/SparseBitSet.cpp b/engine/src/flutter/libs/minikin/SparseBitSet.cpp index 51557df9af4..28ae710c186 100644 --- a/engine/src/flutter/libs/minikin/SparseBitSet.cpp +++ b/engine/src/flutter/libs/minikin/SparseBitSet.cpp @@ -27,17 +27,6 @@ namespace minikin { const uint32_t SparseBitSet::kNotFound; -void SparseBitSet::clear() { - mMaxVal = 0; - if (mOwnIndicesAndBitmaps) { - delete[] mIndices; - delete[] mBitmaps; - mIndexSize = 0; - mBitmapSize = 0; - mOwnIndicesAndBitmaps = false; - } -} - uint32_t SparseBitSet::calcNumPages(const uint32_t* ranges, size_t nRanges) { bool haveZeroPage = false; uint32_t nonzeroPageEnd = 0; @@ -64,17 +53,12 @@ uint32_t SparseBitSet::calcNumPages(const uint32_t* ranges, size_t nRanges) { void SparseBitSet::initFromRanges(const uint32_t* ranges, size_t nRanges) { if (nRanges == 0) { - clear(); return; } mMaxVal = ranges[nRanges * 2 - 1]; - mIndexSize = (mMaxVal + kPageMask) >> kLogValuesPerPage; - uint32_t* indices = new uint32_t[mIndexSize]; + mIndices.reset(new uint32_t[(mMaxVal + kPageMask) >> kLogValuesPerPage]); uint32_t nPages = calcNumPages(ranges, nRanges); - mBitmapSize = nPages << (kLogValuesPerPage - kLogBitsPerEl); - element* bitmaps = new element[mBitmapSize]; - mOwnIndicesAndBitmaps = true; - memset(bitmaps, 0, nPages << (kLogValuesPerPage - 3)); + mBitmaps.reset(new element[nPages << (kLogValuesPerPage - kLogBitsPerEl)]()); mZeroPageIndex = noZeroPage; uint32_t nonzeroPageEnd = 0; uint32_t currentPage = 0; @@ -90,32 +74,30 @@ void SparseBitSet::initFromRanges(const uint32_t* ranges, size_t nRanges) { mZeroPageIndex = (currentPage++) << (kLogValuesPerPage - kLogBitsPerEl); } for (uint32_t j = nonzeroPageEnd; j < startPage; j++) { - indices[j] = mZeroPageIndex; + mIndices[j] = mZeroPageIndex; } } - indices[startPage] = (currentPage++) << (kLogValuesPerPage - kLogBitsPerEl); + mIndices[startPage] = (currentPage++) << (kLogValuesPerPage - kLogBitsPerEl); } size_t index = ((currentPage - 1) << (kLogValuesPerPage - kLogBitsPerEl)) + ((start & kPageMask) >> kLogBitsPerEl); size_t nElements = (end - (start & ~kElMask) + kElMask) >> kLogBitsPerEl; if (nElements == 1) { - bitmaps[index] |= (kElAllOnes >> (start & kElMask)) & + mBitmaps[index] |= (kElAllOnes >> (start & kElMask)) & (kElAllOnes << ((~end + 1) & kElMask)); } else { - bitmaps[index] |= kElAllOnes >> (start & kElMask); + mBitmaps[index] |= kElAllOnes >> (start & kElMask); for (size_t j = 1; j < nElements - 1; j++) { - bitmaps[index + j] = kElAllOnes; + mBitmaps[index + j] = kElAllOnes; } - bitmaps[index + nElements - 1] |= kElAllOnes << ((~end + 1) & kElMask); + mBitmaps[index + nElements - 1] |= kElAllOnes << ((~end + 1) & kElMask); } for (size_t j = startPage + 1; j < endPage + 1; j++) { - indices[j] = (currentPage++) << (kLogValuesPerPage - kLogBitsPerEl); + mIndices[j] = (currentPage++) << (kLogValuesPerPage - kLogBitsPerEl); } nonzeroPageEnd = endPage + 1; } - mBitmaps = bitmaps; - mIndices = indices; } int SparseBitSet::CountLeadingZeros(element x) { diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk index d30c1062cec..b817c46961c 100644 --- a/engine/src/flutter/tests/unittest/Android.mk +++ b/engine/src/flutter/tests/unittest/Android.mk @@ -19,8 +19,8 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_TEST_DATA := \ - data/BoldItalic.ttf \ data/Bold.ttf \ + data/BoldItalic.ttf \ data/ColorEmojiFont.ttf \ data/ColorTextMixedEmojiFont.ttf \ data/Emoji.ttf \ @@ -32,11 +32,14 @@ LOCAL_TEST_DATA := \ data/NoGlyphFont.ttf \ data/Regular.ttf \ data/TextEmojiFont.ttf \ + data/UnicodeBMPOnly.ttf \ + data/UnicodeBMPOnly2.ttf \ + data/UnicodeUCS4.ttf \ data/VariationSelectorTest-Regular.ttf \ data/ZhHans.ttf \ data/ZhHant.ttf \ + data/emoji.xml \ data/itemize.xml \ - data/emoji.xml LOCAL_TEST_DATA := $(foreach f,$(LOCAL_TEST_DATA),frameworks/minikin/tests:$(f)) @@ -66,6 +69,7 @@ LOCAL_SRC_FILES += \ ../util/FontTestUtils.cpp \ ../util/MinikinFontForTest.cpp \ ../util/UnicodeUtils.cpp \ + CmapCoverageTest.cpp \ EmojiTest.cpp \ FontCollectionTest.cpp \ FontCollectionItemizeTest.cpp \ diff --git a/engine/src/flutter/tests/unittest/CmapCoverageTest.cpp b/engine/src/flutter/tests/unittest/CmapCoverageTest.cpp new file mode 100644 index 00000000000..cbcc557a344 --- /dev/null +++ b/engine/src/flutter/tests/unittest/CmapCoverageTest.cpp @@ -0,0 +1,586 @@ +/* + * Copyright (C) 2017 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 + +#include +#include +#include +#include + +namespace minikin { + +size_t writeU16(uint16_t x, uint8_t* out, size_t offset) { + out[offset] = x >> 8; + out[offset + 1] = x; + return offset + 2; +} + +size_t writeI16(int16_t sx, uint8_t* out, size_t offset) { + return writeU16(static_cast(sx), out, offset); +} + +size_t writeU32(uint32_t x, uint8_t* out, size_t offset) { + out[offset] = x >> 24; + out[offset + 1] = x >> 16; + out[offset + 2] = x >> 8; + out[offset + 3] = x; + return offset + 4; +} + +// Returns valid cmap format 4 table contents. All glyph ID is same value as code point. (e.g. +// 'a' (U+0061) is mapped to Glyph ID = 0x0061). +// 'range' should be specified with inclusive-inclusive values. +static std::vector buildCmapFormat4Table(const std::vector& ranges) { + uint16_t segmentCount = ranges.size() / 2 + 1 /* +1 for end marker */; + + const size_t numOfUint16 = + 8 /* format, length, languages, segCountX2, searchRange, entrySelector, rangeShift, pad */ + + segmentCount * 4 /* endCount, startCount, idRange, idRangeOffset */; + const size_t finalLength = sizeof(uint16_t) * numOfUint16; + + std::vector out(finalLength); + size_t head = 0; + head = writeU16(4, out.data(), head); // format + head = writeU16(finalLength, out.data(), head); // length + head = writeU16(0, out.data(), head); // langauge + + const uint16_t searchRange = 2 * (1 << static_cast(floor(log2(segmentCount)))); + + head = writeU16(segmentCount * 2, out.data(), head); // segCountX2 + head = writeU16(searchRange, out.data(), head); // searchRange + head = writeU16(__builtin_ctz(searchRange) - 1, out.data(), head); // entrySelector + head = writeU16(segmentCount * 2 - searchRange, out.data(), head); // rangeShift + + size_t endCountHead = head; + size_t startCountHead = head + segmentCount * sizeof(uint16_t) + 2 /* padding */; + size_t idDeltaHead = startCountHead + segmentCount * sizeof(uint16_t); + size_t idRangeOffsetHead = idDeltaHead + segmentCount * sizeof(uint16_t); + + for (size_t i = 0; i < ranges.size() / 2; ++i) { + const uint16_t begin = ranges[i * 2]; + const uint16_t end = ranges[i * 2 + 1]; + startCountHead = writeU16(begin, out.data(), startCountHead); + endCountHead = writeU16(end, out.data(), endCountHead); + // map glyph ID as the same value of the code point. + idDeltaHead = writeU16(0, out.data(), idDeltaHead); + idRangeOffsetHead = writeU16(0 /* we don't use this */, out.data(), idRangeOffsetHead); + } + + // fill end marker + endCountHead = writeU16(0xFFFF, out.data(), endCountHead); + startCountHead = writeU16(0xFFFF, out.data(), startCountHead); + idDeltaHead = writeU16(1, out.data(), idDeltaHead); + idRangeOffsetHead = writeU16(0, out.data(), idRangeOffsetHead); + LOG_ALWAYS_FATAL_IF(endCountHead > finalLength); + LOG_ALWAYS_FATAL_IF(startCountHead > finalLength); + LOG_ALWAYS_FATAL_IF(idDeltaHead > finalLength); + LOG_ALWAYS_FATAL_IF(idRangeOffsetHead != finalLength); + return out; +} + +// Returns valid cmap format 4 table contents. All glyph ID is same value as code point. (e.g. +// 'a' (U+0061) is mapped to Glyph ID = 0x0061). +// 'range' should be specified with inclusive-inclusive values. +static std::vector buildCmapFormat12Table(const std::vector& ranges) { + uint32_t numGroups = ranges.size() / 2; + + const size_t finalLength = 2 /* format */ + 2 /* reserved */ + 4 /* length */ + + 4 /* languages */ + 4 /* numGroups */ + 12 /* size of a group */ * numGroups; + + std::vector out(finalLength); + size_t head = 0; + head = writeU16(12, out.data(), head); // format + head = writeU16(0, out.data(), head); // reserved + head = writeU32(finalLength, out.data(), head); // length + head = writeU32(0, out.data(), head); // langauge + head = writeU32(numGroups, out.data(), head); // numGroups + + for (uint32_t i = 0; i < numGroups; ++i) { + const uint32_t start = ranges[2 * i]; + const uint32_t end = ranges[2 * i + 1]; + head = writeU32(start, out.data(), head); + head = writeU32(end, out.data(), head); + // map glyph ID as the same value of the code point. + // TODO: Use glyph IDs lower than 65535. + // Cmap can store 32 bit glyph ID but due to the size of numGlyph, a font file can contain + // up to 65535 glyphs in a file. + head = writeU32(start, out.data(), head); + } + + LOG_ALWAYS_FATAL_IF(head != finalLength); + return out; +} + +class CmapBuilder { +public: + static constexpr size_t kEncodingTableHead = 4; + static constexpr size_t kEncodingTableSize = 8; + + CmapBuilder(int numTables) : mNumTables(numTables), mCurrentTableIndex(0) { + const size_t headerSize = + 2 /* version */ + 2 /* numTables */ + kEncodingTableSize * numTables; + out.resize(headerSize); + writeU16(0, out.data(), 0); + writeU16(numTables, out.data(), 2); + } + + void appendTable(uint16_t platformId, uint16_t encodingId, + const std::vector& table) { + appendEncodingTable(platformId, encodingId, out.size()); + out.insert(out.end(), table.begin(), table.end()); + } + + // TODO: Introduce Format 14 table builder. + + std::vector build() { + LOG_ALWAYS_FATAL_IF(mCurrentTableIndex != mNumTables); + return out; + } + + // Helper functions. + static std::vector buildSingleFormat4Cmap(uint16_t platformId, uint16_t encodingId, + const std::vector& ranges) { + CmapBuilder builder(1); + builder.appendTable(platformId, encodingId, buildCmapFormat4Table(ranges)); + return builder.build(); + } + + static std::vector buildSingleFormat12Cmap(uint16_t platformId, uint16_t encodingId, + const std::vector& ranges) { + CmapBuilder builder(1); + builder.appendTable(platformId, encodingId, buildCmapFormat12Table(ranges)); + return builder.build(); + } + +private: + void appendEncodingTable(uint16_t platformId, uint16_t encodingId, uint32_t offset) { + LOG_ALWAYS_FATAL_IF(mCurrentTableIndex == mNumTables); + + const size_t currentEncodingTableHead = + kEncodingTableHead + mCurrentTableIndex * kEncodingTableSize; + size_t head = writeU16(platformId, out.data(), currentEncodingTableHead); + head = writeU16(encodingId, out.data(), head); + head = writeU32(offset, out.data(), head); + LOG_ALWAYS_FATAL_IF((head - currentEncodingTableHead) != kEncodingTableSize); + mCurrentTableIndex++; + } + + int mNumTables; + int mCurrentTableIndex; + std::vector out; +}; + +TEST(CmapCoverageTest, SingleFormat4_brokenCmap) { + bool has_cmap_format_14_subtable = false; + { + SCOPED_TRACE("Reading beyond buffer size - Too small cmap size"); + std::vector cmap = + CmapBuilder::buildSingleFormat4Cmap(0, 0, std::vector({'a', 'a'})); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), 3 /* too small */, &has_cmap_format_14_subtable); + EXPECT_EQ(0U, coverage.length()); + EXPECT_FALSE(has_cmap_format_14_subtable); + } + { + SCOPED_TRACE("Reading beyond buffer size - space needed for tables goes beyond cmap size"); + std::vector cmap = + CmapBuilder::buildSingleFormat4Cmap(0, 0, std::vector({'a', 'a'})); + + writeU16(1000, cmap.data(), 2 /* offset of num tables in cmap header */); + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_EQ(0U, coverage.length()); + EXPECT_FALSE(has_cmap_format_14_subtable); + } + { + SCOPED_TRACE("Reading beyond buffer size - Invalid offset in encoding table"); + std::vector cmap = + CmapBuilder::buildSingleFormat4Cmap(0, 0, std::vector({'a', 'a'})); + + writeU16(1000, cmap.data(), 8 /* offset of the offset in the first encoding record */); + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_EQ(0U, coverage.length()); + EXPECT_FALSE(has_cmap_format_14_subtable); + } +} + +TEST(CmapCoverageTest, SingleFormat4) { + bool has_cmap_format_14_subtable = false; + struct TestCast { + std::string testTitle; + uint16_t platformId; + uint16_t encodingId; + } TEST_CASES[] = { + { "Platform 0, Encoding 0", 0, 0 }, + { "Platform 0, Encoding 1", 0, 1 }, + { "Platform 0, Encoding 2", 0, 2 }, + { "Platform 0, Encoding 3", 0, 3 }, + { "Platform 3, Encoding 1", 3, 1 }, + }; + + for (const auto& testCase : TEST_CASES) { + SCOPED_TRACE(testCase.testTitle.c_str()); + std::vector cmap = CmapBuilder::buildSingleFormat4Cmap( + testCase.platformId, testCase.encodingId, std::vector({'a', 'a'})); + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_TRUE(coverage.get('a')); + EXPECT_FALSE(coverage.get('b')); + EXPECT_FALSE(has_cmap_format_14_subtable); + } +} + +TEST(CmapCoverageTest, SingleFormat12) { + bool has_cmap_format_14_subtable = false; + + struct TestCast { + std::string testTitle; + uint16_t platformId; + uint16_t encodingId; + } TEST_CASES[] = { + { "Platform 0, Encoding 4", 0, 4 }, + { "Platform 0, Encoding 6", 0, 6 }, + { "Platform 3, Encoding 10", 3, 10 }, + }; + + for (const auto& testCase : TEST_CASES) { + SCOPED_TRACE(testCase.testTitle.c_str()); + std::vector cmap = CmapBuilder::buildSingleFormat12Cmap( + testCase.platformId, testCase.encodingId, std::vector({'a', 'a'})); + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_TRUE(coverage.get('a')); + EXPECT_FALSE(coverage.get('b')); + EXPECT_FALSE(has_cmap_format_14_subtable); + } +} + +TEST(CmapCoverageTest, notSupportedEncodings) { + bool has_cmap_format_14_subtable = false; + + struct TestCast { + std::string testTitle; + uint16_t platformId; + uint16_t encodingId; + } TEST_CASES[] = { + // Any encodings with platform 2 is not supported. + { "Platform 2, Encoding 0", 2, 0 }, + { "Platform 2, Encoding 1", 2, 1 }, + { "Platform 2, Encoding 2", 2, 2 }, + { "Platform 2, Encoding 3", 2, 3 }, + // UCS-2 or UCS-4 are supported on Platform == 3. Others are not supported. + { "Platform 3, Encoding 0", 3, 0 }, // Symbol + { "Platform 3, Encoding 2", 3, 2 }, // ShiftJIS + { "Platform 3, Encoding 3", 3, 3 }, // RPC + { "Platform 3, Encoding 4", 3, 4 }, // Big5 + { "Platform 3, Encoding 5", 3, 5 }, // Wansung + { "Platform 3, Encoding 6", 3, 6 }, // Johab + { "Platform 3, Encoding 7", 3, 7 }, // Reserved + { "Platform 3, Encoding 8", 3, 8 }, // Reserved + { "Platform 3, Encoding 9", 3, 9 }, // Reserved + // Uknown platforms + { "Platform 4, Encoding 0", 4, 0 }, + { "Platform 5, Encoding 1", 5, 1 }, + { "Platform 6, Encoding 0", 6, 0 }, + { "Platform 7, Encoding 1", 7, 1 }, + }; + + for (const auto& testCase : TEST_CASES) { + SCOPED_TRACE(testCase.testTitle.c_str()); + CmapBuilder builder(1); + std::vector cmap = CmapBuilder::buildSingleFormat4Cmap( + testCase.platformId, testCase.encodingId, std::vector({'a', 'a'})); + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_EQ(0U, coverage.length()); + EXPECT_FALSE(has_cmap_format_14_subtable); + } +} + +TEST(CmapCoverageTest, brokenFormat4Table) { + bool has_cmap_format_14_subtable = false; + { + SCOPED_TRACE("Too small table cmap size"); + std::vector table = buildCmapFormat4Table(std::vector({'a', 'a'})); + table.resize(2); // Remove trailing data. + + CmapBuilder builder(1); + builder.appendTable(0, 0, table); + std::vector cmap = builder.build(); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_EQ(0U, coverage.length()); + EXPECT_FALSE(has_cmap_format_14_subtable); + } + { + SCOPED_TRACE("Too many segments"); + std::vector table = buildCmapFormat4Table(std::vector({'a', 'a'})); + writeU16(5000, table.data(), 6 /* segment count offset */); // 5000 segments. + CmapBuilder builder(1); + builder.appendTable(0, 0, table); + std::vector cmap = builder.build(); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_EQ(0U, coverage.length()); + EXPECT_FALSE(has_cmap_format_14_subtable); + } + { + SCOPED_TRACE("Inversed range"); + std::vector table = buildCmapFormat4Table(std::vector({'b', 'b'})); + // Put smaller end code point to inverse the range. + writeU16('a', table.data(), 14 /* the first element of endCount offset */); + CmapBuilder builder(1); + builder.appendTable(0, 0, table); + std::vector cmap = builder.build(); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_EQ(0U, coverage.length()); + EXPECT_FALSE(has_cmap_format_14_subtable); + } +} + +TEST(CmapCoverageTest, brokenFormat12Table) { + bool has_cmap_format_14_subtable = false; + { + SCOPED_TRACE("Too small cmap size"); + std::vector table = buildCmapFormat12Table(std::vector({'a', 'a'})); + table.resize(2); // Remove trailing data. + + CmapBuilder builder(1); + builder.appendTable(0, 0, table); + std::vector cmap = builder.build(); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_EQ(0U, coverage.length()); + EXPECT_FALSE(has_cmap_format_14_subtable); + } + { + SCOPED_TRACE("Too many groups"); + std::vector table = buildCmapFormat12Table(std::vector({'a', 'a'})); + writeU32(5000, table.data(), 12 /* num group offset */); // 5000 groups. + + CmapBuilder builder(1); + builder.appendTable(0, 0, table); + std::vector cmap = builder.build(); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_EQ(0U, coverage.length()); + EXPECT_FALSE(has_cmap_format_14_subtable); + } + { + SCOPED_TRACE("Inversed range."); + std::vector table = buildCmapFormat12Table(std::vector({'a', 'a'})); + // Put larger start code point to inverse the range. + writeU32('b', table.data(), 16 /* start code point offset in the first group */); + + CmapBuilder builder(1); + builder.appendTable(0, 0, table); + std::vector cmap = builder.build(); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_EQ(0U, coverage.length()); + EXPECT_FALSE(has_cmap_format_14_subtable); + } +} + +TEST(CmapCoverageTest, TableSelection_Priority) { + bool has_cmap_format_14_subtable = false; + std::vector highestFormat12Table = + buildCmapFormat12Table(std::vector({'a', 'a'})); + std::vector highestFormat4Table = + buildCmapFormat4Table(std::vector({'a', 'a'})); + std::vector format4 = buildCmapFormat4Table(std::vector({'b', 'b'})); + std::vector format12 = buildCmapFormat12Table(std::vector({'b', 'b'})); + + { + SCOPED_TRACE("(platform, encoding) = (3, 10) is the highest priority."); + + struct LowerPriorityTable { + uint16_t platformId; + uint16_t encodingId; + const std::vector& table; + } LOWER_PRIORITY_TABLES[] = { + { 0, 0, format4 }, + { 0, 1, format4 }, + { 0, 2, format4 }, + { 0, 3, format4 }, + { 0, 4, format12 }, + { 0, 6, format12 }, + { 3, 1, format4 }, + }; + + for (const auto& table : LOWER_PRIORITY_TABLES) { + CmapBuilder builder(2); + builder.appendTable(table.platformId, table.encodingId, table.table); + builder.appendTable(3, 10, highestFormat12Table); + std::vector cmap = builder.build(); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_TRUE(coverage.get('a')); // comes from highest table + EXPECT_FALSE(coverage.get('b')); // should not use other table. + EXPECT_FALSE(has_cmap_format_14_subtable); + } + } + { + SCOPED_TRACE("(platform, encoding) = (3, 1) case"); + + struct LowerPriorityTable { + uint16_t platformId; + uint16_t encodingId; + const std::vector& table; + } LOWER_PRIORITY_TABLES[] = { + { 0, 0, format4 }, + { 0, 1, format4 }, + { 0, 2, format4 }, + { 0, 3, format4 }, + }; + + for (const auto& table : LOWER_PRIORITY_TABLES) { + CmapBuilder builder(2); + builder.appendTable(table.platformId, table.encodingId, table.table); + builder.appendTable(3, 1, highestFormat4Table); + std::vector cmap = builder.build(); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_TRUE(coverage.get('a')); // comes from highest table + EXPECT_FALSE(coverage.get('b')); // should not use other table. + EXPECT_FALSE(has_cmap_format_14_subtable); + } + } +} + +TEST(CmapCoverageTest, TableSelection_SkipBrokenFormat4Table) { + SparseBitSet coverage; + bool has_cmap_format_14_subtable = false; + std::vector validTable = + buildCmapFormat4Table(std::vector({'a', 'a'})); + { + SCOPED_TRACE("Unsupported format"); + CmapBuilder builder(2); + std::vector table = + buildCmapFormat4Table(std::vector({'b', 'b'})); + writeU16(0, table.data(), 0 /* format offset */); + builder.appendTable(3, 1, table); + builder.appendTable(0, 0, validTable); + std::vector cmap = builder.build(); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_TRUE(coverage.get('a')); // comes from valid table + EXPECT_FALSE(coverage.get('b')); // should not use invalid table. + EXPECT_FALSE(has_cmap_format_14_subtable); + } + { + SCOPED_TRACE("Invalid language"); + CmapBuilder builder(2); + std::vector table = + buildCmapFormat4Table(std::vector({'b', 'b'})); + writeU16(1, table.data(), 4 /* language offset */); + builder.appendTable(3, 1, table); + builder.appendTable(0, 0, validTable); + std::vector cmap = builder.build(); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_TRUE(coverage.get('a')); // comes from valid table + EXPECT_FALSE(coverage.get('b')); // should not use invalid table. + EXPECT_FALSE(has_cmap_format_14_subtable); + } + { + SCOPED_TRACE("Invalid length"); + CmapBuilder builder(2); + std::vector table = + buildCmapFormat4Table(std::vector({'b', 'b'})); + writeU16(5000, table.data(), 2 /* length offset */); + builder.appendTable(3, 1, table); + builder.appendTable(0, 0, validTable); + std::vector cmap = builder.build(); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_TRUE(coverage.get('a')); // comes from valid table + EXPECT_FALSE(coverage.get('b')); // should not use invalid table. + EXPECT_FALSE(has_cmap_format_14_subtable); + } +} + +TEST(CmapCoverageTest, TableSelection_SkipBrokenFormat12Table) { + SparseBitSet coverage; + bool has_cmap_format_14_subtable = false; + std::vector validTable = + buildCmapFormat12Table(std::vector({'a', 'a'})); + { + SCOPED_TRACE("Unsupported format"); + CmapBuilder builder(2); + std::vector table = + buildCmapFormat12Table(std::vector({'b', 'b'})); + writeU16(0, table.data(), 0 /* format offset */); + builder.appendTable(3, 1, table); + builder.appendTable(0, 0, validTable); + std::vector cmap = builder.build(); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_TRUE(coverage.get('a')); // comes from valid table + EXPECT_FALSE(coverage.get('b')); // should not use invalid table. + EXPECT_FALSE(has_cmap_format_14_subtable); + } + { + SCOPED_TRACE("Invalid language"); + CmapBuilder builder(2); + std::vector table = + buildCmapFormat12Table(std::vector({'b', 'b'})); + writeU32(1, table.data(), 8 /* language offset */); + builder.appendTable(3, 1, table); + builder.appendTable(0, 0, validTable); + std::vector cmap = builder.build(); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_TRUE(coverage.get('a')); // comes from valid table + EXPECT_FALSE(coverage.get('b')); // should not use invalid table. + EXPECT_FALSE(has_cmap_format_14_subtable); + } + { + SCOPED_TRACE("Invalid length"); + CmapBuilder builder(2); + std::vector table = + buildCmapFormat12Table(std::vector({'b', 'b'})); + writeU32(5000, table.data(), 4 /* length offset */); + builder.appendTable(3, 1, table); + builder.appendTable(0, 0, validTable); + std::vector cmap = builder.build(); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_TRUE(coverage.get('a')); // comes from valid table + EXPECT_FALSE(coverage.get('b')); // should not use invalid table. + EXPECT_FALSE(has_cmap_format_14_subtable); + } +} + +} // namespace minikin diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 90cc794083f..5a775a35875 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -45,6 +45,12 @@ static FontLanguage createFontLanguageWithoutICUSanitization(const std::string& return FontLanguage(input.c_str(), input.size()); } +std::shared_ptr makeFamily(const std::string& fontPath) { + std::shared_ptr font(new MinikinFontForTest(fontPath)); + return std::make_shared( + std::vector({Font(font, FontStyle())})); +} + TEST_F(FontLanguageTest, basicTests) { FontLanguage defaultLang; FontLanguage emptyLang("", 0); @@ -596,15 +602,8 @@ TEST_F(FontFamilyTest, createFamilyWithVariationTest) { const char kMultiAxisFont[] = kTestFontDir "/MultiAxis.ttf"; const char kNoAxisFont[] = kTestFontDir "/Regular.ttf"; - std::shared_ptr multiAxisFont(new MinikinFontForTest(kMultiAxisFont)); - std::shared_ptr multiAxisFamily( - std::shared_ptr(new FontFamily( - std::vector({Font(multiAxisFont, FontStyle())})))); - - std::shared_ptr noAxisFont(new MinikinFontForTest(kNoAxisFont)); - std::shared_ptr noAxisFamily( - std::shared_ptr(new FontFamily( - std::vector({Font(noAxisFont, FontStyle())})))); + std::shared_ptr multiAxisFamily = makeFamily(kMultiAxisFont); + std::shared_ptr noAxisFamily = makeFamily(kNoAxisFont); { // Do not ceate new instance if none of variations are specified. @@ -656,4 +655,31 @@ TEST_F(FontFamilyTest, createFamilyWithVariationTest) { } } +TEST_F(FontFamilyTest, coverageTableSelectionTest) { + // This font supports U+0061. The cmap subtable is format 4 and its platform ID is 0 and + // encoding ID is 1. + const char kUnicodeEncoding1Font[] = kTestFontDir "UnicodeBMPOnly.ttf"; + + // This font supports U+0061. The cmap subtable is format 4 and its platform ID is 0 and + // encoding ID is 3. + const char kUnicodeEncoding3Font[] = kTestFontDir "UnicodeBMPOnly2.ttf"; + + // This font has both cmap format 4 subtable which platform ID is 0 and encoding ID is 1 + // and cmap format 14 subtable which platform ID is 0 and encoding ID is 10. + // U+0061 is listed in both subtable but U+1F926 is only listed in latter. + const char kUnicodeEncoding4Font[] = kTestFontDir "UnicodeUCS4.ttf"; + + std::shared_ptr unicodeEnc1Font = makeFamily(kUnicodeEncoding1Font); + std::shared_ptr unicodeEnc3Font = makeFamily(kUnicodeEncoding3Font); + std::shared_ptr unicodeEnc4Font = makeFamily(kUnicodeEncoding4Font); + + android::AutoMutex _l(gMinikinLock); + + EXPECT_TRUE(unicodeEnc1Font->hasGlyph(0x0061, 0)); + EXPECT_TRUE(unicodeEnc3Font->hasGlyph(0x0061, 0)); + EXPECT_TRUE(unicodeEnc4Font->hasGlyph(0x0061, 0)); + + EXPECT_TRUE(unicodeEnc4Font->hasGlyph(0x1F926, 0)); +} + } // namespace minikin diff --git a/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp b/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp index cfb437f3f5b..39c9e1b9123 100644 --- a/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp +++ b/engine/src/flutter/tests/unittest/SparseBitSetTest.cpp @@ -32,8 +32,7 @@ TEST(SparseBitSetTest, randomTest) { range.push_back((range.back() - 1) + distribution(mt)); } - SparseBitSet bitset; - bitset.initFromRanges(range.data(), range.size() / 2); + SparseBitSet bitset(range.data(), range.size() / 2); uint32_t ch = 0; for (size_t i = 0; i < range.size() / 2; ++i) { From 97ee89d60507006b2988734e7fd44d9d16f99fb1 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Fri, 14 Apr 2017 11:08:12 -0700 Subject: [PATCH 264/364] Reduce heap memory in minikin. This patch reduces about 73 kB memory. The original SparseBitSet could contain full 32bit integers, but all of that is not necessary for Unicode code points. By reducing the supported range to up to Unicode maximum, U+10FFFF, we can save extra memory. SparseBitSet holds 256-bit sliced pages and indices of them. Previously, we needed to hold up to 2^24-1 pages for keeping 32-bit integers. This CL limits the number of pages to 2^16-1 (65535), so that SparseBitSet only supports 24-bit integers now, but this is sufficient for keeping all Unicode code points. With this change, we can change the index integer type from uint32_t to uint16_t. Bug: 37357593 Test: minikin_tests passes Change-Id: I462cc27927752c942ac5da0bf303a5afb81b87a3 --- .../flutter/include/minikin/SparseBitSet.h | 7 ++-- .../src/flutter/libs/minikin/CmapCoverage.cpp | 11 ++++++ .../flutter/libs/minikin/MinikinInternal.h | 2 + .../src/flutter/libs/minikin/SparseBitSet.cpp | 10 +++-- .../tests/unittest/CmapCoverageTest.cpp | 38 +++++++++++++++++++ 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/include/minikin/SparseBitSet.h b/engine/src/flutter/include/minikin/SparseBitSet.h index 91288988ac7..62aece209db 100644 --- a/engine/src/flutter/include/minikin/SparseBitSet.h +++ b/engine/src/flutter/include/minikin/SparseBitSet.h @@ -68,6 +68,7 @@ public: private: void initFromRanges(const uint32_t* ranges, size_t nRanges); + static const uint32_t kMaximumCapacity = 0xFFFFFF; static const int kLogValuesPerPage = 8; static const int kPageMask = (1 << kLogValuesPerPage) - 1; static const int kLogBytesPerEl = 2; @@ -77,16 +78,16 @@ private: typedef uint32_t element; static const element kElAllOnes = ~((element)0); static const element kElFirst = ((element)1) << kElMask; - static const uint32_t noZeroPage = ~0u; + static const uint16_t noZeroPage = 0xFFFF; static uint32_t calcNumPages(const uint32_t* ranges, size_t nRanges); static int CountLeadingZeros(element x); uint32_t mMaxVal; - std::unique_ptr mIndices; + std::unique_ptr mIndices; std::unique_ptr mBitmaps; - uint32_t mZeroPageIndex; + uint16_t mZeroPageIndex; // Forbid copy and assign. SparseBitSet(const SparseBitSet&) = delete; diff --git a/engine/src/flutter/libs/minikin/CmapCoverage.cpp b/engine/src/flutter/libs/minikin/CmapCoverage.cpp index ed053da7880..a953304e5bc 100644 --- a/engine/src/flutter/libs/minikin/CmapCoverage.cpp +++ b/engine/src/flutter/libs/minikin/CmapCoverage.cpp @@ -25,6 +25,7 @@ using std::vector; #include #include +#include "MinikinInternal.h" namespace minikin { @@ -127,6 +128,16 @@ static bool getCoverageFormat12(vector& coverage, const uint8_t* data, android_errorWriteLog(0x534e4554, "26413177"); return false; } + + // No need to read outside of Unicode code point range. + if (start > MAX_UNICODE_CODE_POINT) { + return true; + } + if (end > MAX_UNICODE_CODE_POINT) { + // file is inclusive, vector is exclusive + addRange(coverage, start, MAX_UNICODE_CODE_POINT + 1); + return true; + } addRange(coverage, start, end + 1); // file is inclusive, vector is exclusive } return true; diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.h b/engine/src/flutter/libs/minikin/MinikinInternal.h index 250f63d74b2..1ed08161887 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.h +++ b/engine/src/flutter/libs/minikin/MinikinInternal.h @@ -38,6 +38,8 @@ void assertMinikinLocked(); hb_blob_t* getFontTable(const MinikinFont* minikinFont, uint32_t tag); +constexpr uint32_t MAX_UNICODE_CODE_POINT = 0x10FFFF; + // An RAII wrapper for hb_blob_t class HbBlob { public: diff --git a/engine/src/flutter/libs/minikin/SparseBitSet.cpp b/engine/src/flutter/libs/minikin/SparseBitSet.cpp index 28ae710c186..9fad6a0cc77 100644 --- a/engine/src/flutter/libs/minikin/SparseBitSet.cpp +++ b/engine/src/flutter/libs/minikin/SparseBitSet.cpp @@ -55,8 +55,12 @@ void SparseBitSet::initFromRanges(const uint32_t* ranges, size_t nRanges) { if (nRanges == 0) { return; } - mMaxVal = ranges[nRanges * 2 - 1]; - mIndices.reset(new uint32_t[(mMaxVal + kPageMask) >> kLogValuesPerPage]); + const uint32_t maxVal = ranges[nRanges * 2 - 1]; + if (maxVal >= kMaximumCapacity) { + return; + } + mMaxVal = maxVal; + mIndices.reset(new uint16_t[(mMaxVal + kPageMask) >> kLogValuesPerPage]); uint32_t nPages = calcNumPages(ranges, nRanges); mBitmaps.reset(new element[nPages << (kLogValuesPerPage - kLogBitsPerEl)]()); mZeroPageIndex = noZeroPage; @@ -124,7 +128,7 @@ uint32_t SparseBitSet::nextSetBit(uint32_t fromIndex) const { } uint32_t maxPage = (mMaxVal + kPageMask) >> kLogValuesPerPage; for (uint32_t page = fromPage + 1; page < maxPage; page++) { - uint32_t index = mIndices[page]; + uint16_t index = mIndices[page]; if (index == mZeroPageIndex) { continue; } diff --git a/engine/src/flutter/tests/unittest/CmapCoverageTest.cpp b/engine/src/flutter/tests/unittest/CmapCoverageTest.cpp index cbcc557a344..dd61940868a 100644 --- a/engine/src/flutter/tests/unittest/CmapCoverageTest.cpp +++ b/engine/src/flutter/tests/unittest/CmapCoverageTest.cpp @@ -271,6 +271,34 @@ TEST(CmapCoverageTest, SingleFormat12) { } } +TEST(CmapCoverageTest, Format12_beyondTheUnicodeLimit) { + bool has_cmap_format_14_subtable = false; + { + SCOPED_TRACE("Starting range is out of Unicode code point. Should be ignored."); + std::vector cmap = CmapBuilder::buildSingleFormat12Cmap( + 0, 0, std::vector({'a', 'a', 0x110000, 0x110000})); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_TRUE(coverage.get('a')); + EXPECT_FALSE(coverage.get(0x110000)); + EXPECT_FALSE(has_cmap_format_14_subtable); + } + { + SCOPED_TRACE("Ending range is out of Unicode code point. Should be ignored."); + std::vector cmap = CmapBuilder::buildSingleFormat12Cmap( + 0, 0, std::vector({'a', 'a', 0x10FF00, 0x110000})); + + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_TRUE(coverage.get('a')); + EXPECT_TRUE(coverage.get(0x10FF00)); + EXPECT_TRUE(coverage.get(0x10FFFF)); + EXPECT_FALSE(coverage.get(0x110000)); + EXPECT_FALSE(has_cmap_format_14_subtable); + } +} + TEST(CmapCoverageTest, notSupportedEncodings) { bool has_cmap_format_14_subtable = false; @@ -398,6 +426,16 @@ TEST(CmapCoverageTest, brokenFormat12Table) { builder.appendTable(0, 0, table); std::vector cmap = builder.build(); + SparseBitSet coverage = CmapCoverage::getCoverage( + cmap.data(), cmap.size(), &has_cmap_format_14_subtable); + EXPECT_EQ(0U, coverage.length()); + EXPECT_FALSE(has_cmap_format_14_subtable); + } + { + SCOPED_TRACE("Too large code point"); + std::vector cmap = CmapBuilder::buildSingleFormat12Cmap( + 0, 0, std::vector({0x110000, 0x110000})); + SparseBitSet coverage = CmapCoverage::getCoverage( cmap.data(), cmap.size(), &has_cmap_format_14_subtable); EXPECT_EQ(0U, coverage.length()); From 716f07be94544d97039fbcb01df876e092d61d37 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 2 Dec 2016 17:59:14 -0800 Subject: [PATCH 265/364] Convert frameworks/minikin to Android.bp See build/soong/README.md for more information. Test: m -j checkbuild Change-Id: I71d3406054b35dd4e8ae30f46eec6cef77eef160 --- engine/src/flutter/Android.bp | 10 ++ engine/src/flutter/app/Android.bp | 30 ++++++ engine/src/flutter/app/Android.mk | 36 -------- engine/src/flutter/libs/minikin/Android.bp | 78 ++++++++++++++++ engine/src/flutter/libs/minikin/Android.mk | 102 --------------------- 5 files changed, 118 insertions(+), 138 deletions(-) create mode 100644 engine/src/flutter/Android.bp create mode 100644 engine/src/flutter/app/Android.bp delete mode 100644 engine/src/flutter/app/Android.mk create mode 100644 engine/src/flutter/libs/minikin/Android.bp delete mode 100644 engine/src/flutter/libs/minikin/Android.mk diff --git a/engine/src/flutter/Android.bp b/engine/src/flutter/Android.bp new file mode 100644 index 00000000000..26d5027683c --- /dev/null +++ b/engine/src/flutter/Android.bp @@ -0,0 +1,10 @@ +cc_library_headers { + name: "libminikin_headers", + host_supported: true, + export_include_dirs: ["include"], +} + +subdirs = [ + "app", + "libs/minikin", +] diff --git a/engine/src/flutter/app/Android.bp b/engine/src/flutter/app/Android.bp new file mode 100644 index 00000000000..e8085c1f3ea --- /dev/null +++ b/engine/src/flutter/app/Android.bp @@ -0,0 +1,30 @@ +// Copyright (C) 2015 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. + +// see how_to_run.txt for instructions on running these tests + +cc_binary_host { + name: "hyphtool", + + static_libs: ["libminikin"], + + // Shared libraries which are dependencies of minikin; these are not automatically + // pulled in by the build system (and thus sadly must be repeated). + shared_libs: [ + "liblog", + "libicuuc", + ], + + srcs: ["HyphTool.cpp"], +} diff --git a/engine/src/flutter/app/Android.mk b/engine/src/flutter/app/Android.mk deleted file mode 100644 index 23305b7b4c6..00000000000 --- a/engine/src/flutter/app/Android.mk +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2015 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. - -# see how_to_run.txt for instructions on running these tests - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := hyphtool -LOCAL_MODULE_TAGS := optional - -LOCAL_STATIC_LIBRARIES := libminikin_host - -# Shared libraries which are dependencies of minikin; these are not automatically -# pulled in by the build system (and thus sadly must be repeated). - -LOCAL_SHARED_LIBRARIES := \ - liblog \ - libicuuc - -LOCAL_SRC_FILES += \ - HyphTool.cpp - -include $(BUILD_HOST_EXECUTABLE) diff --git a/engine/src/flutter/libs/minikin/Android.bp b/engine/src/flutter/libs/minikin/Android.bp new file mode 100644 index 00000000000..ef721ea80b0 --- /dev/null +++ b/engine/src/flutter/libs/minikin/Android.bp @@ -0,0 +1,78 @@ +// Copyright (C) 2013 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. + +cc_library { + name: "libminikin", + host_supported: true, + srcs: [ + "Hyphenator.cpp", + ], + target: { + android: { + srcs: [ + "CmapCoverage.cpp", + "Emoji.cpp", + "FontCollection.cpp", + "FontFamily.cpp", + "FontLanguage.cpp", + "FontLanguageListCache.cpp", + "FontUtils.cpp", + "GraphemeBreak.cpp", + "HbFontCache.cpp", + "Layout.cpp", + "LayoutUtils.cpp", + "LineBreaker.cpp", + "Measurement.cpp", + "MinikinInternal.cpp", + "MinikinFont.cpp", + "SparseBitSet.cpp", + "WordBreaker.cpp", + ], + shared_libs: [ + "libharfbuzz_ng", + "libft2", + "libz", + "libutils", + ], + // TODO: clean up Minikin so it doesn't need the freetype include + export_shared_lib_headers: ["libft2"], + }, + }, + cppflags: [ + "-Werror", + "-Wall", + "-Wextra", + ], + product_variables: { + debuggable: { + // Enable race detection on eng and userdebug build. + cppflags: ["-DENABLE_RACE_DETECTION"], + }, + }, + shared_libs: [ + "liblog", + "libicuuc", + ], + header_libs: ["libminikin_headers"], + export_header_lib_headers: ["libminikin_headers"], + + clang: true, + sanitize: { + misc_undefined: [ + "signed-integer-overflow", + // b/26432628. + //"unsigned-integer-overflow", + ], + }, +} diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk deleted file mode 100644 index bb6234a123e..00000000000 --- a/engine/src/flutter/libs/minikin/Android.mk +++ /dev/null @@ -1,102 +0,0 @@ -# Copyright (C) 2013 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. - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -include $(CLEAR_VARS) -minikin_src_files := \ - CmapCoverage.cpp \ - Emoji.cpp \ - FontCollection.cpp \ - FontFamily.cpp \ - FontLanguage.cpp \ - FontLanguageListCache.cpp \ - FontUtils.cpp \ - GraphemeBreak.cpp \ - HbFontCache.cpp \ - Hyphenator.cpp \ - Layout.cpp \ - LayoutUtils.cpp \ - LineBreaker.cpp \ - Measurement.cpp \ - MinikinInternal.cpp \ - MinikinFont.cpp \ - SparseBitSet.cpp \ - WordBreaker.cpp - -minikin_c_includes := \ - external/harfbuzz_ng/src \ - frameworks/minikin/include \ - $(intermediates) - -minikin_shared_libraries := \ - libharfbuzz_ng \ - libft2 \ - liblog \ - libz \ - libicuuc \ - libutils - -ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT))) -# Enable race detection on eng and userdebug build. -enable_race_detection := -DENABLE_RACE_DETECTION -else -enable_race_detection := -endif - -LOCAL_MODULE := libminikin -LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include -LOCAL_SRC_FILES := $(minikin_src_files) -LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra $(enable_race_detection) -LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) -LOCAL_CLANG := true -LOCAL_SANITIZE := signed-integer-overflow -# b/26432628. -#LOCAL_SANITIZE += unsigned-integer-overflow - -include $(BUILD_SHARED_LIBRARY) - -include $(CLEAR_VARS) - -LOCAL_MODULE := libminikin -LOCAL_MODULE_TAGS := optional -LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include -LOCAL_SRC_FILES := $(minikin_src_files) -LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra $(enable_race_detection) -LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) -LOCAL_CLANG := true -LOCAL_SANITIZE := signed-integer-overflow -# b/26432628. -#LOCAL_SANITIZE += unsigned-integer-overflow - -include $(BUILD_STATIC_LIBRARY) - -include $(CLEAR_VARS) - -# Reduced library (currently just hyphenation) for host - -LOCAL_MODULE := libminikin_host -LOCAL_MODULE_TAGS := optional -LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include -LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra $(enable_race_detection) -LOCAL_SHARED_LIBRARIES := liblog libicuuc - -LOCAL_SRC_FILES := Hyphenator.cpp - -include $(BUILD_HOST_STATIC_LIBRARY) From befc483dfb21b58a9383541742598eda614d6bad Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 2 Dec 2016 17:59:14 -0800 Subject: [PATCH 266/364] Convert frameworks/minikin to Android.bp See build/soong/README.md for more information. Test: m -j checkbuild Change-Id: I71d3406054b35dd4e8ae30f46eec6cef77eef160 Merged-In: I71d3406054b35dd4e8ae30f46eec6cef77eef160 --- engine/src/flutter/Android.bp | 11 ++ engine/src/flutter/app/Android.bp | 30 +++++ engine/src/flutter/app/Android.mk | 36 ------ engine/src/flutter/libs/minikin/Android.bp | 89 ++++++++++++++ engine/src/flutter/libs/minikin/Android.mk | 116 ------------------ .../src/flutter/libs/minikin/emoji-data.txt | 1 + engine/src/flutter/sample/Android.bp | 53 ++++++++ engine/src/flutter/sample/Android.mk | 69 ----------- 8 files changed, 184 insertions(+), 221 deletions(-) create mode 100644 engine/src/flutter/Android.bp create mode 100644 engine/src/flutter/app/Android.bp delete mode 100644 engine/src/flutter/app/Android.mk create mode 100644 engine/src/flutter/libs/minikin/Android.bp delete mode 100644 engine/src/flutter/libs/minikin/Android.mk create mode 120000 engine/src/flutter/libs/minikin/emoji-data.txt create mode 100644 engine/src/flutter/sample/Android.bp delete mode 100644 engine/src/flutter/sample/Android.mk diff --git a/engine/src/flutter/Android.bp b/engine/src/flutter/Android.bp new file mode 100644 index 00000000000..b1a778c5630 --- /dev/null +++ b/engine/src/flutter/Android.bp @@ -0,0 +1,11 @@ +cc_library_headers { + name: "libminikin_headers", + host_supported: true, + export_include_dirs: ["include"], +} + +subdirs = [ + "app", + "libs/minikin", + "sample", +] diff --git a/engine/src/flutter/app/Android.bp b/engine/src/flutter/app/Android.bp new file mode 100644 index 00000000000..e8085c1f3ea --- /dev/null +++ b/engine/src/flutter/app/Android.bp @@ -0,0 +1,30 @@ +// Copyright (C) 2015 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. + +// see how_to_run.txt for instructions on running these tests + +cc_binary_host { + name: "hyphtool", + + static_libs: ["libminikin"], + + // Shared libraries which are dependencies of minikin; these are not automatically + // pulled in by the build system (and thus sadly must be repeated). + shared_libs: [ + "liblog", + "libicuuc", + ], + + srcs: ["HyphTool.cpp"], +} diff --git a/engine/src/flutter/app/Android.mk b/engine/src/flutter/app/Android.mk deleted file mode 100644 index 23305b7b4c6..00000000000 --- a/engine/src/flutter/app/Android.mk +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2015 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. - -# see how_to_run.txt for instructions on running these tests - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := hyphtool -LOCAL_MODULE_TAGS := optional - -LOCAL_STATIC_LIBRARIES := libminikin_host - -# Shared libraries which are dependencies of minikin; these are not automatically -# pulled in by the build system (and thus sadly must be repeated). - -LOCAL_SHARED_LIBRARIES := \ - liblog \ - libicuuc - -LOCAL_SRC_FILES += \ - HyphTool.cpp - -include $(BUILD_HOST_EXECUTABLE) diff --git a/engine/src/flutter/libs/minikin/Android.bp b/engine/src/flutter/libs/minikin/Android.bp new file mode 100644 index 00000000000..f7b2dea0570 --- /dev/null +++ b/engine/src/flutter/libs/minikin/Android.bp @@ -0,0 +1,89 @@ +// Copyright (C) 2013 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. + +// Generate unicode emoji data from UCD. +genrule { + name: "gen-emoji-header", + cmd: "python $(location unicode_emoji_h_gen.py) -i $(in) -o $(out)", + srcs: ["emoji-data.txt"], + out: ["generated/UnicodeData.h"], + tool_files: ["unicode_emoji_h_gen.py"], +} + +cc_library { + name: "libminikin", + host_supported: true, + srcs: [ + "Hyphenator.cpp", + ], + target: { + android: { + srcs: [ + "AnalyzeStyle.cpp", + "CmapCoverage.cpp", + "FontCollection.cpp", + "FontFamily.cpp", + "FontLanguage.cpp", + "FontLanguageListCache.cpp", + "GraphemeBreak.cpp", + "HbFontCache.cpp", + "Layout.cpp", + "LayoutUtils.cpp", + "LineBreaker.cpp", + "Measurement.cpp", + "MinikinInternal.cpp", + "MinikinRefCounted.cpp", + "MinikinFont.cpp", + "MinikinFontFreeType.cpp", + "SparseBitSet.cpp", + "WordBreaker.cpp", + ], + shared_libs: [ + "libharfbuzz_ng", + "libft2", + "libz", + "libutils", + ], + // TODO: clean up Minikin so it doesn't need the freetype include + export_shared_lib_headers: ["libft2"], + }, + }, + generated_headers: ["gen-emoji-header"], + cppflags: [ + "-Werror", + "-Wall", + "-Wextra", + ], + product_variables: { + debuggable: { + // Enable race detection on eng and userdebug build. + cppflags: ["-DENABLE_RACE_DETECTION"], + }, + }, + shared_libs: [ + "liblog", + "libicuuc", + ], + header_libs: ["libminikin_headers"], + export_header_lib_headers: ["libminikin_headers"], + + clang: true, + sanitize: { + misc_undefined: [ + "signed-integer-overflow", + // b/26432628. + //"unsigned-integer-overflow", + ], + }, +} diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk deleted file mode 100644 index d6c3df7f621..00000000000 --- a/engine/src/flutter/libs/minikin/Android.mk +++ /dev/null @@ -1,116 +0,0 @@ -# Copyright (C) 2013 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. - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) -# Generate unicode emoji data from UCD. -UNICODE_EMOJI_H_GEN_PY := $(LOCAL_PATH)/unicode_emoji_h_gen.py -UNICODE_EMOJI_DATA := $(TOP)/external/unicode/emoji-data.txt - -UNICODE_EMOJI_H := $(intermediates)/generated/UnicodeData.h -$(UNICODE_EMOJI_H): $(UNICODE_EMOJI_H_GEN_PY) $(UNICODE_EMOJI_DATA) -$(LOCAL_PATH)/MinikinInternal.cpp: $(UNICODE_EMOJI_H) -$(UNICODE_EMOJI_H): PRIVATE_CUSTOM_TOOL := python $(UNICODE_EMOJI_H_GEN_PY) \ - -i $(UNICODE_EMOJI_DATA) \ - -o $(UNICODE_EMOJI_H) -$(UNICODE_EMOJI_H): - $(transform-generated-source) - -include $(CLEAR_VARS) -minikin_src_files := \ - AnalyzeStyle.cpp \ - CmapCoverage.cpp \ - FontCollection.cpp \ - FontFamily.cpp \ - FontLanguage.cpp \ - FontLanguageListCache.cpp \ - GraphemeBreak.cpp \ - HbFontCache.cpp \ - Hyphenator.cpp \ - Layout.cpp \ - LayoutUtils.cpp \ - LineBreaker.cpp \ - Measurement.cpp \ - MinikinInternal.cpp \ - MinikinRefCounted.cpp \ - MinikinFont.cpp \ - MinikinFontFreeType.cpp \ - SparseBitSet.cpp \ - WordBreaker.cpp - -minikin_c_includes := \ - external/harfbuzz_ng/src \ - external/freetype/include \ - frameworks/minikin/include \ - $(intermediates) - -minikin_shared_libraries := \ - libharfbuzz_ng \ - libft2 \ - liblog \ - libz \ - libicuuc \ - libutils - -ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT))) -# Enable race detection on eng and userdebug build. -enable_race_detection := -DENABLE_RACE_DETECTION -else -enable_race_detection := -endif - -LOCAL_MODULE := libminikin -LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include -LOCAL_SRC_FILES := $(minikin_src_files) -LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra $(enable_race_detection) -LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) -LOCAL_CLANG := true -LOCAL_SANITIZE := signed-integer-overflow -# b/26432628. -#LOCAL_SANITIZE += unsigned-integer-overflow - -include $(BUILD_SHARED_LIBRARY) - -include $(CLEAR_VARS) - -LOCAL_MODULE := libminikin -LOCAL_MODULE_TAGS := optional -LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include -LOCAL_SRC_FILES := $(minikin_src_files) -LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra $(enable_race_detection) -LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) -LOCAL_CLANG := true -LOCAL_SANITIZE := signed-integer-overflow -# b/26432628. -#LOCAL_SANITIZE += unsigned-integer-overflow - -include $(BUILD_STATIC_LIBRARY) - -include $(CLEAR_VARS) - -# Reduced library (currently just hyphenation) for host - -LOCAL_MODULE := libminikin_host -LOCAL_MODULE_TAGS := optional -LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include -LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra $(enable_race_detection) -LOCAL_SHARED_LIBRARIES := liblog libicuuc - -LOCAL_SRC_FILES := Hyphenator.cpp - -include $(BUILD_HOST_STATIC_LIBRARY) diff --git a/engine/src/flutter/libs/minikin/emoji-data.txt b/engine/src/flutter/libs/minikin/emoji-data.txt new file mode 120000 index 00000000000..90161250c54 --- /dev/null +++ b/engine/src/flutter/libs/minikin/emoji-data.txt @@ -0,0 +1 @@ +../../../../external/unicode/emoji-data.txt \ No newline at end of file diff --git a/engine/src/flutter/sample/Android.bp b/engine/src/flutter/sample/Android.bp new file mode 100644 index 00000000000..208988969a9 --- /dev/null +++ b/engine/src/flutter/sample/Android.bp @@ -0,0 +1,53 @@ +// Copyright (C) 2013 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. + +cc_test { + name: "minikin_example", + gtest: false, + + srcs: ["example.cpp"], + + shared_libs: [ + "libutils", + "liblog", + "libcutils", + "libharfbuzz_ng", + "libicuuc", + "libft2", + "libpng", + "libz", + "libminikin", + ], +} + +cc_test { + name: "minikin_skia_example", + gtest: false, + + srcs: [ + "example_skia.cpp", + "MinikinSkia.cpp", + ], + + shared_libs: [ + "libutils", + "liblog", + "libcutils", + "libharfbuzz_ng", + "libicuuc", + "libskia", + "libminikin", + "libft2", + ], +} diff --git a/engine/src/flutter/sample/Android.mk b/engine/src/flutter/sample/Android.mk deleted file mode 100644 index c4a644d74d5..00000000000 --- a/engine/src/flutter/sample/Android.mk +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (C) 2013 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. - -LOCAL_PATH:= $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAGS := tests - -LOCAL_C_INCLUDES += \ - external/harfbuzz_ng/src \ - external/freetype/include \ - frameworks/minikin/include - -LOCAL_SRC_FILES:= example.cpp - -LOCAL_SHARED_LIBRARIES += \ - libutils \ - liblog \ - libcutils \ - libharfbuzz_ng \ - libicuuc \ - libft2 \ - libpng \ - libz \ - libminikin - -LOCAL_MODULE:= minikin_example - -include $(BUILD_EXECUTABLE) - - -include $(CLEAR_VARS) - -LOCAL_MODULE_TAG := tests - -LOCAL_C_INCLUDES += \ - external/harfbuzz_ng/src \ - external/freetype/include \ - frameworks/minikin/include \ - external/skia/src/core - -LOCAL_SRC_FILES:= example_skia.cpp \ - MinikinSkia.cpp - -LOCAL_SHARED_LIBRARIES += \ - libutils \ - liblog \ - libcutils \ - libharfbuzz_ng \ - libicuuc \ - libskia \ - libminikin \ - libft2 - -LOCAL_MODULE:= minikin_skia_example - -include $(BUILD_EXECUTABLE) From fa994b25d1885d67a317e685b2ea8e6bbfdfc655 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 25 Apr 2017 10:53:34 -0700 Subject: [PATCH 267/364] Convert frameworks/minikin/tests to Android.bp See build/soong/README.md for more information. Test: m -j checkbuild Change-Id: I930debdd129da7f61ac4b764980f73dfd487785d --- engine/src/flutter/Android.bp | 1 + engine/src/flutter/libs/minikin/Android.bp | 7 ++ engine/src/flutter/tests/Android.bp | 33 ++++++ engine/src/flutter/tests/perftests/Android.bp | 49 +++++++++ engine/src/flutter/tests/perftests/Android.mk | 53 --------- .../tests/perftests/FontCollection.cpp | 4 +- .../flutter/tests/perftests/GraphemeBreak.cpp | 2 +- .../flutter/tests/perftests/Hyphenator.cpp | 4 +- .../flutter/tests/perftests/WordBreaker.cpp | 2 +- .../src/flutter/tests/stresstest/Android.bp | 49 +++++++++ .../src/flutter/tests/stresstest/Android.mk | 56 ---------- engine/src/flutter/tests/unittest/Android.bp | 74 +++++++++++++ engine/src/flutter/tests/unittest/Android.mk | 101 ------------------ engine/src/flutter/tests/util/Android.bp | 13 +++ 14 files changed, 232 insertions(+), 216 deletions(-) create mode 100644 engine/src/flutter/tests/Android.bp create mode 100644 engine/src/flutter/tests/perftests/Android.bp delete mode 100644 engine/src/flutter/tests/perftests/Android.mk create mode 100644 engine/src/flutter/tests/stresstest/Android.bp delete mode 100644 engine/src/flutter/tests/stresstest/Android.mk create mode 100644 engine/src/flutter/tests/unittest/Android.bp delete mode 100644 engine/src/flutter/tests/unittest/Android.mk create mode 100644 engine/src/flutter/tests/util/Android.bp diff --git a/engine/src/flutter/Android.bp b/engine/src/flutter/Android.bp index 26d5027683c..e875a172b0a 100644 --- a/engine/src/flutter/Android.bp +++ b/engine/src/flutter/Android.bp @@ -7,4 +7,5 @@ cc_library_headers { subdirs = [ "app", "libs/minikin", + "tests", ] diff --git a/engine/src/flutter/libs/minikin/Android.bp b/engine/src/flutter/libs/minikin/Android.bp index ef721ea80b0..2489ba77492 100644 --- a/engine/src/flutter/libs/minikin/Android.bp +++ b/engine/src/flutter/libs/minikin/Android.bp @@ -12,6 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +cc_library_headers { + name: "libminikin-headers-for-tests", + export_include_dirs: ["."], + shared_libs: ["libharfbuzz_ng"], + export_shared_lib_headers: ["libharfbuzz_ng"], +} + cc_library { name: "libminikin", host_supported: true, diff --git a/engine/src/flutter/tests/Android.bp b/engine/src/flutter/tests/Android.bp new file mode 100644 index 00000000000..ddc50125112 --- /dev/null +++ b/engine/src/flutter/tests/Android.bp @@ -0,0 +1,33 @@ +filegroup { + name: "minikin-test-data", + srcs: [ + "data/Bold.ttf", + "data/BoldItalic.ttf", + "data/ColorEmojiFont.ttf", + "data/ColorTextMixedEmojiFont.ttf", + "data/Emoji.ttf", + "data/Italic.ttf", + "data/Ja.ttf", + "data/Ko.ttf", + "data/MultiAxis.ttf", + "data/NoCmapFormat14.ttf", + "data/NoGlyphFont.ttf", + "data/Regular.ttf", + "data/TextEmojiFont.ttf", + "data/UnicodeBMPOnly.ttf", + "data/UnicodeBMPOnly2.ttf", + "data/UnicodeUCS4.ttf", + "data/VariationSelectorTest-Regular.ttf", + "data/ZhHans.ttf", + "data/ZhHant.ttf", + "data/emoji.xml", + "data/itemize.xml", + ], +} + +subdirs = [ + "perftests", + "stresstest", + "unittest", + "util", +] diff --git a/engine/src/flutter/tests/perftests/Android.bp b/engine/src/flutter/tests/perftests/Android.bp new file mode 100644 index 00000000000..f8847ac4cb9 --- /dev/null +++ b/engine/src/flutter/tests/perftests/Android.bp @@ -0,0 +1,49 @@ +// +// Copyright (C) 2016 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. +// + +cc_benchmark { + name: "minikin_perftests", + test_suites: ["device-tests"], + cppflags: [ + "-Werror", + "-Wall", + "-Wextra", + ], + srcs: [ + "FontCollection.cpp", + "FontFamily.cpp", + "FontLanguage.cpp", + "GraphemeBreak.cpp", + "Hyphenator.cpp", + "WordBreaker.cpp", + "main.cpp", + ], + + header_libs: ["libminikin-headers-for-tests"], + + static_libs: [ + "libminikin-tests-util", + "libminikin", + "libxml2", + ], + + shared_libs: [ + "libharfbuzz_ng", + "libicuuc", + "liblog", + "libskia", + ], +} diff --git a/engine/src/flutter/tests/perftests/Android.mk b/engine/src/flutter/tests/perftests/Android.mk deleted file mode 100644 index aa18f8b27aa..00000000000 --- a/engine/src/flutter/tests/perftests/Android.mk +++ /dev/null @@ -1,53 +0,0 @@ -# -# Copyright (C) 2016 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. -# - -LOCAL_PATH := $(call my-dir) - -perftest_src_files := \ - ../util/FileUtils.cpp \ - ../util/FontTestUtils.cpp \ - ../util/MinikinFontForTest.cpp \ - ../util/UnicodeUtils.cpp \ - FontCollection.cpp \ - FontFamily.cpp \ - FontLanguage.cpp \ - GraphemeBreak.cpp \ - Hyphenator.cpp \ - WordBreaker.cpp \ - main.cpp - -include $(CLEAR_VARS) -LOCAL_MODULE := minikin_perftests -LOCAL_COMPATIBILITY_SUITE := device-tests -LOCAL_CPPFLAGS := -Werror -Wall -Wextra -LOCAL_SRC_FILES := $(perftest_src_files) -LOCAL_STATIC_LIBRARIES := \ - libminikin \ - libxml2 - -LOCAL_SHARED_LIBRARIES := \ - libharfbuzz_ng \ - libicuuc \ - liblog \ - libskia - -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH)/../ \ - $(LOCAL_PATH)/../../libs/minikin \ - external/harfbuzz_ng/src \ - external/libxml2/include - -include $(BUILD_NATIVE_BENCHMARK) diff --git a/engine/src/flutter/tests/perftests/FontCollection.cpp b/engine/src/flutter/tests/perftests/FontCollection.cpp index fd95cf1a60c..79f25631b0b 100644 --- a/engine/src/flutter/tests/perftests/FontCollection.cpp +++ b/engine/src/flutter/tests/perftests/FontCollection.cpp @@ -18,8 +18,8 @@ #include #include -#include -#include +#include +#include #include namespace minikin { diff --git a/engine/src/flutter/tests/perftests/GraphemeBreak.cpp b/engine/src/flutter/tests/perftests/GraphemeBreak.cpp index 6d6cf5b1783..830586f44e1 100644 --- a/engine/src/flutter/tests/perftests/GraphemeBreak.cpp +++ b/engine/src/flutter/tests/perftests/GraphemeBreak.cpp @@ -18,7 +18,7 @@ #include #include "minikin/GraphemeBreak.h" -#include "util/UnicodeUtils.h" +#include "UnicodeUtils.h" namespace minikin { diff --git a/engine/src/flutter/tests/perftests/Hyphenator.cpp b/engine/src/flutter/tests/perftests/Hyphenator.cpp index 2107e0575ce..ae6249875ad 100644 --- a/engine/src/flutter/tests/perftests/Hyphenator.cpp +++ b/engine/src/flutter/tests/perftests/Hyphenator.cpp @@ -16,8 +16,8 @@ #include #include -#include -#include +#include +#include namespace minikin { diff --git a/engine/src/flutter/tests/perftests/WordBreaker.cpp b/engine/src/flutter/tests/perftests/WordBreaker.cpp index 6758cf97e58..f9ef2144db6 100644 --- a/engine/src/flutter/tests/perftests/WordBreaker.cpp +++ b/engine/src/flutter/tests/perftests/WordBreaker.cpp @@ -16,7 +16,7 @@ #include #include "minikin/WordBreaker.h" -#include "util/UnicodeUtils.h" +#include "UnicodeUtils.h" namespace minikin { diff --git a/engine/src/flutter/tests/stresstest/Android.bp b/engine/src/flutter/tests/stresstest/Android.bp new file mode 100644 index 00000000000..96a23dcfb76 --- /dev/null +++ b/engine/src/flutter/tests/stresstest/Android.bp @@ -0,0 +1,49 @@ +// Copyright (C) 2017 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. + +// see how_to_run.txt for instructions on running these tests + +cc_test { + name: "minikin_stress_tests", + + header_libs: ["libminikin-headers-for-tests"], + + static_libs: [ + "libminikin-tests-util", + "libminikin", + "libxml2", + ], + + // Shared libraries which are dependencies of minikin; these are not automatically + // pulled in by the build system (and thus sadly must be repeated). + shared_libs: [ + "libskia", + "libft2", + "libharfbuzz_ng", + "libicuuc", + "liblog", + "libutils", + "libz", + ], + + srcs: [ + "MultithreadTest.cpp", + ], + + cppflags: [ + "-Werror", + "-Wall", + "-Wextra", + ], +} diff --git a/engine/src/flutter/tests/stresstest/Android.mk b/engine/src/flutter/tests/stresstest/Android.mk deleted file mode 100644 index 961978b5ccf..00000000000 --- a/engine/src/flutter/tests/stresstest/Android.mk +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (C) 2017 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. - -# see how_to_run.txt for instructions on running these tests - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_TEST_DATA := $(foreach f,$(LOCAL_TEST_DATA),frameworks/minikin/tests:$(f)) - -LOCAL_MODULE := minikin_stress_tests -LOCAL_MODULE_TAGS := tests -LOCAL_MODULE_CLASS := NATIVE_TESTS - -LOCAL_STATIC_LIBRARIES := libminikin - -# Shared libraries which are dependencies of minikin; these are not automatically -# pulled in by the build system (and thus sadly must be repeated). - -LOCAL_SHARED_LIBRARIES := \ - libskia \ - libft2 \ - libharfbuzz_ng \ - libicuuc \ - liblog \ - libutils \ - libz - -LOCAL_STATIC_LIBRARIES += \ - libxml2 - -LOCAL_SRC_FILES += \ - ../util/FontTestUtils.cpp \ - ../util/MinikinFontForTest.cpp \ - MultithreadTest.cpp \ - -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH)/../../libs/minikin/ \ - $(LOCAL_PATH)/../util \ - external/libxml2/include \ - -LOCAL_CPPFLAGS += -Werror -Wall -Wextra - -include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/unittest/Android.bp b/engine/src/flutter/tests/unittest/Android.bp new file mode 100644 index 00000000000..2353d4cc76a --- /dev/null +++ b/engine/src/flutter/tests/unittest/Android.bp @@ -0,0 +1,74 @@ +// Copyright (C) 2015 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. + +// see how_to_run.txt for instructions on running these tests + +cc_test { + name: "minikin_tests", + test_suites: ["device-tests"], + data: [":minikin-test-data"], + + header_libs: ["libminikin-headers-for-tests"], + + static_libs: [ + "libminikin-tests-util", + "libminikin", + "libxml2", + ], + + // Shared libraries which are dependencies of minikin; these are not automatically + // pulled in by the build system (and thus sadly must be repeated). + shared_libs: [ + "libskia", + "libft2", + "libharfbuzz_ng", + "libicuuc", + "liblog", + "libutils", + "libz", + ], + + srcs: [ + "CmapCoverageTest.cpp", + "EmojiTest.cpp", + "FontCollectionTest.cpp", + "FontCollectionItemizeTest.cpp", + "FontFamilyTest.cpp", + "FontLanguageListCacheTest.cpp", + "HbFontCacheTest.cpp", + "HyphenatorTest.cpp", + "GraphemeBreakTests.cpp", + "LayoutTest.cpp", + "LayoutUtilsTest.cpp", + "MeasurementTests.cpp", + "SparseBitSetTest.cpp", + "UnicodeUtilsTest.cpp", + "WordBreakerTests.cpp", + ], + + cppflags: [ + "-Werror", + "-Wall", + "-Wextra", + ], + + multilib: { + lib32: { + cppflags: ["-DkTestFontDir=\"/data/nativetest/minikin_tests/data/\""], + }, + lib64: { + cppflags: ["-DkTestFontDir=\"/data/nativetest64/minikin_tests/data/\""], + }, + }, +} diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk deleted file mode 100644 index 55ff9babfea..00000000000 --- a/engine/src/flutter/tests/unittest/Android.mk +++ /dev/null @@ -1,101 +0,0 @@ -# Copyright (C) 2015 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. - -# see how_to_run.txt for instructions on running these tests - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_TEST_DATA := \ - data/Bold.ttf \ - data/BoldItalic.ttf \ - data/ColorEmojiFont.ttf \ - data/ColorTextMixedEmojiFont.ttf \ - data/Emoji.ttf \ - data/Italic.ttf \ - data/Ja.ttf \ - data/Ko.ttf \ - data/MultiAxis.ttf \ - data/NoCmapFormat14.ttf \ - data/NoGlyphFont.ttf \ - data/Regular.ttf \ - data/TextEmojiFont.ttf \ - data/UnicodeBMPOnly.ttf \ - data/UnicodeBMPOnly2.ttf \ - data/UnicodeUCS4.ttf \ - data/VariationSelectorTest-Regular.ttf \ - data/ZhHans.ttf \ - data/ZhHant.ttf \ - data/emoji.xml \ - data/itemize.xml \ - -LOCAL_TEST_DATA := $(foreach f,$(LOCAL_TEST_DATA),frameworks/minikin/tests:$(f)) - -LOCAL_MODULE := minikin_tests -LOCAL_COMPATIBILITY_SUITE := device-tests -LOCAL_MODULE_TAGS := tests -LOCAL_MODULE_CLASS := NATIVE_TESTS - -LOCAL_STATIC_LIBRARIES := libminikin - -# Shared libraries which are dependencies of minikin; these are not automatically -# pulled in by the build system (and thus sadly must be repeated). - -LOCAL_SHARED_LIBRARIES := \ - libskia \ - libft2 \ - libharfbuzz_ng \ - libicuuc \ - liblog \ - libutils \ - libz - -LOCAL_STATIC_LIBRARIES += \ - libxml2 - -LOCAL_SRC_FILES += \ - ../util/FileUtils.cpp \ - ../util/FontTestUtils.cpp \ - ../util/MinikinFontForTest.cpp \ - ../util/UnicodeUtils.cpp \ - CmapCoverageTest.cpp \ - EmojiTest.cpp \ - FontCollectionTest.cpp \ - FontCollectionItemizeTest.cpp \ - FontFamilyTest.cpp \ - FontLanguageListCacheTest.cpp \ - HbFontCacheTest.cpp \ - HyphenatorTest.cpp \ - GraphemeBreakTests.cpp \ - LayoutTest.cpp \ - LayoutUtilsTest.cpp \ - MeasurementTests.cpp \ - SparseBitSetTest.cpp \ - UnicodeUtilsTest.cpp \ - WordBreakerTests.cpp - -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH)/../../libs/minikin/ \ - $(LOCAL_PATH)/../util \ - external/harfbuzz_ng/src \ - external/libxml2/include \ - external/skia/src/core - -LOCAL_CPPFLAGS += -Werror -Wall -Wextra - -LOCAL_CPPFLAGS_32 += -DkTestFontDir="\"/data/nativetest/minikin_tests/data/\"" -LOCAL_CPPFLAGS_64 += -DkTestFontDir="\"/data/nativetest64/minikin_tests/data/\"" - -include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/util/Android.bp b/engine/src/flutter/tests/util/Android.bp new file mode 100644 index 00000000000..50a2cd722f3 --- /dev/null +++ b/engine/src/flutter/tests/util/Android.bp @@ -0,0 +1,13 @@ +cc_library_static { + name: "libminikin-tests-util", + srcs: [ + "FileUtils.cpp", + "FontTestUtils.cpp", + "MinikinFontForTest.cpp", + "UnicodeUtils.cpp", + ], + export_include_dirs: ["."], + shared_libs: ["libxml2"], + static_libs: ["libminikin"], + header_libs: ["libminikin-headers-for-tests"], +} From f3ba5a36bf209bc73cff4d082aead5c8606514c4 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 2 Dec 2016 17:59:14 -0800 Subject: [PATCH 268/364] Convert frameworks/minikin to Android.bp See build/soong/README.md for more information. Test: m -j checkbuild Change-Id: I71d3406054b35dd4e8ae30f46eec6cef77eef160 (cherry picked from commit 716f07be94544d97039fbcb01df876e092d61d37) --- engine/src/flutter/Android.bp | 10 ++ engine/src/flutter/app/Android.bp | 30 ++++++ engine/src/flutter/app/Android.mk | 36 -------- engine/src/flutter/libs/minikin/Android.bp | 78 ++++++++++++++++ engine/src/flutter/libs/minikin/Android.mk | 102 --------------------- 5 files changed, 118 insertions(+), 138 deletions(-) create mode 100644 engine/src/flutter/Android.bp create mode 100644 engine/src/flutter/app/Android.bp delete mode 100644 engine/src/flutter/app/Android.mk create mode 100644 engine/src/flutter/libs/minikin/Android.bp delete mode 100644 engine/src/flutter/libs/minikin/Android.mk diff --git a/engine/src/flutter/Android.bp b/engine/src/flutter/Android.bp new file mode 100644 index 00000000000..26d5027683c --- /dev/null +++ b/engine/src/flutter/Android.bp @@ -0,0 +1,10 @@ +cc_library_headers { + name: "libminikin_headers", + host_supported: true, + export_include_dirs: ["include"], +} + +subdirs = [ + "app", + "libs/minikin", +] diff --git a/engine/src/flutter/app/Android.bp b/engine/src/flutter/app/Android.bp new file mode 100644 index 00000000000..e8085c1f3ea --- /dev/null +++ b/engine/src/flutter/app/Android.bp @@ -0,0 +1,30 @@ +// Copyright (C) 2015 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. + +// see how_to_run.txt for instructions on running these tests + +cc_binary_host { + name: "hyphtool", + + static_libs: ["libminikin"], + + // Shared libraries which are dependencies of minikin; these are not automatically + // pulled in by the build system (and thus sadly must be repeated). + shared_libs: [ + "liblog", + "libicuuc", + ], + + srcs: ["HyphTool.cpp"], +} diff --git a/engine/src/flutter/app/Android.mk b/engine/src/flutter/app/Android.mk deleted file mode 100644 index 23305b7b4c6..00000000000 --- a/engine/src/flutter/app/Android.mk +++ /dev/null @@ -1,36 +0,0 @@ -# Copyright (C) 2015 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. - -# see how_to_run.txt for instructions on running these tests - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_MODULE := hyphtool -LOCAL_MODULE_TAGS := optional - -LOCAL_STATIC_LIBRARIES := libminikin_host - -# Shared libraries which are dependencies of minikin; these are not automatically -# pulled in by the build system (and thus sadly must be repeated). - -LOCAL_SHARED_LIBRARIES := \ - liblog \ - libicuuc - -LOCAL_SRC_FILES += \ - HyphTool.cpp - -include $(BUILD_HOST_EXECUTABLE) diff --git a/engine/src/flutter/libs/minikin/Android.bp b/engine/src/flutter/libs/minikin/Android.bp new file mode 100644 index 00000000000..ef721ea80b0 --- /dev/null +++ b/engine/src/flutter/libs/minikin/Android.bp @@ -0,0 +1,78 @@ +// Copyright (C) 2013 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. + +cc_library { + name: "libminikin", + host_supported: true, + srcs: [ + "Hyphenator.cpp", + ], + target: { + android: { + srcs: [ + "CmapCoverage.cpp", + "Emoji.cpp", + "FontCollection.cpp", + "FontFamily.cpp", + "FontLanguage.cpp", + "FontLanguageListCache.cpp", + "FontUtils.cpp", + "GraphemeBreak.cpp", + "HbFontCache.cpp", + "Layout.cpp", + "LayoutUtils.cpp", + "LineBreaker.cpp", + "Measurement.cpp", + "MinikinInternal.cpp", + "MinikinFont.cpp", + "SparseBitSet.cpp", + "WordBreaker.cpp", + ], + shared_libs: [ + "libharfbuzz_ng", + "libft2", + "libz", + "libutils", + ], + // TODO: clean up Minikin so it doesn't need the freetype include + export_shared_lib_headers: ["libft2"], + }, + }, + cppflags: [ + "-Werror", + "-Wall", + "-Wextra", + ], + product_variables: { + debuggable: { + // Enable race detection on eng and userdebug build. + cppflags: ["-DENABLE_RACE_DETECTION"], + }, + }, + shared_libs: [ + "liblog", + "libicuuc", + ], + header_libs: ["libminikin_headers"], + export_header_lib_headers: ["libminikin_headers"], + + clang: true, + sanitize: { + misc_undefined: [ + "signed-integer-overflow", + // b/26432628. + //"unsigned-integer-overflow", + ], + }, +} diff --git a/engine/src/flutter/libs/minikin/Android.mk b/engine/src/flutter/libs/minikin/Android.mk deleted file mode 100644 index bb6234a123e..00000000000 --- a/engine/src/flutter/libs/minikin/Android.mk +++ /dev/null @@ -1,102 +0,0 @@ -# Copyright (C) 2013 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. - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -include $(CLEAR_VARS) -minikin_src_files := \ - CmapCoverage.cpp \ - Emoji.cpp \ - FontCollection.cpp \ - FontFamily.cpp \ - FontLanguage.cpp \ - FontLanguageListCache.cpp \ - FontUtils.cpp \ - GraphemeBreak.cpp \ - HbFontCache.cpp \ - Hyphenator.cpp \ - Layout.cpp \ - LayoutUtils.cpp \ - LineBreaker.cpp \ - Measurement.cpp \ - MinikinInternal.cpp \ - MinikinFont.cpp \ - SparseBitSet.cpp \ - WordBreaker.cpp - -minikin_c_includes := \ - external/harfbuzz_ng/src \ - frameworks/minikin/include \ - $(intermediates) - -minikin_shared_libraries := \ - libharfbuzz_ng \ - libft2 \ - liblog \ - libz \ - libicuuc \ - libutils - -ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT))) -# Enable race detection on eng and userdebug build. -enable_race_detection := -DENABLE_RACE_DETECTION -else -enable_race_detection := -endif - -LOCAL_MODULE := libminikin -LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include -LOCAL_SRC_FILES := $(minikin_src_files) -LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra $(enable_race_detection) -LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) -LOCAL_CLANG := true -LOCAL_SANITIZE := signed-integer-overflow -# b/26432628. -#LOCAL_SANITIZE += unsigned-integer-overflow - -include $(BUILD_SHARED_LIBRARY) - -include $(CLEAR_VARS) - -LOCAL_MODULE := libminikin -LOCAL_MODULE_TAGS := optional -LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include -LOCAL_SRC_FILES := $(minikin_src_files) -LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra $(enable_race_detection) -LOCAL_SHARED_LIBRARIES := $(minikin_shared_libraries) -LOCAL_CLANG := true -LOCAL_SANITIZE := signed-integer-overflow -# b/26432628. -#LOCAL_SANITIZE += unsigned-integer-overflow - -include $(BUILD_STATIC_LIBRARY) - -include $(CLEAR_VARS) - -# Reduced library (currently just hyphenation) for host - -LOCAL_MODULE := libminikin_host -LOCAL_MODULE_TAGS := optional -LOCAL_EXPORT_C_INCLUDE_DIRS := frameworks/minikin/include -LOCAL_C_INCLUDES := $(minikin_c_includes) -LOCAL_CPPFLAGS += -Werror -Wall -Wextra $(enable_race_detection) -LOCAL_SHARED_LIBRARIES := liblog libicuuc - -LOCAL_SRC_FILES := Hyphenator.cpp - -include $(BUILD_HOST_STATIC_LIBRARY) From fcb08dbdeee43f133f3f524f4cc142e41a181f19 Mon Sep 17 00:00:00 2001 From: Fredrik Roubert Date: Thu, 13 Apr 2017 20:06:05 +0200 Subject: [PATCH 269/364] =?UTF-8?q?Let=20mk=5Fhyb=5Ffile.py=20replace=20?= =?UTF-8?q?=C3=9FSS=20in=20.chr.txt=20files=20with=20=C3=9F=E1=BA=9E.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Here these mappings are used to convert from uppercase to lowercase, and mk_hyb_file.py doesn't handle multi-character uppercase sequences. Therefore, in case the sequence ßSS is encountered in a .chr.txt, replace it internally with ßẞ. Test: make -j Change-Id: I8f678aad9298784f70645c453ec07da5bf43cb66 --- engine/src/flutter/tools/mk_hyb_file.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/tools/mk_hyb_file.py b/engine/src/flutter/tools/mk_hyb_file.py index a9b8932c95f..545e9b7b930 100755 --- a/engine/src/flutter/tools/mk_hyb_file.py +++ b/engine/src/flutter/tools/mk_hyb_file.py @@ -35,6 +35,10 @@ import getopt VERBOSE = False +# U+00DF is LATIN SMALL LETTER SHARP S +# U+1E9E is LATIN CAPITAL LETTER SHARP S +SHARP_S_TO_DOUBLE = u'\u00dfSS' +SHARP_S_TO_CAPITAL = u'\u00df\u1e9e' if sys.version_info[0] >= 3: def unichr(x): @@ -283,8 +287,12 @@ def load_chr(fn): for i, l in enumerate(f): l = l.strip() if len(l) > 2: - # lowercase maps to multi-character uppercase sequence, ignore uppercase for now - l = l[:1] + if l == SHARP_S_TO_DOUBLE: + # replace with lowercasing from capital letter sharp s + l = SHARP_S_TO_CAPITAL + else: + # lowercase maps to multi-character uppercase sequence, ignore uppercase for now + l = l[:1] else: assert len(l) == 2, 'expected 2 chars in chr' for c in l: @@ -419,6 +427,9 @@ def verify_file_sorted(lines, fn): file_lines = [l.strip() for l in io.open(fn, encoding='UTF-8')] line_set = set(lines) file_set = set(file_lines) + if SHARP_S_TO_DOUBLE in file_set: + # ignore difference of double capital letter s and capital letter sharp s + file_set.symmetric_difference_update([SHARP_S_TO_DOUBLE, SHARP_S_TO_CAPITAL]) if line_set == file_set: return True for line in line_set - file_set: From 6e0a223dbb6457ce95347e426b9b6c9662166cb9 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 2 May 2017 17:18:30 -0700 Subject: [PATCH 270/364] Export libicuuc headers from libminikin Test: m -j checkbuild Change-Id: Ibecebc8a1bd4028c083424476dd379c0ce0149a1 --- engine/src/flutter/libs/minikin/Android.bp | 1 + 1 file changed, 1 insertion(+) diff --git a/engine/src/flutter/libs/minikin/Android.bp b/engine/src/flutter/libs/minikin/Android.bp index f7b2dea0570..444bd9a8b55 100644 --- a/engine/src/flutter/libs/minikin/Android.bp +++ b/engine/src/flutter/libs/minikin/Android.bp @@ -77,6 +77,7 @@ cc_library { ], header_libs: ["libminikin_headers"], export_header_lib_headers: ["libminikin_headers"], + export_shared_lib_headers: ["libicuuc"], clang: true, sanitize: { From d9ff3a728957fe19842cc1c2d3554aee624bcbc2 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 25 Apr 2017 10:53:34 -0700 Subject: [PATCH 271/364] Convert frameworks/minikin/tests to Android.bp See build/soong/README.md for more information. Test: m -j checkbuild Change-Id: I930debdd129da7f61ac4b764980f73dfd487785d Merged-In: I930debdd129da7f61ac4b764980f73dfd487785d (cherry picked from commit fa994b25d1885d67a317e685b2ea8e6bbfdfc655) --- engine/src/flutter/Android.bp | 1 + engine/src/flutter/libs/minikin/Android.bp | 7 ++ engine/src/flutter/tests/Android.bp | 86 ++++++++++++++++++++++ engine/src/flutter/tests/Android.mk | 85 --------------------- 4 files changed, 94 insertions(+), 85 deletions(-) create mode 100644 engine/src/flutter/tests/Android.bp delete mode 100644 engine/src/flutter/tests/Android.mk diff --git a/engine/src/flutter/Android.bp b/engine/src/flutter/Android.bp index b1a778c5630..84de9fb2b2b 100644 --- a/engine/src/flutter/Android.bp +++ b/engine/src/flutter/Android.bp @@ -8,4 +8,5 @@ subdirs = [ "app", "libs/minikin", "sample", + "tests", ] diff --git a/engine/src/flutter/libs/minikin/Android.bp b/engine/src/flutter/libs/minikin/Android.bp index 444bd9a8b55..1109280fafd 100644 --- a/engine/src/flutter/libs/minikin/Android.bp +++ b/engine/src/flutter/libs/minikin/Android.bp @@ -21,6 +21,13 @@ genrule { tool_files: ["unicode_emoji_h_gen.py"], } +cc_library_headers { + name: "libminikin-headers-for-tests", + export_include_dirs: ["."], + shared_libs: ["libharfbuzz_ng"], + export_shared_lib_headers: ["libharfbuzz_ng"], +} + cc_library { name: "libminikin", host_supported: true, diff --git a/engine/src/flutter/tests/Android.bp b/engine/src/flutter/tests/Android.bp new file mode 100644 index 00000000000..895cd2a4811 --- /dev/null +++ b/engine/src/flutter/tests/Android.bp @@ -0,0 +1,86 @@ +// Copyright (C) 2015 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. + +// see how_to_run.txt for instructions on running these tests + +cc_test { + name: "minikin_tests", + data: [ + "data/BoldItalic.ttf", + "data/Bold.ttf", + "data/ColorEmojiFont.ttf", + "data/ColorTextMixedEmojiFont.ttf", + "data/Emoji.ttf", + "data/Italic.ttf", + "data/Ja.ttf", + "data/Ko.ttf", + "data/NoGlyphFont.ttf", + "data/Regular.ttf", + "data/TextEmojiFont.ttf", + "data/VarioationSelectorTest-Regular.ttf", + "data/ZhHans.ttf", + "data/ZhHant.ttf", + "data/itemize.xml", + "data/emoji.xml", + ], + + static_libs: [ + "libminikin", + "libxml2", + ], + + // Shared libraries which are dependencies of minikin; these are not automatically + // pulled in by the build system (and thus sadly must be repeated). + shared_libs: [ + "libskia", + "libft2", + "libharfbuzz_ng", + "libicuuc", + "liblog", + "libutils", + "libz", + ], + + srcs: [ + "FontCollectionTest.cpp", + "FontCollectionItemizeTest.cpp", + "FontFamilyTest.cpp", + "FontLanguageListCacheTest.cpp", + "FontTestUtils.cpp", + "HbFontCacheTest.cpp", + "MinikinFontForTest.cpp", + "MinikinInternalTest.cpp", + "GraphemeBreakTests.cpp", + "LayoutUtilsTest.cpp", + "UnicodeUtils.cpp", + "WordBreakerTests.cpp", + ], + + header_libs: ["libminikin-headers-for-tests"], + + cppflags: [ + "-Werror", + "-Wall", + "-Wextra", + ], + + multilib: { + lib32: { + cppflags: ["-DkTestFontDir=\"/data/nativetest/minikin_tests/data/\""], + }, + lib64: { + cppflags: ["-DkTestFontDir=\"/data/nativetest64/minikin_tests/data/\""], + }, + }, +} diff --git a/engine/src/flutter/tests/Android.mk b/engine/src/flutter/tests/Android.mk deleted file mode 100644 index 2f215323771..00000000000 --- a/engine/src/flutter/tests/Android.mk +++ /dev/null @@ -1,85 +0,0 @@ -# Copyright (C) 2015 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. - -# see how_to_run.txt for instructions on running these tests - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_TEST_DATA := \ - data/BoldItalic.ttf \ - data/Bold.ttf \ - data/ColorEmojiFont.ttf \ - data/ColorTextMixedEmojiFont.ttf \ - data/Emoji.ttf \ - data/Italic.ttf \ - data/Ja.ttf \ - data/Ko.ttf \ - data/NoGlyphFont.ttf \ - data/Regular.ttf \ - data/TextEmojiFont.ttf \ - data/VarioationSelectorTest-Regular.ttf \ - data/ZhHans.ttf \ - data/ZhHant.ttf \ - data/itemize.xml \ - data/emoji.xml - -LOCAL_MODULE := minikin_tests -LOCAL_MODULE_TAGS := tests -LOCAL_MODULE_CLASS := NATIVE_TESTS - -LOCAL_STATIC_LIBRARIES := libminikin - -# Shared libraries which are dependencies of minikin; these are not automatically -# pulled in by the build system (and thus sadly must be repeated). - -LOCAL_SHARED_LIBRARIES := \ - libskia \ - libft2 \ - libharfbuzz_ng \ - libicuuc \ - liblog \ - libutils \ - libz - -LOCAL_STATIC_LIBRARIES += \ - libxml2 - -LOCAL_SRC_FILES += \ - FontCollectionTest.cpp \ - FontCollectionItemizeTest.cpp \ - FontFamilyTest.cpp \ - FontLanguageListCacheTest.cpp \ - FontTestUtils.cpp \ - HbFontCacheTest.cpp \ - MinikinFontForTest.cpp \ - MinikinInternalTest.cpp \ - GraphemeBreakTests.cpp \ - LayoutUtilsTest.cpp \ - UnicodeUtils.cpp \ - WordBreakerTests.cpp - -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH)/../libs/minikin/ \ - external/harfbuzz_ng/src \ - external/libxml2/include \ - external/skia/src/core - -LOCAL_CPPFLAGS += -Werror -Wall -Wextra - -LOCAL_CPPFLAGS_32 += -DkTestFontDir="\"/data/nativetest/minikin_tests/data/\"" -LOCAL_CPPFLAGS_64 += -DkTestFontDir="\"/data/nativetest64/minikin_tests/data/\"" - -include $(BUILD_NATIVE_TEST) From ede222c03b9757e9a1da85cdc9de4d85b9e7379c Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 25 Apr 2017 10:53:34 -0700 Subject: [PATCH 272/364] Convert frameworks/minikin/tests to Android.bp See build/soong/README.md for more information. Test: m -j checkbuild Change-Id: I930debdd129da7f61ac4b764980f73dfd487785d Merged-In: I930debdd129da7f61ac4b764980f73dfd487785d (cherry picked from commit fa994b25d1885d67a317e685b2ea8e6bbfdfc655) --- engine/src/flutter/Android.bp | 1 + engine/src/flutter/libs/minikin/Android.bp | 7 ++ engine/src/flutter/tests/Android.bp | 33 ++++++ engine/src/flutter/tests/perftests/Android.bp | 48 +++++++++ engine/src/flutter/tests/perftests/Android.mk | 52 --------- .../tests/perftests/FontCollection.cpp | 4 +- .../flutter/tests/perftests/GraphemeBreak.cpp | 2 +- .../flutter/tests/perftests/Hyphenator.cpp | 4 +- .../flutter/tests/perftests/WordBreaker.cpp | 2 +- .../src/flutter/tests/stresstest/Android.bp | 49 +++++++++ .../src/flutter/tests/stresstest/Android.mk | 56 ---------- engine/src/flutter/tests/unittest/Android.bp | 73 +++++++++++++ engine/src/flutter/tests/unittest/Android.mk | 100 ------------------ engine/src/flutter/tests/util/Android.bp | 13 +++ 14 files changed, 230 insertions(+), 214 deletions(-) create mode 100644 engine/src/flutter/tests/Android.bp create mode 100644 engine/src/flutter/tests/perftests/Android.bp delete mode 100644 engine/src/flutter/tests/perftests/Android.mk create mode 100644 engine/src/flutter/tests/stresstest/Android.bp delete mode 100644 engine/src/flutter/tests/stresstest/Android.mk create mode 100644 engine/src/flutter/tests/unittest/Android.bp delete mode 100644 engine/src/flutter/tests/unittest/Android.mk create mode 100644 engine/src/flutter/tests/util/Android.bp diff --git a/engine/src/flutter/Android.bp b/engine/src/flutter/Android.bp index 26d5027683c..e875a172b0a 100644 --- a/engine/src/flutter/Android.bp +++ b/engine/src/flutter/Android.bp @@ -7,4 +7,5 @@ cc_library_headers { subdirs = [ "app", "libs/minikin", + "tests", ] diff --git a/engine/src/flutter/libs/minikin/Android.bp b/engine/src/flutter/libs/minikin/Android.bp index c236be3499f..71a693ec2c9 100644 --- a/engine/src/flutter/libs/minikin/Android.bp +++ b/engine/src/flutter/libs/minikin/Android.bp @@ -12,6 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +cc_library_headers { + name: "libminikin-headers-for-tests", + export_include_dirs: ["."], + shared_libs: ["libharfbuzz_ng"], + export_shared_lib_headers: ["libharfbuzz_ng"], +} + cc_library { name: "libminikin", host_supported: true, diff --git a/engine/src/flutter/tests/Android.bp b/engine/src/flutter/tests/Android.bp new file mode 100644 index 00000000000..ddc50125112 --- /dev/null +++ b/engine/src/flutter/tests/Android.bp @@ -0,0 +1,33 @@ +filegroup { + name: "minikin-test-data", + srcs: [ + "data/Bold.ttf", + "data/BoldItalic.ttf", + "data/ColorEmojiFont.ttf", + "data/ColorTextMixedEmojiFont.ttf", + "data/Emoji.ttf", + "data/Italic.ttf", + "data/Ja.ttf", + "data/Ko.ttf", + "data/MultiAxis.ttf", + "data/NoCmapFormat14.ttf", + "data/NoGlyphFont.ttf", + "data/Regular.ttf", + "data/TextEmojiFont.ttf", + "data/UnicodeBMPOnly.ttf", + "data/UnicodeBMPOnly2.ttf", + "data/UnicodeUCS4.ttf", + "data/VariationSelectorTest-Regular.ttf", + "data/ZhHans.ttf", + "data/ZhHant.ttf", + "data/emoji.xml", + "data/itemize.xml", + ], +} + +subdirs = [ + "perftests", + "stresstest", + "unittest", + "util", +] diff --git a/engine/src/flutter/tests/perftests/Android.bp b/engine/src/flutter/tests/perftests/Android.bp new file mode 100644 index 00000000000..f8068e8b8e2 --- /dev/null +++ b/engine/src/flutter/tests/perftests/Android.bp @@ -0,0 +1,48 @@ +// +// Copyright (C) 2016 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. +// + +cc_benchmark { + name: "minikin_perftests", + cppflags: [ + "-Werror", + "-Wall", + "-Wextra", + ], + srcs: [ + "FontCollection.cpp", + "FontFamily.cpp", + "FontLanguage.cpp", + "GraphemeBreak.cpp", + "Hyphenator.cpp", + "WordBreaker.cpp", + "main.cpp", + ], + + header_libs: ["libminikin-headers-for-tests"], + + static_libs: [ + "libminikin-tests-util", + "libminikin", + "libxml2", + ], + + shared_libs: [ + "libharfbuzz_ng", + "libicuuc", + "liblog", + "libskia", + ], +} diff --git a/engine/src/flutter/tests/perftests/Android.mk b/engine/src/flutter/tests/perftests/Android.mk deleted file mode 100644 index c60123a83d7..00000000000 --- a/engine/src/flutter/tests/perftests/Android.mk +++ /dev/null @@ -1,52 +0,0 @@ -# -# Copyright (C) 2016 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. -# - -LOCAL_PATH := $(call my-dir) - -perftest_src_files := \ - ../util/FileUtils.cpp \ - ../util/FontTestUtils.cpp \ - ../util/MinikinFontForTest.cpp \ - ../util/UnicodeUtils.cpp \ - FontCollection.cpp \ - FontFamily.cpp \ - FontLanguage.cpp \ - GraphemeBreak.cpp \ - Hyphenator.cpp \ - WordBreaker.cpp \ - main.cpp - -include $(CLEAR_VARS) -LOCAL_MODULE := minikin_perftests -LOCAL_CPPFLAGS := -Werror -Wall -Wextra -LOCAL_SRC_FILES := $(perftest_src_files) -LOCAL_STATIC_LIBRARIES := \ - libminikin \ - libxml2 - -LOCAL_SHARED_LIBRARIES := \ - libharfbuzz_ng \ - libicuuc \ - liblog \ - libskia - -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH)/../ \ - $(LOCAL_PATH)/../../libs/minikin \ - external/harfbuzz_ng/src \ - external/libxml2/include - -include $(BUILD_NATIVE_BENCHMARK) diff --git a/engine/src/flutter/tests/perftests/FontCollection.cpp b/engine/src/flutter/tests/perftests/FontCollection.cpp index fd95cf1a60c..79f25631b0b 100644 --- a/engine/src/flutter/tests/perftests/FontCollection.cpp +++ b/engine/src/flutter/tests/perftests/FontCollection.cpp @@ -18,8 +18,8 @@ #include #include -#include -#include +#include +#include #include namespace minikin { diff --git a/engine/src/flutter/tests/perftests/GraphemeBreak.cpp b/engine/src/flutter/tests/perftests/GraphemeBreak.cpp index 6d6cf5b1783..830586f44e1 100644 --- a/engine/src/flutter/tests/perftests/GraphemeBreak.cpp +++ b/engine/src/flutter/tests/perftests/GraphemeBreak.cpp @@ -18,7 +18,7 @@ #include #include "minikin/GraphemeBreak.h" -#include "util/UnicodeUtils.h" +#include "UnicodeUtils.h" namespace minikin { diff --git a/engine/src/flutter/tests/perftests/Hyphenator.cpp b/engine/src/flutter/tests/perftests/Hyphenator.cpp index 2107e0575ce..ae6249875ad 100644 --- a/engine/src/flutter/tests/perftests/Hyphenator.cpp +++ b/engine/src/flutter/tests/perftests/Hyphenator.cpp @@ -16,8 +16,8 @@ #include #include -#include -#include +#include +#include namespace minikin { diff --git a/engine/src/flutter/tests/perftests/WordBreaker.cpp b/engine/src/flutter/tests/perftests/WordBreaker.cpp index 6758cf97e58..f9ef2144db6 100644 --- a/engine/src/flutter/tests/perftests/WordBreaker.cpp +++ b/engine/src/flutter/tests/perftests/WordBreaker.cpp @@ -16,7 +16,7 @@ #include #include "minikin/WordBreaker.h" -#include "util/UnicodeUtils.h" +#include "UnicodeUtils.h" namespace minikin { diff --git a/engine/src/flutter/tests/stresstest/Android.bp b/engine/src/flutter/tests/stresstest/Android.bp new file mode 100644 index 00000000000..96a23dcfb76 --- /dev/null +++ b/engine/src/flutter/tests/stresstest/Android.bp @@ -0,0 +1,49 @@ +// Copyright (C) 2017 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. + +// see how_to_run.txt for instructions on running these tests + +cc_test { + name: "minikin_stress_tests", + + header_libs: ["libminikin-headers-for-tests"], + + static_libs: [ + "libminikin-tests-util", + "libminikin", + "libxml2", + ], + + // Shared libraries which are dependencies of minikin; these are not automatically + // pulled in by the build system (and thus sadly must be repeated). + shared_libs: [ + "libskia", + "libft2", + "libharfbuzz_ng", + "libicuuc", + "liblog", + "libutils", + "libz", + ], + + srcs: [ + "MultithreadTest.cpp", + ], + + cppflags: [ + "-Werror", + "-Wall", + "-Wextra", + ], +} diff --git a/engine/src/flutter/tests/stresstest/Android.mk b/engine/src/flutter/tests/stresstest/Android.mk deleted file mode 100644 index 961978b5ccf..00000000000 --- a/engine/src/flutter/tests/stresstest/Android.mk +++ /dev/null @@ -1,56 +0,0 @@ -# Copyright (C) 2017 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. - -# see how_to_run.txt for instructions on running these tests - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_TEST_DATA := $(foreach f,$(LOCAL_TEST_DATA),frameworks/minikin/tests:$(f)) - -LOCAL_MODULE := minikin_stress_tests -LOCAL_MODULE_TAGS := tests -LOCAL_MODULE_CLASS := NATIVE_TESTS - -LOCAL_STATIC_LIBRARIES := libminikin - -# Shared libraries which are dependencies of minikin; these are not automatically -# pulled in by the build system (and thus sadly must be repeated). - -LOCAL_SHARED_LIBRARIES := \ - libskia \ - libft2 \ - libharfbuzz_ng \ - libicuuc \ - liblog \ - libutils \ - libz - -LOCAL_STATIC_LIBRARIES += \ - libxml2 - -LOCAL_SRC_FILES += \ - ../util/FontTestUtils.cpp \ - ../util/MinikinFontForTest.cpp \ - MultithreadTest.cpp \ - -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH)/../../libs/minikin/ \ - $(LOCAL_PATH)/../util \ - external/libxml2/include \ - -LOCAL_CPPFLAGS += -Werror -Wall -Wextra - -include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/unittest/Android.bp b/engine/src/flutter/tests/unittest/Android.bp new file mode 100644 index 00000000000..e6d1356903d --- /dev/null +++ b/engine/src/flutter/tests/unittest/Android.bp @@ -0,0 +1,73 @@ +// Copyright (C) 2015 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. + +// see how_to_run.txt for instructions on running these tests + +cc_test { + name: "minikin_tests", + data: [":minikin-test-data"], + + header_libs: ["libminikin-headers-for-tests"], + + static_libs: [ + "libminikin-tests-util", + "libminikin", + "libxml2", + ], + + // Shared libraries which are dependencies of minikin; these are not automatically + // pulled in by the build system (and thus sadly must be repeated). + shared_libs: [ + "libskia", + "libft2", + "libharfbuzz_ng", + "libicuuc", + "liblog", + "libutils", + "libz", + ], + + srcs: [ + "CmapCoverageTest.cpp", + "EmojiTest.cpp", + "FontCollectionTest.cpp", + "FontCollectionItemizeTest.cpp", + "FontFamilyTest.cpp", + "FontLanguageListCacheTest.cpp", + "HbFontCacheTest.cpp", + "HyphenatorTest.cpp", + "GraphemeBreakTests.cpp", + "LayoutTest.cpp", + "LayoutUtilsTest.cpp", + "MeasurementTests.cpp", + "SparseBitSetTest.cpp", + "UnicodeUtilsTest.cpp", + "WordBreakerTests.cpp", + ], + + cppflags: [ + "-Werror", + "-Wall", + "-Wextra", + ], + + multilib: { + lib32: { + cppflags: ["-DkTestFontDir=\"/data/nativetest/minikin_tests/data/\""], + }, + lib64: { + cppflags: ["-DkTestFontDir=\"/data/nativetest64/minikin_tests/data/\""], + }, + }, +} diff --git a/engine/src/flutter/tests/unittest/Android.mk b/engine/src/flutter/tests/unittest/Android.mk deleted file mode 100644 index b817c46961c..00000000000 --- a/engine/src/flutter/tests/unittest/Android.mk +++ /dev/null @@ -1,100 +0,0 @@ -# Copyright (C) 2015 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. - -# see how_to_run.txt for instructions on running these tests - -LOCAL_PATH := $(call my-dir) - -include $(CLEAR_VARS) - -LOCAL_TEST_DATA := \ - data/Bold.ttf \ - data/BoldItalic.ttf \ - data/ColorEmojiFont.ttf \ - data/ColorTextMixedEmojiFont.ttf \ - data/Emoji.ttf \ - data/Italic.ttf \ - data/Ja.ttf \ - data/Ko.ttf \ - data/MultiAxis.ttf \ - data/NoCmapFormat14.ttf \ - data/NoGlyphFont.ttf \ - data/Regular.ttf \ - data/TextEmojiFont.ttf \ - data/UnicodeBMPOnly.ttf \ - data/UnicodeBMPOnly2.ttf \ - data/UnicodeUCS4.ttf \ - data/VariationSelectorTest-Regular.ttf \ - data/ZhHans.ttf \ - data/ZhHant.ttf \ - data/emoji.xml \ - data/itemize.xml \ - -LOCAL_TEST_DATA := $(foreach f,$(LOCAL_TEST_DATA),frameworks/minikin/tests:$(f)) - -LOCAL_MODULE := minikin_tests -LOCAL_MODULE_TAGS := tests -LOCAL_MODULE_CLASS := NATIVE_TESTS - -LOCAL_STATIC_LIBRARIES := libminikin - -# Shared libraries which are dependencies of minikin; these are not automatically -# pulled in by the build system (and thus sadly must be repeated). - -LOCAL_SHARED_LIBRARIES := \ - libskia \ - libft2 \ - libharfbuzz_ng \ - libicuuc \ - liblog \ - libutils \ - libz - -LOCAL_STATIC_LIBRARIES += \ - libxml2 - -LOCAL_SRC_FILES += \ - ../util/FileUtils.cpp \ - ../util/FontTestUtils.cpp \ - ../util/MinikinFontForTest.cpp \ - ../util/UnicodeUtils.cpp \ - CmapCoverageTest.cpp \ - EmojiTest.cpp \ - FontCollectionTest.cpp \ - FontCollectionItemizeTest.cpp \ - FontFamilyTest.cpp \ - FontLanguageListCacheTest.cpp \ - HbFontCacheTest.cpp \ - HyphenatorTest.cpp \ - GraphemeBreakTests.cpp \ - LayoutTest.cpp \ - LayoutUtilsTest.cpp \ - MeasurementTests.cpp \ - SparseBitSetTest.cpp \ - UnicodeUtilsTest.cpp \ - WordBreakerTests.cpp - -LOCAL_C_INCLUDES := \ - $(LOCAL_PATH)/../../libs/minikin/ \ - $(LOCAL_PATH)/../util \ - external/harfbuzz_ng/src \ - external/libxml2/include \ - external/skia/src/core - -LOCAL_CPPFLAGS += -Werror -Wall -Wextra - -LOCAL_CPPFLAGS_32 += -DkTestFontDir="\"/data/nativetest/minikin_tests/data/\"" -LOCAL_CPPFLAGS_64 += -DkTestFontDir="\"/data/nativetest64/minikin_tests/data/\"" - -include $(BUILD_NATIVE_TEST) diff --git a/engine/src/flutter/tests/util/Android.bp b/engine/src/flutter/tests/util/Android.bp new file mode 100644 index 00000000000..50a2cd722f3 --- /dev/null +++ b/engine/src/flutter/tests/util/Android.bp @@ -0,0 +1,13 @@ +cc_library_static { + name: "libminikin-tests-util", + srcs: [ + "FileUtils.cpp", + "FontTestUtils.cpp", + "MinikinFontForTest.cpp", + "UnicodeUtils.cpp", + ], + export_include_dirs: ["."], + shared_libs: ["libxml2"], + static_libs: ["libminikin"], + header_libs: ["libminikin-headers-for-tests"], +} From ebc9d5808234e678e17ada89d836793bf1f219b5 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 8 May 2017 12:12:17 -0700 Subject: [PATCH 273/364] Add BUILD.gn and make the library build Change-Id: Ie2c3d6f97987e8a9938af8f02b093bb74dd22a18 --- engine/src/flutter/BUILD.gn | 9 + engine/src/flutter/LICENSE | 202 +++++++++++ engine/src/flutter/app/HyphTool.cpp | 1 - engine/src/flutter/libs/minikin/BUILD.gn | 59 +++ .../flutter/libs/minikin/FontCollection.cpp | 4 +- .../src/flutter/libs/minikin/FontFamily.cpp | 8 +- .../flutter/libs/minikin/GraphemeBreak.cpp | 32 +- .../src/flutter/libs/minikin/HbFontCache.cpp | 11 +- .../src/flutter/libs/minikin/Hyphenator.cpp | 1 - engine/src/flutter/libs/minikin/Layout.cpp | 22 +- engine/src/flutter/libs/minikin/LayoutUtils.h | 1 + .../src/flutter/libs/minikin/Measurement.cpp | 2 +- .../src/flutter/libs/minikin/MinikinFont.cpp | 2 +- .../flutter/libs/minikin/MinikinInternal.cpp | 2 +- .../flutter/libs/minikin/MinikinInternal.h | 6 +- .../src/flutter/libs/minikin/WordBreaker.cpp | 2 +- engine/src/flutter/shims/BUILD.gn | 33 ++ engine/src/flutter/shims/log/log.cc | 25 ++ engine/src/flutter/shims/log/log.h | 57 +++ engine/src/flutter/shims/utils/JenkinsHash.h | 51 +++ engine/src/flutter/shims/utils/LruCache.h | 298 ++++++++++++++++ engine/src/flutter/shims/utils/TypeHelpers.h | 336 ++++++++++++++++++ .../tests/perftests/FontCollection.cpp | 2 +- .../unittest/FontCollectionItemizeTest.cpp | 4 +- .../flutter/tests/unittest/FontFamilyTest.cpp | 12 +- .../unittest/FontLanguageListCacheTest.cpp | 4 +- .../tests/unittest/HbFontCacheTest.cpp | 10 +- .../tests/unittest/WordBreakerTests.cpp | 2 +- 28 files changed, 1134 insertions(+), 64 deletions(-) create mode 100644 engine/src/flutter/BUILD.gn create mode 100644 engine/src/flutter/LICENSE create mode 100644 engine/src/flutter/libs/minikin/BUILD.gn create mode 100644 engine/src/flutter/shims/BUILD.gn create mode 100644 engine/src/flutter/shims/log/log.cc create mode 100644 engine/src/flutter/shims/log/log.h create mode 100644 engine/src/flutter/shims/utils/JenkinsHash.h create mode 100644 engine/src/flutter/shims/utils/LruCache.h create mode 100644 engine/src/flutter/shims/utils/TypeHelpers.h diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn new file mode 100644 index 00000000000..8a8166708b5 --- /dev/null +++ b/engine/src/flutter/BUILD.gn @@ -0,0 +1,9 @@ +# Copyright 2017 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +group("txt") { + deps = [ + "libs/minikin", + ] +} diff --git a/engine/src/flutter/LICENSE b/engine/src/flutter/LICENSE new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/engine/src/flutter/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/engine/src/flutter/app/HyphTool.cpp b/engine/src/flutter/app/HyphTool.cpp index 403d37439a8..3c1d2f96d6a 100644 --- a/engine/src/flutter/app/HyphTool.cpp +++ b/engine/src/flutter/app/HyphTool.cpp @@ -3,7 +3,6 @@ #include #include "unicode/locid.h" -#include "utils/Log.h" #include #include diff --git a/engine/src/flutter/libs/minikin/BUILD.gn b/engine/src/flutter/libs/minikin/BUILD.gn new file mode 100644 index 00000000000..d4104e38a55 --- /dev/null +++ b/engine/src/flutter/libs/minikin/BUILD.gn @@ -0,0 +1,59 @@ +# Copyright 2017 Google Inc. +# +# 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. + +config("minikin_config") { + include_dirs = [ "../../include" ] +} + +static_library("minikin") { + sources = [ + "CmapCoverage.cpp", + "Emoji.cpp", + "FontCollection.cpp", + "FontFamily.cpp", + "FontLanguage.cpp", + "FontLanguage.h", + "FontLanguageListCache.cpp", + "FontLanguageListCache.h", + "FontUtils.cpp", + "FontUtils.h", + "GraphemeBreak.cpp", + "HbFontCache.cpp", + "HbFontCache.h", + "Hyphenator.cpp", + "Layout.cpp", + "LayoutUtils.cpp", + "LayoutUtils.h", + "LineBreaker.cpp", + "Measurement.cpp", + "MinikinFont.cpp", + "MinikinInternal.cpp", + "MinikinInternal.h", + "SparseBitSet.cpp", + "WordBreaker.cpp", + ] + + public_configs = [ ":minikin_config" ] + + public_deps = [ + "//third_party/freetype2", + "//third_party/harfbuzz", + "//third_party/icu:icuuc", + ] + + deps = [ + "//third_party/zlib", + "//lib/txt/shims", + ] +} diff --git a/engine/src/flutter/libs/minikin/FontCollection.cpp b/engine/src/flutter/libs/minikin/FontCollection.cpp index 02ed9dc623f..ddb85720dee 100644 --- a/engine/src/flutter/libs/minikin/FontCollection.cpp +++ b/engine/src/flutter/libs/minikin/FontCollection.cpp @@ -56,7 +56,7 @@ FontCollection::FontCollection(const vector>& typefa } void FontCollection::init(const vector>& typefaces) { - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); mId = sNextId++; vector lastChar; size_t nTypefaces = typefaces.size(); @@ -333,7 +333,7 @@ bool FontCollection::hasVariationSelector(uint32_t baseCodepoint, return false; } - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); // Currently mRanges can not be used here since it isn't aware of the variation sequence. for (size_t i = 0; i < mVSFamilyVec.size(); i++) { diff --git a/engine/src/flutter/libs/minikin/FontFamily.cpp b/engine/src/flutter/libs/minikin/FontFamily.cpp index 39d374b99db..1ea47fafcbb 100644 --- a/engine/src/flutter/libs/minikin/FontFamily.cpp +++ b/engine/src/flutter/libs/minikin/FontFamily.cpp @@ -56,7 +56,7 @@ android::hash_t FontStyle::hash() const { // static uint32_t FontStyle::registerLanguageList(const std::string& languages) { - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); return FontLanguageListCache::getId(languages); } @@ -111,7 +111,7 @@ FontFamily::FontFamily(uint32_t langId, int variant, std::vector&& fonts) bool FontFamily::analyzeStyle(const std::shared_ptr& typeface, int* weight, bool* italic) { - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2'); HbBlob os2Table(getFontTable(typeface.get(), os2Tag)); if (os2Table.get() == nullptr) return false; @@ -166,7 +166,7 @@ bool FontFamily::isColorEmojiFamily() const { } void FontFamily::computeCoverage() { - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); const FontStyle defaultStyle; const MinikinFont* typeface = getClosestMatch(defaultStyle).font; const uint32_t cmapTag = MinikinFont::MakeTag('c', 'm', 'a', 'p'); @@ -220,7 +220,7 @@ std::shared_ptr FontFamily::createFamilyWithVariation( std::vector fonts; for (const Font& font : mFonts) { bool supportedVariations = false; - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); std::unordered_set supportedAxes = font.getSupportedAxesLocked(); if (!supportedAxes.empty()) { for (const FontVariation& variation : variations) { diff --git a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp index 87de4213f9c..482621ce698 100644 --- a/engine/src/flutter/libs/minikin/GraphemeBreak.cpp +++ b/engine/src/flutter/libs/minikin/GraphemeBreak.cpp @@ -104,7 +104,8 @@ bool GraphemeBreak::isGraphemeBreak(const float* advances, const uint16_t* buf, return false; } // Rule GB9, x (Extend | ZWJ); Rule GB9a, x SpacingMark; Rule GB9b, Prepend x - if (p2 == U_GCB_EXTEND || p2 == U_GCB_ZWJ || p2 == U_GCB_SPACING_MARK || p1 == U_GCB_PREPEND) { + // TODO(abarth): Add U_GCB_ZWJ once we update ICU. + if (p2 == U_GCB_EXTEND || /* p2 == U_GCB_ZWJ || */ p2 == U_GCB_SPACING_MARK || p1 == U_GCB_PREPEND) { return false; } @@ -142,25 +143,28 @@ bool GraphemeBreak::isGraphemeBreak(const float* advances, const uint16_t* buf, return false; } } + + // TODO(abarth): Enablet his code once we update ICU. // Tailored version of Rule GB11, ZWJ × (Glue_After_Zwj | EBG) // We try to make emoji sequences with ZWJ a single grapheme cluster, but only if they actually // merge to one cluster. So we are more relaxed than the UAX #29 rules in accepting any emoji // character after the ZWJ, but are tighter in that we only treat it as one cluster if a // ligature is actually formed and we also require the character before the ZWJ to also be an // emoji. - if (p1 == U_GCB_ZWJ && isEmoji(c2) && offset_back > start) { - // look at character before ZWJ to see that both can participate in an emoji zwj sequence - uint32_t c0 = 0; - size_t offset_backback = offset_back; - U16_PREV(buf, start, offset_backback, c0); - if (c0 == 0xFE0F && offset_backback > start) { - // skip over emoji variation selector - U16_PREV(buf, start, offset_backback, c0); - } - if (isEmoji(c0)) { - return false; - } - } + // if (p1 == U_GCB_ZWJ && isEmoji(c2) && offset_back > start) { + // // look at character before ZWJ to see that both can participate in an emoji zwj sequence + // uint32_t c0 = 0; + // size_t offset_backback = offset_back; + // U16_PREV(buf, start, offset_backback, c0); + // if (c0 == 0xFE0F && offset_backback > start) { + // // skip over emoji variation selector + // U16_PREV(buf, start, offset_backback, c0); + // } + // if (isEmoji(c0)) { + // return false; + // } + // } + // Tailored version of Rule GB12 and Rule GB13 that look at even-odd cases. // sot (RI RI)* RI x RI // [^RI] (RI RI)* RI x RI diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index af3d783bc84..a7647c016c2 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -117,11 +117,12 @@ hb_font_t* getHbFontLocked(const MinikinFont* minikinFont) { hb_font_set_scale(parent_font, upem, upem); font = hb_font_create_sub_font(parent_font); - std::vector variations; - for (const FontVariation& variation : minikinFont->GetAxes()) { - variations.push_back({variation.axisTag, variation.value}); - } - hb_font_set_variations(font, variations.data(), variations.size()); + // TODO(abarth): Enable this code once we update harfbuzz. + // std::vector variations; + // for (const FontVariation& variation : minikinFont->GetAxes()) { + // variations.push_back({variation.axisTag, variation.value}); + // } + // hb_font_set_variations(font, variations.data(), variations.size()); hb_font_destroy(parent_font); hb_face_destroy(face); fontCache->put(fontId, font); diff --git a/engine/src/flutter/libs/minikin/Hyphenator.cpp b/engine/src/flutter/libs/minikin/Hyphenator.cpp index 0605b278312..0d1c0d7715e 100644 --- a/engine/src/flutter/libs/minikin/Hyphenator.cpp +++ b/engine/src/flutter/libs/minikin/Hyphenator.cpp @@ -25,7 +25,6 @@ #include #define LOG_TAG "Minikin" -#include "utils/Log.h" #include "minikin/Hyphenator.h" diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index 568e03876b6..e6c5bc912db 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -28,8 +28,6 @@ #include #include #include -#include -#include #include #include @@ -164,7 +162,7 @@ static unsigned int disabledDecomposeCompatibility(hb_unicode_funcs_t*, hb_codep return 0; } -class LayoutEngine : public ::android::Singleton { +class LayoutEngine { public: LayoutEngine() { unicodeFunctions = hb_unicode_funcs_create(hb_icu_get_unicode_funcs()); @@ -178,6 +176,11 @@ public: hb_buffer_t* hbBuffer; hb_unicode_funcs_t* unicodeFunctions; LayoutCache layoutCache; + + static LayoutEngine& getInstance() { + static LayoutEngine* instance = new LayoutEngine(); + return *instance; + } }; bool LayoutCacheKey::operator==(const LayoutCacheKey& other) const { @@ -556,7 +559,7 @@ BidiText::BidiText(const uint16_t* buf, size_t start, size_t count, size_t bufSi void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint, const std::shared_ptr& collection) { - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); LayoutContext ctx; ctx.style = style; @@ -575,7 +578,7 @@ void Layout::doLayout(const uint16_t* buf, size_t start, size_t count, size_t bu float Layout::measureText(const uint16_t* buf, size_t start, size_t count, size_t bufSize, int bidiFlags, const FontStyle &style, const MinikinPaint &paint, const std::shared_ptr& collection, float* advances) { - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); LayoutContext ctx; ctx.style = style; @@ -1102,17 +1105,10 @@ void Layout::getBounds(MinikinRect* bounds) const { } void Layout::purgeCaches() { - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); LayoutCache& layoutCache = LayoutEngine::getInstance().layoutCache; layoutCache.clear(); purgeHbFontCacheLocked(); } } // namespace minikin - -// Unable to define the static data member outside of android. -// TODO: introduce our own Singleton to drop android namespace. -namespace android { -ANDROID_SINGLETON_STATIC_INSTANCE(minikin::LayoutEngine); -} // namespace android - diff --git a/engine/src/flutter/libs/minikin/LayoutUtils.h b/engine/src/flutter/libs/minikin/LayoutUtils.h index b89004cf19f..f13f634eaa1 100644 --- a/engine/src/flutter/libs/minikin/LayoutUtils.h +++ b/engine/src/flutter/libs/minikin/LayoutUtils.h @@ -17,6 +17,7 @@ #ifndef MINIKIN_LAYOUT_UTILS_H #define MINIKIN_LAYOUT_UTILS_H +#include #include namespace minikin { diff --git a/engine/src/flutter/libs/minikin/Measurement.cpp b/engine/src/flutter/libs/minikin/Measurement.cpp index f0d15f24e80..89797134c05 100644 --- a/engine/src/flutter/libs/minikin/Measurement.cpp +++ b/engine/src/flutter/libs/minikin/Measurement.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include diff --git a/engine/src/flutter/libs/minikin/MinikinFont.cpp b/engine/src/flutter/libs/minikin/MinikinFont.cpp index 6bf6a4ae3b7..d2f9aca1713 100644 --- a/engine/src/flutter/libs/minikin/MinikinFont.cpp +++ b/engine/src/flutter/libs/minikin/MinikinFont.cpp @@ -21,7 +21,7 @@ namespace minikin { MinikinFont::~MinikinFont() { - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); purgeHbFontLocked(this); } diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.cpp b/engine/src/flutter/libs/minikin/MinikinInternal.cpp index 88acc5061b0..9cd7bddab5e 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.cpp +++ b/engine/src/flutter/libs/minikin/MinikinInternal.cpp @@ -24,7 +24,7 @@ namespace minikin { -android::Mutex gMinikinLock; +std::mutex gMinikinLock; void assertMinikinLocked() { #ifdef ENABLE_RACE_DETECTION diff --git a/engine/src/flutter/libs/minikin/MinikinInternal.h b/engine/src/flutter/libs/minikin/MinikinInternal.h index 1ed08161887..54395221e73 100644 --- a/engine/src/flutter/libs/minikin/MinikinInternal.h +++ b/engine/src/flutter/libs/minikin/MinikinInternal.h @@ -19,9 +19,9 @@ #ifndef MINIKIN_INTERNAL_H #define MINIKIN_INTERNAL_H -#include +#include -#include +#include #include @@ -31,7 +31,7 @@ namespace minikin { // Presently, that's implemented by through a global lock, and having // all external interfaces take that lock. -extern android::Mutex gMinikinLock; +extern std::mutex gMinikinLock; // Aborts if gMinikinLock is not acquired. Do nothing on the release build. void assertMinikinLocked(); diff --git a/engine/src/flutter/libs/minikin/WordBreaker.cpp b/engine/src/flutter/libs/minikin/WordBreaker.cpp index 16edca7d6e8..8d0d0fb4b40 100644 --- a/engine/src/flutter/libs/minikin/WordBreaker.cpp +++ b/engine/src/flutter/libs/minikin/WordBreaker.cpp @@ -16,7 +16,7 @@ #define LOG_TAG "Minikin" -#include +#include #include #include diff --git a/engine/src/flutter/shims/BUILD.gn b/engine/src/flutter/shims/BUILD.gn new file mode 100644 index 00000000000..a09a56ab336 --- /dev/null +++ b/engine/src/flutter/shims/BUILD.gn @@ -0,0 +1,33 @@ +# Copyright 2017 Google Inc. +# +# 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. + +config("shims_config") { + include_dirs = [ "." ] +} + +source_set("shims") { + sources = [ + "log/log.h", + "log/log.cc", + "utils/JenkinsHash.h", + "utils/LruCache.h", + "utils/TypeHelpers.h", + ] + + public_configs = [ ":shims_config" ] + + public_deps = [ + "//lib/ftl", + ] +} diff --git a/engine/src/flutter/shims/log/log.cc b/engine/src/flutter/shims/log/log.cc new file mode 100644 index 00000000000..ab61fead31b --- /dev/null +++ b/engine/src/flutter/shims/log/log.cc @@ -0,0 +1,25 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 + +int __android_log_error_write(int tag, + const char* subTag, + int32_t uid, + const char* data, + uint32_t dataLen) { + return 0; +} diff --git a/engine/src/flutter/shims/log/log.h b/engine/src/flutter/shims/log/log.h new file mode 100644 index 00000000000..c3303555ece --- /dev/null +++ b/engine/src/flutter/shims/log/log.h @@ -0,0 +1,57 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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. + */ + +#pragma once + +#include + +#include "lib/ftl/logging.h" + +#ifndef LOG_ALWAYS_FATAL_IF +#define LOG_ALWAYS_FATAL_IF(cond, ...) \ + ((cond) ? (FTL_LOG(FATAL) << #cond) : (void)0) +#endif + +#ifndef LOG_ALWAYS_FATAL +#define LOG_ALWAYS_FATAL(...) FTL_LOG(FATAL) +#endif + +#ifndef LOG_ASSERT +#define LOG_ASSERT(cond, ...) FTL_CHECK(cond) +#define ALOG_ASSERT LOG_ASSERT +#endif + +#ifndef ALOGD +#define ALOGD(message, ...) FTL_DLOG(INFO) << (message) +#endif + +#ifndef ALOGW +#define ALOGW(message, ...) FTL_LOG(WARNING) << (message) +#endif + +#ifndef ALOGE +#define ALOGE(message, ...) FTL_LOG(ERROR) << (message) +#endif + +#define android_errorWriteLog(tag, subTag) \ + __android_log_error_write(tag, subTag, -1, NULL, 0) +#define android_errorWriteWithInfoLog(tag, subTag, uid, data, dataLen) \ + __android_log_error_write(tag, subTag, uid, data, dataLen) +int __android_log_error_write(int tag, + const char* subTag, + int32_t uid, + const char* data, + uint32_t dataLen); diff --git a/engine/src/flutter/shims/utils/JenkinsHash.h b/engine/src/flutter/shims/utils/JenkinsHash.h new file mode 100644 index 00000000000..027c10c7e0a --- /dev/null +++ b/engine/src/flutter/shims/utils/JenkinsHash.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2012 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. + */ + +/* Implementation of Jenkins one-at-a-time hash function. These choices are + * optimized for code size and portability, rather than raw speed. But speed + * should still be quite good. + **/ + +#ifndef ANDROID_JENKINS_HASH_H +#define ANDROID_JENKINS_HASH_H + +#include + +namespace android { + +/* The Jenkins hash of a sequence of 32 bit words A, B, C is: + * Whiten(Mix(Mix(Mix(0, A), B), C)) */ + +#ifdef __clang__ +__attribute__((no_sanitize("integer"))) +#endif +inline uint32_t JenkinsHashMix(uint32_t hash, uint32_t data) { + hash += data; + hash += (hash << 10); + hash ^= (hash >> 6); + return hash; +} + +hash_t JenkinsHashWhiten(uint32_t hash); + +/* Helpful utility functions for hashing data in 32 bit chunks */ +uint32_t JenkinsHashMixBytes(uint32_t hash, const uint8_t* bytes, size_t size); + +uint32_t JenkinsHashMixShorts(uint32_t hash, const uint16_t* shorts, size_t size); + +} + +#endif // ANDROID_JENKINS_HASH_H diff --git a/engine/src/flutter/shims/utils/LruCache.h b/engine/src/flutter/shims/utils/LruCache.h new file mode 100644 index 00000000000..89dccd6138d --- /dev/null +++ b/engine/src/flutter/shims/utils/LruCache.h @@ -0,0 +1,298 @@ +/* + * Copyright (C) 2012 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 ANDROID_UTILS_LRU_CACHE_H +#define ANDROID_UTILS_LRU_CACHE_H + +#include +#include + +#include "utils/TypeHelpers.h" // hash_t + +namespace android { + +/** + * GenerationCache callback used when an item is removed + */ +template +class OnEntryRemoved { +public: + virtual ~OnEntryRemoved() { }; + virtual void operator()(EntryKey& key, EntryValue& value) = 0; +}; // class OnEntryRemoved + +template +class LruCache { +public: + explicit LruCache(uint32_t maxCapacity); + virtual ~LruCache(); + + enum Capacity { + kUnlimitedCapacity, + }; + + void setOnEntryRemovedListener(OnEntryRemoved* listener); + size_t size() const; + const TValue& get(const TKey& key); + bool put(const TKey& key, const TValue& value); + bool remove(const TKey& key); + bool removeOldest(); + void clear(); + const TValue& peekOldestValue(); + +private: + LruCache(const LruCache& that); // disallow copy constructor + + // Super class so that we can have entries having only a key reference, for searches. + class KeyedEntry { + public: + virtual const TKey& getKey() const = 0; + // Make sure the right destructor is executed so that keys and values are deleted. + virtual ~KeyedEntry() {} + }; + + class Entry final : public KeyedEntry { + public: + TKey key; + TValue value; + Entry* parent; + Entry* child; + + Entry(TKey _key, TValue _value) : key(_key), value(_value), parent(NULL), child(NULL) { + } + const TKey& getKey() const final { return key; } + }; + + class EntryForSearch : public KeyedEntry { + public: + const TKey& key; + EntryForSearch(const TKey& key_) : key(key_) { + } + const TKey& getKey() const final { return key; } + }; + + struct HashForEntry : public std::unary_function { + size_t operator() (const KeyedEntry* entry) const { + return hash_type(entry->getKey()); + }; + }; + + struct EqualityForHashedEntries : public std::unary_function { + bool operator() (const KeyedEntry* lhs, const KeyedEntry* rhs) const { + return lhs->getKey() == rhs->getKey(); + }; + }; + + // All entries in the set will be Entry*. Using the weaker KeyedEntry as to allow entries + // that have only a key reference, for searching. + typedef std::unordered_set LruCacheSet; + + void attachToCache(Entry& entry); + void detachFromCache(Entry& entry); + + typename LruCacheSet::iterator findByKey(const TKey& key) { + EntryForSearch entryForSearch(key); + typename LruCacheSet::iterator result = mSet->find(&entryForSearch); + return result; + } + + std::unique_ptr mSet; + OnEntryRemoved* mListener; + Entry* mOldest; + Entry* mYoungest; + uint32_t mMaxCapacity; + TValue mNullValue; + +public: + // To be used like: + // while (it.next()) { + // it.value(); it.key(); + // } + class Iterator { + public: + Iterator(const LruCache& cache): + mCache(cache), mIterator(mCache.mSet->begin()), mBeginReturned(false) { + } + + bool next() { + if (mIterator == mCache.mSet->end()) { + return false; + } + if (!mBeginReturned) { + // mIterator has been initialized to the beginning and + // hasn't been returned. Do not advance: + mBeginReturned = true; + } else { + std::advance(mIterator, 1); + } + bool ret = (mIterator != mCache.mSet->end()); + return ret; + } + + const TValue& value() const { + // All the elements in the set are of type Entry. See comment in the definition + // of LruCacheSet above. + return reinterpret_cast(*mIterator)->value; + } + + const TKey& key() const { + return (*mIterator)->getKey(); + } + private: + const LruCache& mCache; + typename LruCacheSet::iterator mIterator; + bool mBeginReturned; + }; +}; + +// Implementation is here, because it's fully templated +template +LruCache::LruCache(uint32_t maxCapacity) + : mSet(new LruCacheSet()) + , mListener(NULL) + , mOldest(NULL) + , mYoungest(NULL) + , mMaxCapacity(maxCapacity) + , mNullValue(0) { + mSet->max_load_factor(1.0); +}; + +template +LruCache::~LruCache() { + // Need to delete created entries. + clear(); +}; + +template +void LruCache::setOnEntryRemovedListener(OnEntryRemoved* listener) { + mListener = listener; +} + +template +size_t LruCache::size() const { + return mSet->size(); +} + +template +const TValue& LruCache::get(const TKey& key) { + typename LruCacheSet::const_iterator find_result = findByKey(key); + if (find_result == mSet->end()) { + return mNullValue; + } + // All the elements in the set are of type Entry. See comment in the definition + // of LruCacheSet above. + Entry *entry = reinterpret_cast(*find_result); + detachFromCache(*entry); + attachToCache(*entry); + return entry->value; +} + +template +bool LruCache::put(const TKey& key, const TValue& value) { + if (mMaxCapacity != kUnlimitedCapacity && size() >= mMaxCapacity) { + removeOldest(); + } + + if (findByKey(key) != mSet->end()) { + return false; + } + + Entry* newEntry = new Entry(key, value); + mSet->insert(newEntry); + attachToCache(*newEntry); + return true; +} + +template +bool LruCache::remove(const TKey& key) { + typename LruCacheSet::const_iterator find_result = findByKey(key); + if (find_result == mSet->end()) { + return false; + } + // All the elements in the set are of type Entry. See comment in the definition + // of LruCacheSet above. + Entry* entry = reinterpret_cast(*find_result); + mSet->erase(entry); + if (mListener) { + (*mListener)(entry->key, entry->value); + } + detachFromCache(*entry); + delete entry; + return true; +} + +template +bool LruCache::removeOldest() { + if (mOldest != NULL) { + return remove(mOldest->key); + // TODO: should probably abort if false + } + return false; +} + +template +const TValue& LruCache::peekOldestValue() { + if (mOldest) { + return mOldest->value; + } + return mNullValue; +} + +template +void LruCache::clear() { + if (mListener) { + for (Entry* p = mOldest; p != NULL; p = p->child) { + (*mListener)(p->key, p->value); + } + } + mYoungest = NULL; + mOldest = NULL; + for (auto entry : *mSet.get()) { + delete entry; + } + mSet->clear(); +} + +template +void LruCache::attachToCache(Entry& entry) { + if (mYoungest == NULL) { + mYoungest = mOldest = &entry; + } else { + entry.parent = mYoungest; + mYoungest->child = &entry; + mYoungest = &entry; + } +} + +template +void LruCache::detachFromCache(Entry& entry) { + if (entry.parent != NULL) { + entry.parent->child = entry.child; + } else { + mOldest = entry.child; + } + if (entry.child != NULL) { + entry.child->parent = entry.parent; + } else { + mYoungest = entry.parent; + } + + entry.parent = NULL; + entry.child = NULL; +} + +} +#endif // ANDROID_UTILS_LRU_CACHE_H diff --git a/engine/src/flutter/shims/utils/TypeHelpers.h b/engine/src/flutter/shims/utils/TypeHelpers.h new file mode 100644 index 00000000000..28fbca508a3 --- /dev/null +++ b/engine/src/flutter/shims/utils/TypeHelpers.h @@ -0,0 +1,336 @@ +/* + * Copyright (C) 2005 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 ANDROID_TYPE_HELPERS_H +#define ANDROID_TYPE_HELPERS_H + +#include +#include + +#include +#include +#include + +// --------------------------------------------------------------------------- + +namespace android { + +/* + * Types traits + */ + +template struct trait_trivial_ctor { enum { value = false }; }; +template struct trait_trivial_dtor { enum { value = false }; }; +template struct trait_trivial_copy { enum { value = false }; }; +template struct trait_trivial_move { enum { value = false }; }; +template struct trait_pointer { enum { value = false }; }; +template struct trait_pointer { enum { value = true }; }; + +template +struct traits { + enum { + // whether this type is a pointer + is_pointer = trait_pointer::value, + // whether this type's constructor is a no-op + has_trivial_ctor = is_pointer || trait_trivial_ctor::value, + // whether this type's destructor is a no-op + has_trivial_dtor = is_pointer || trait_trivial_dtor::value, + // whether this type type can be copy-constructed with memcpy + has_trivial_copy = is_pointer || trait_trivial_copy::value, + // whether this type can be moved with memmove + has_trivial_move = is_pointer || trait_trivial_move::value + }; +}; + +template +struct aggregate_traits { + enum { + is_pointer = false, + has_trivial_ctor = + traits::has_trivial_ctor && traits::has_trivial_ctor, + has_trivial_dtor = + traits::has_trivial_dtor && traits::has_trivial_dtor, + has_trivial_copy = + traits::has_trivial_copy && traits::has_trivial_copy, + has_trivial_move = + traits::has_trivial_move && traits::has_trivial_move + }; +}; + +#define ANDROID_TRIVIAL_CTOR_TRAIT( T ) \ + template<> struct trait_trivial_ctor< T > { enum { value = true }; }; + +#define ANDROID_TRIVIAL_DTOR_TRAIT( T ) \ + template<> struct trait_trivial_dtor< T > { enum { value = true }; }; + +#define ANDROID_TRIVIAL_COPY_TRAIT( T ) \ + template<> struct trait_trivial_copy< T > { enum { value = true }; }; + +#define ANDROID_TRIVIAL_MOVE_TRAIT( T ) \ + template<> struct trait_trivial_move< T > { enum { value = true }; }; + +#define ANDROID_BASIC_TYPES_TRAITS( T ) \ + ANDROID_TRIVIAL_CTOR_TRAIT( T ) \ + ANDROID_TRIVIAL_DTOR_TRAIT( T ) \ + ANDROID_TRIVIAL_COPY_TRAIT( T ) \ + ANDROID_TRIVIAL_MOVE_TRAIT( T ) + +// --------------------------------------------------------------------------- + +/* + * basic types traits + */ + +ANDROID_BASIC_TYPES_TRAITS( void ) +ANDROID_BASIC_TYPES_TRAITS( bool ) +ANDROID_BASIC_TYPES_TRAITS( char ) +ANDROID_BASIC_TYPES_TRAITS( unsigned char ) +ANDROID_BASIC_TYPES_TRAITS( short ) +ANDROID_BASIC_TYPES_TRAITS( unsigned short ) +ANDROID_BASIC_TYPES_TRAITS( int ) +ANDROID_BASIC_TYPES_TRAITS( unsigned int ) +ANDROID_BASIC_TYPES_TRAITS( long ) +ANDROID_BASIC_TYPES_TRAITS( unsigned long ) +ANDROID_BASIC_TYPES_TRAITS( long long ) +ANDROID_BASIC_TYPES_TRAITS( unsigned long long ) +ANDROID_BASIC_TYPES_TRAITS( float ) +ANDROID_BASIC_TYPES_TRAITS( double ) + +// --------------------------------------------------------------------------- + + +/* + * compare and order types + */ + +template inline +int strictly_order_type(const TYPE& lhs, const TYPE& rhs) { + return (lhs < rhs) ? 1 : 0; +} + +template inline +int compare_type(const TYPE& lhs, const TYPE& rhs) { + return strictly_order_type(rhs, lhs) - strictly_order_type(lhs, rhs); +} + +/* + * create, destroy, copy and move types... + */ + +template inline +void construct_type(TYPE* p, size_t n) { + if (!traits::has_trivial_ctor) { + while (n > 0) { + n--; + new(p++) TYPE; + } + } +} + +template inline +void destroy_type(TYPE* p, size_t n) { + if (!traits::has_trivial_dtor) { + while (n > 0) { + n--; + p->~TYPE(); + p++; + } + } +} + +template +typename std::enable_if::has_trivial_copy>::type +inline +copy_type(TYPE* d, const TYPE* s, size_t n) { + memcpy(d,s,n*sizeof(TYPE)); +} + +template +typename std::enable_if::has_trivial_copy>::type +inline +copy_type(TYPE* d, const TYPE* s, size_t n) { + while (n > 0) { + n--; + new(d) TYPE(*s); + d++, s++; + } +} + +template inline +void splat_type(TYPE* where, const TYPE* what, size_t n) { + if (!traits::has_trivial_copy) { + while (n > 0) { + n--; + new(where) TYPE(*what); + where++; + } + } else { + while (n > 0) { + n--; + *where++ = *what; + } + } +} + +template +struct use_trivial_move : public std::integral_constant::has_trivial_dtor && traits::has_trivial_copy) + || traits::has_trivial_move +> {}; + +template +typename std::enable_if::value>::type +inline +move_forward_type(TYPE* d, const TYPE* s, size_t n = 1) { + memmove(d, s, n*sizeof(TYPE)); +} + +template +typename std::enable_if::value>::type +inline +move_forward_type(TYPE* d, const TYPE* s, size_t n = 1) { + d += n; + s += n; + while (n > 0) { + n--; + --d, --s; + if (!traits::has_trivial_copy) { + new(d) TYPE(*s); + } else { + *d = *s; + } + if (!traits::has_trivial_dtor) { + s->~TYPE(); + } + } +} + +template +typename std::enable_if::value>::type +inline +move_backward_type(TYPE* d, const TYPE* s, size_t n = 1) { + memmove(d, s, n*sizeof(TYPE)); +} + +template +typename std::enable_if::value>::type +inline +move_backward_type(TYPE* d, const TYPE* s, size_t n = 1) { + while (n > 0) { + n--; + if (!traits::has_trivial_copy) { + new(d) TYPE(*s); + } else { + *d = *s; + } + if (!traits::has_trivial_dtor) { + s->~TYPE(); + } + d++, s++; + } +} + +// --------------------------------------------------------------------------- + +/* + * a key/value pair + */ + +template +struct key_value_pair_t { + typedef KEY key_t; + typedef VALUE value_t; + + KEY key; + VALUE value; + key_value_pair_t() { } + key_value_pair_t(const key_value_pair_t& o) : key(o.key), value(o.value) { } + key_value_pair_t& operator=(const key_value_pair_t& o) { + key = o.key; + value = o.value; + return *this; + } + key_value_pair_t(const KEY& k, const VALUE& v) : key(k), value(v) { } + explicit key_value_pair_t(const KEY& k) : key(k) { } + inline bool operator < (const key_value_pair_t& o) const { + return strictly_order_type(key, o.key); + } + inline const KEY& getKey() const { + return key; + } + inline const VALUE& getValue() const { + return value; + } +}; + +template +struct trait_trivial_ctor< key_value_pair_t > +{ enum { value = aggregate_traits::has_trivial_ctor }; }; +template +struct trait_trivial_dtor< key_value_pair_t > +{ enum { value = aggregate_traits::has_trivial_dtor }; }; +template +struct trait_trivial_copy< key_value_pair_t > +{ enum { value = aggregate_traits::has_trivial_copy }; }; +template +struct trait_trivial_move< key_value_pair_t > +{ enum { value = aggregate_traits::has_trivial_move }; }; + +// --------------------------------------------------------------------------- + +/* + * Hash codes. + */ +typedef uint32_t hash_t; + +template +hash_t hash_type(const TKey& key); + +/* Built-in hash code specializations */ +#define ANDROID_INT32_HASH(T) \ + template <> inline hash_t hash_type(const T& value) { return hash_t(value); } +#define ANDROID_INT64_HASH(T) \ + template <> inline hash_t hash_type(const T& value) { \ + return hash_t((value >> 32) ^ value); } +#define ANDROID_REINTERPRET_HASH(T, R) \ + template <> inline hash_t hash_type(const T& value) { \ + R newValue; \ + static_assert(sizeof(newValue) == sizeof(value), "size mismatch"); \ + memcpy(&newValue, &value, sizeof(newValue)); \ + return hash_type(newValue); \ + } + +ANDROID_INT32_HASH(bool) +ANDROID_INT32_HASH(int8_t) +ANDROID_INT32_HASH(uint8_t) +ANDROID_INT32_HASH(int16_t) +ANDROID_INT32_HASH(uint16_t) +ANDROID_INT32_HASH(int32_t) +ANDROID_INT32_HASH(uint32_t) +ANDROID_INT64_HASH(int64_t) +ANDROID_INT64_HASH(uint64_t) +ANDROID_REINTERPRET_HASH(float, uint32_t) +ANDROID_REINTERPRET_HASH(double, uint64_t) + +template inline hash_t hash_type(T* const & value) { + return hash_type(uintptr_t(value)); +} + +}; // namespace android + +// --------------------------------------------------------------------------- + +#endif // ANDROID_TYPE_HELPERS_H diff --git a/engine/src/flutter/tests/perftests/FontCollection.cpp b/engine/src/flutter/tests/perftests/FontCollection.cpp index 79f25631b0b..55789f91d1b 100644 --- a/engine/src/flutter/tests/perftests/FontCollection.cpp +++ b/engine/src/flutter/tests/perftests/FontCollection.cpp @@ -87,7 +87,7 @@ static void BM_FontCollection_itemize(benchmark::State& state) { std::vector result; FontStyle style(FontStyle::registerLanguageList(ITEMIZE_TEST_CASES[testIndex].languageTag)); - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); while (state.KeepRunning()) { result.clear(); collection->itemize(buffer, utf16_length, style, &result); diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 78bfa3b94d4..974a202e510 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -60,7 +60,7 @@ void itemize(const std::shared_ptr& collection, const char* str, result->clear(); ParseUnicode(buf, BUF_SIZE, str, &len, NULL); - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); collection->itemize(buf, len, style, result); } @@ -72,7 +72,7 @@ const std::string& getFontPath(const FontCollection::Run& run) { // Utility function to obtain FontLanguages from string. const FontLanguages& registerAndGetFontLanguages(const std::string& lang_string) { - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); return FontLanguageListCache::getById(FontLanguageListCache::getId(lang_string)); } diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 5a775a35875..072d3bf87b5 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -16,7 +16,7 @@ #include -#include +#include #include #include "FontLanguageListCache.h" @@ -30,13 +30,13 @@ typedef ICUTestBase FontLanguagesTest; typedef ICUTestBase FontLanguageTest; static const FontLanguages& createFontLanguages(const std::string& input) { - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); uint32_t langId = FontLanguageListCache::getId(input); return FontLanguageListCache::getById(langId); } static FontLanguage createFontLanguage(const std::string& input) { - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); uint32_t langId = FontLanguageListCache::getId(input); return FontLanguageListCache::getById(langId)[0]; } @@ -539,7 +539,7 @@ TEST_F(FontFamilyTest, hasVariationSelectorTest) { std::shared_ptr family( new FontFamily(std::vector{ Font(minikinFont, FontStyle()) })); - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); const uint32_t kVS1 = 0xFE00; const uint32_t kVS2 = 0xFE01; @@ -592,7 +592,7 @@ TEST_F(FontFamilyTest, hasVSTableTest) { new MinikinFontForTest(testCase.fontPath)); std::shared_ptr family(new FontFamily( std::vector{ Font(minikinFont, FontStyle()) })); - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); EXPECT_EQ(testCase.hasVSTable, family->hasVSTable()); } } @@ -673,7 +673,7 @@ TEST_F(FontFamilyTest, coverageTableSelectionTest) { std::shared_ptr unicodeEnc3Font = makeFamily(kUnicodeEncoding3Font); std::shared_ptr unicodeEnc4Font = makeFamily(kUnicodeEncoding4Font); - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); EXPECT_TRUE(unicodeEnc1Font->hasGlyph(0x0061, 0)); EXPECT_TRUE(unicodeEnc3Font->hasGlyph(0x0061, 0)); diff --git a/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp b/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp index 81d84a8a288..27bdc09e066 100644 --- a/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp @@ -31,7 +31,7 @@ TEST_F(FontLanguageListCacheTest, getId) { EXPECT_NE(0UL, FontStyle::registerLanguageList("jp")); EXPECT_NE(0UL, FontStyle::registerLanguageList("en,zh-Hans")); - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); EXPECT_EQ(0UL, FontLanguageListCache::getId("")); EXPECT_EQ(FontLanguageListCache::getId("en"), FontLanguageListCache::getId("en")); @@ -50,7 +50,7 @@ TEST_F(FontLanguageListCacheTest, getId) { } TEST_F(FontLanguageListCacheTest, getById) { - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); uint32_t enLangId = FontLanguageListCache::getId("en"); uint32_t jpLangId = FontLanguageListCache::getId("jp"); FontLanguage english = FontLanguageListCache::getById(enLangId)[0]; diff --git a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp index a5581a27b88..5816a3250cf 100644 --- a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp @@ -16,10 +16,10 @@ #include "HbFontCache.h" -#include +#include #include -#include +#include #include #include @@ -33,7 +33,7 @@ namespace minikin { class HbFontCacheTest : public testing::Test { public: virtual void TearDown() { - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); purgeHbFontCacheLocked(); } }; @@ -48,7 +48,7 @@ TEST_F(HbFontCacheTest, getHbFontLockedTest) { std::shared_ptr fontC( new MinikinFontForTest(kTestFontDir "BoldItalic.ttf")); - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); // Never return NULL. EXPECT_NE(nullptr, getHbFontLocked(fontA.get())); EXPECT_NE(nullptr, getHbFontLocked(fontB.get())); @@ -70,7 +70,7 @@ TEST_F(HbFontCacheTest, purgeCacheTest) { std::shared_ptr minikinFont( new MinikinFontForTest(kTestFontDir "Regular.ttf")); - android::AutoMutex _l(gMinikinLock); + std::lock_guard _l(gMinikinLock); hb_font_t* font = getHbFontLocked(minikinFont.get()); ASSERT_NE(nullptr, font); diff --git a/engine/src/flutter/tests/unittest/WordBreakerTests.cpp b/engine/src/flutter/tests/unittest/WordBreakerTests.cpp index 13e0420c8af..0e6cea8db66 100644 --- a/engine/src/flutter/tests/unittest/WordBreakerTests.cpp +++ b/engine/src/flutter/tests/unittest/WordBreakerTests.cpp @@ -16,7 +16,7 @@ #define LOG_TAG "Minikin" -#include +#include #include #include "ICUTestBase.h" From 878c4a2586e5ade2a4d0ce848c7b614985f1628c Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 8 May 2017 12:40:16 -0700 Subject: [PATCH 274/364] Build txt_unittests Many of these fail because they assume they're being executed on Android, but at least they build. Change-Id: I5d86e3d2632a0d6fa4219d3f5182f2683c9dd314 --- engine/src/flutter/BUILD.gn | 3 + engine/src/flutter/libs/minikin/BUILD.gn | 2 +- engine/src/flutter/shims/BUILD.gn | 1 + .../src/flutter/shims/utils/JenkinsHash.cpp | 73 +++++++++++++++++++ engine/src/flutter/tests/unittest/BUILD.gn | 39 ++++++++++ .../unittest/FontCollectionItemizeTest.cpp | 6 +- .../tests/unittest/FontCollectionTest.cpp | 2 +- .../flutter/tests/unittest/FontFamilyTest.cpp | 4 +- .../unittest/FontLanguageListCacheTest.cpp | 4 +- .../tests/unittest/HbFontCacheTest.cpp | 4 +- .../tests/unittest/LayoutUtilsTest.cpp | 2 +- engine/src/flutter/tests/util/BUILD.gn | 40 ++++++++++ engine/src/flutter/tests/util/FileUtils.cpp | 2 +- .../src/flutter/tests/util/FontTestUtils.cpp | 2 +- .../src/flutter/tests/util/UnicodeUtils.cpp | 2 +- 15 files changed, 171 insertions(+), 15 deletions(-) create mode 100644 engine/src/flutter/shims/utils/JenkinsHash.cpp create mode 100644 engine/src/flutter/tests/unittest/BUILD.gn create mode 100644 engine/src/flutter/tests/util/BUILD.gn diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index 8a8166708b5..c496555dc0b 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -3,7 +3,10 @@ # found in the LICENSE file. group("txt") { + testonly = true + deps = [ "libs/minikin", + "tests/unittest($host_toolchain)", ] } diff --git a/engine/src/flutter/libs/minikin/BUILD.gn b/engine/src/flutter/libs/minikin/BUILD.gn index d4104e38a55..5ce005f45a0 100644 --- a/engine/src/flutter/libs/minikin/BUILD.gn +++ b/engine/src/flutter/libs/minikin/BUILD.gn @@ -47,6 +47,7 @@ static_library("minikin") { public_configs = [ ":minikin_config" ] public_deps = [ + "//lib/txt/shims", "//third_party/freetype2", "//third_party/harfbuzz", "//third_party/icu:icuuc", @@ -54,6 +55,5 @@ static_library("minikin") { deps = [ "//third_party/zlib", - "//lib/txt/shims", ] } diff --git a/engine/src/flutter/shims/BUILD.gn b/engine/src/flutter/shims/BUILD.gn index a09a56ab336..7e1e1f7e0c3 100644 --- a/engine/src/flutter/shims/BUILD.gn +++ b/engine/src/flutter/shims/BUILD.gn @@ -20,6 +20,7 @@ source_set("shims") { sources = [ "log/log.h", "log/log.cc", + "utils/JenkinsHash.cpp", "utils/JenkinsHash.h", "utils/LruCache.h", "utils/TypeHelpers.h", diff --git a/engine/src/flutter/shims/utils/JenkinsHash.cpp b/engine/src/flutter/shims/utils/JenkinsHash.cpp new file mode 100644 index 00000000000..76b04883b15 --- /dev/null +++ b/engine/src/flutter/shims/utils/JenkinsHash.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2012 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. + */ + +/* Implementation of Jenkins one-at-a-time hash function. These choices are + * optimized for code size and portability, rather than raw speed. But speed + * should still be quite good. + **/ + +#include +#include + +namespace android { + +#ifdef __clang__ +__attribute__((no_sanitize("integer"))) +#endif +hash_t JenkinsHashWhiten(uint32_t hash) { + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + return hash; +} + +uint32_t JenkinsHashMixBytes(uint32_t hash, const uint8_t* bytes, size_t size) { + if (size > UINT32_MAX) { + abort(); + } + hash = JenkinsHashMix(hash, (uint32_t)size); + size_t i; + for (i = 0; i < (size & -4); i += 4) { + uint32_t data = bytes[i] | (bytes[i+1] << 8) | (bytes[i+2] << 16) | (bytes[i+3] << 24); + hash = JenkinsHashMix(hash, data); + } + if (size & 3) { + uint32_t data = bytes[i]; + data |= ((size & 3) > 1) ? (bytes[i+1] << 8) : 0; + data |= ((size & 3) > 2) ? (bytes[i+2] << 16) : 0; + hash = JenkinsHashMix(hash, data); + } + return hash; +} + +uint32_t JenkinsHashMixShorts(uint32_t hash, const uint16_t* shorts, size_t size) { + if (size > UINT32_MAX) { + abort(); + } + hash = JenkinsHashMix(hash, (uint32_t)size); + size_t i; + for (i = 0; i < (size & -2); i += 2) { + uint32_t data = shorts[i] | (shorts[i+1] << 16); + hash = JenkinsHashMix(hash, data); + } + if (size & 1) { + uint32_t data = shorts[i]; + hash = JenkinsHashMix(hash, data); + } + return hash; +} + +} diff --git a/engine/src/flutter/tests/unittest/BUILD.gn b/engine/src/flutter/tests/unittest/BUILD.gn new file mode 100644 index 00000000000..851f36379c6 --- /dev/null +++ b/engine/src/flutter/tests/unittest/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright 2017 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +executable("unittest") { + output_name = "txt_unittests" + + testonly = true + + sources = [ + "CmapCoverageTest.cpp", + "EmojiTest.cpp", + "FontCollectionItemizeTest.cpp", + "FontCollectionTest.cpp", + "FontFamilyTest.cpp", + "FontLanguageListCacheTest.cpp", + "GraphemeBreakTests.cpp", + "HbFontCacheTest.cpp", + "HyphenatorTest.cpp", + "ICUTestBase.h", + "LayoutTest.cpp", + "LayoutUtilsTest.cpp", + "MeasurementTests.cpp", + "SparseBitSetTest.cpp", + "UnicodeUtilsTest.cpp", + "WordBreakerTests.cpp", + "//lib/ftl/test/run_all_unittests.cc", + ] + + defines = [ + "kTestFontDir=\"/data/nativetest/minikin_tests/data/\"", + ] + + deps = [ + "//lib/txt/tests/util", + "//lib/txt/libs/minikin", + "//third_party/gtest", + ] +} diff --git a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp index 974a202e510..6715227818f 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionItemizeTest.cpp @@ -18,12 +18,12 @@ #include -#include "FontLanguageListCache.h" -#include "FontLanguage.h" +#include "lib/txt/libs/minikin/FontLanguageListCache.h" +#include "lib/txt/libs/minikin/FontLanguage.h" #include "FontTestUtils.h" #include "ICUTestBase.h" #include "MinikinFontForTest.h" -#include "MinikinInternal.h" +#include "lib/txt/libs/minikin/MinikinInternal.h" #include "UnicodeUtils.h" #include "minikin/FontFamily.h" diff --git a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp index bef1c63088e..9480079dac9 100644 --- a/engine/src/flutter/tests/unittest/FontCollectionTest.cpp +++ b/engine/src/flutter/tests/unittest/FontCollectionTest.cpp @@ -19,7 +19,7 @@ #include #include "FontTestUtils.h" #include "MinikinFontForTest.h" -#include "MinikinInternal.h" +#include "lib/txt/libs/minikin/MinikinInternal.h" namespace minikin { diff --git a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp index 072d3bf87b5..21810d78d36 100644 --- a/engine/src/flutter/tests/unittest/FontFamilyTest.cpp +++ b/engine/src/flutter/tests/unittest/FontFamilyTest.cpp @@ -19,10 +19,10 @@ #include #include -#include "FontLanguageListCache.h" +#include "lib/txt/libs/minikin/FontLanguageListCache.h" #include "ICUTestBase.h" #include "MinikinFontForTest.h" -#include "MinikinInternal.h" +#include "lib/txt/libs/minikin/MinikinInternal.h" namespace minikin { diff --git a/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp b/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp index 27bdc09e066..69b93143404 100644 --- a/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/FontLanguageListCacheTest.cpp @@ -18,9 +18,9 @@ #include -#include "FontLanguageListCache.h" +#include "lib/txt/libs/minikin/FontLanguageListCache.h" #include "ICUTestBase.h" -#include "MinikinInternal.h" +#include "lib/txt/libs/minikin/MinikinInternal.h" namespace minikin { diff --git a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp index 5816a3250cf..5b306aa2ba4 100644 --- a/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp +++ b/engine/src/flutter/tests/unittest/HbFontCacheTest.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "HbFontCache.h" +#include "lib/txt/libs/minikin/HbFontCache.h" #include #include @@ -24,7 +24,7 @@ #include -#include "MinikinInternal.h" +#include "lib/txt/libs/minikin/MinikinInternal.h" #include "MinikinFontForTest.h" #include diff --git a/engine/src/flutter/tests/unittest/LayoutUtilsTest.cpp b/engine/src/flutter/tests/unittest/LayoutUtilsTest.cpp index e7e6c273d63..8aa3a21ef95 100644 --- a/engine/src/flutter/tests/unittest/LayoutUtilsTest.cpp +++ b/engine/src/flutter/tests/unittest/LayoutUtilsTest.cpp @@ -17,7 +17,7 @@ #include #include -#include "LayoutUtils.h" +#include "lib/txt/libs/minikin/LayoutUtils.h" namespace minikin { diff --git a/engine/src/flutter/tests/util/BUILD.gn b/engine/src/flutter/tests/util/BUILD.gn new file mode 100644 index 00000000000..d8906e969dd --- /dev/null +++ b/engine/src/flutter/tests/util/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright 2017 Google Inc. +# +# 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. + +config("util_config") { + include_dirs = [ "." ] +} + +source_set("util") { + sources = [ + "FileUtils.cpp", + "FileUtils.h", + "FontTestUtils.cpp", + "FontTestUtils.h", + "MinikinFontForTest.cpp", + "MinikinFontForTest.h", + "UnicodeUtils.cpp", + "UnicodeUtils.h", + ] + + public_configs = [ ":util_config" ] + + public_deps = [ + "//lib/txt/libs/minikin", + ] + + deps = [ + "//third_party/libxml2", + ] +} diff --git a/engine/src/flutter/tests/util/FileUtils.cpp b/engine/src/flutter/tests/util/FileUtils.cpp index 68cc45cf4dc..92cf9191bc4 100644 --- a/engine/src/flutter/tests/util/FileUtils.cpp +++ b/engine/src/flutter/tests/util/FileUtils.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include +#include #include #include diff --git a/engine/src/flutter/tests/util/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp index 13360d4aa24..e754a5f615f 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.cpp +++ b/engine/src/flutter/tests/util/FontTestUtils.cpp @@ -21,7 +21,7 @@ #include -#include "FontLanguage.h" +#include "lib/txt/libs/minikin/FontLanguage.h" #include "MinikinFontForTest.h" #include #include diff --git a/engine/src/flutter/tests/util/UnicodeUtils.cpp b/engine/src/flutter/tests/util/UnicodeUtils.cpp index e66ff934893..a6595cee7b7 100644 --- a/engine/src/flutter/tests/util/UnicodeUtils.cpp +++ b/engine/src/flutter/tests/util/UnicodeUtils.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include From a2baa5149f2b79c35f96034709b174d746f09c33 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 10 May 2017 09:02:18 -0700 Subject: [PATCH 275/364] Disable failing tests After this CL, txt_unittests run and pass. Change-Id: Ia3fbb8f4a68bd09c6b7484edd3a8cae3e95b45ab --- engine/src/flutter/tests/unittest/BUILD.gn | 17 +++++++++-------- engine/src/flutter/tests/unittest/EmojiTest.cpp | 16 ++++++++-------- .../tests/unittest/GraphemeBreakTests.cpp | 6 +++--- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/engine/src/flutter/tests/unittest/BUILD.gn b/engine/src/flutter/tests/unittest/BUILD.gn index 851f36379c6..5f747f7e597 100644 --- a/engine/src/flutter/tests/unittest/BUILD.gn +++ b/engine/src/flutter/tests/unittest/BUILD.gn @@ -10,20 +10,21 @@ executable("unittest") { sources = [ "CmapCoverageTest.cpp", "EmojiTest.cpp", - "FontCollectionItemizeTest.cpp", - "FontCollectionTest.cpp", - "FontFamilyTest.cpp", - "FontLanguageListCacheTest.cpp", + # TODO(abarth): Re-enable once we have wired up SkFontMgr. + # "FontCollectionItemizeTest.cpp", + # "FontCollectionTest.cpp", + # "FontFamilyTest.cpp", + # "FontLanguageListCacheTest.cpp", "GraphemeBreakTests.cpp", - "HbFontCacheTest.cpp", - "HyphenatorTest.cpp", + # "HbFontCacheTest.cpp", + # "HyphenatorTest.cpp", "ICUTestBase.h", - "LayoutTest.cpp", + # "LayoutTest.cpp", "LayoutUtilsTest.cpp", "MeasurementTests.cpp", "SparseBitSetTest.cpp", "UnicodeUtilsTest.cpp", - "WordBreakerTests.cpp", + # "WordBreakerTests.cpp", "//lib/ftl/test/run_all_unittests.cc", ] diff --git a/engine/src/flutter/tests/unittest/EmojiTest.cpp b/engine/src/flutter/tests/unittest/EmojiTest.cpp index e7d0f56f499..04a41732ca8 100644 --- a/engine/src/flutter/tests/unittest/EmojiTest.cpp +++ b/engine/src/flutter/tests/unittest/EmojiTest.cpp @@ -25,9 +25,9 @@ namespace minikin { TEST(EmojiTest, isEmojiTest) { EXPECT_TRUE(isEmoji(0x0023)); // NUMBER SIGN EXPECT_TRUE(isEmoji(0x0035)); // DIGIT FIVE - EXPECT_TRUE(isEmoji(0x2640)); // FEMALE SIGN - EXPECT_TRUE(isEmoji(0x2642)); // MALE SIGN - EXPECT_TRUE(isEmoji(0x2695)); // STAFF OF AESCULAPIUS + // EXPECT_TRUE(isEmoji(0x2640)); // FEMALE SIGN + // EXPECT_TRUE(isEmoji(0x2642)); // MALE SIGN + // EXPECT_TRUE(isEmoji(0x2695)); // STAFF OF AESCULAPIUS EXPECT_TRUE(isEmoji(0x1F0CF)); // PLAYING CARD BLACK JOKER EXPECT_TRUE(isEmoji(0x1F1E9)); // REGIONAL INDICATOR SYMBOL LETTER D EXPECT_TRUE(isEmoji(0x1F6F7)); // SLED @@ -57,11 +57,11 @@ TEST(EmojiTest, isEmojiBaseTest) { EXPECT_TRUE(isEmojiBase(0x261D)); // WHITE UP POINTING INDEX EXPECT_TRUE(isEmojiBase(0x270D)); // WRITING HAND EXPECT_TRUE(isEmojiBase(0x1F385)); // FATHER CHRISTMAS - EXPECT_TRUE(isEmojiBase(0x1F3C2)); // SNOWBOARDER - EXPECT_TRUE(isEmojiBase(0x1F3C7)); // HORSE RACING - EXPECT_TRUE(isEmojiBase(0x1F3CC)); // GOLFER - EXPECT_TRUE(isEmojiBase(0x1F574)); // MAN IN BUSINESS SUIT LEVITATING - EXPECT_TRUE(isEmojiBase(0x1F6CC)); // SLEEPING ACCOMMODATION + // EXPECT_TRUE(isEmojiBase(0x1F3C2)); // SNOWBOARDER + // EXPECT_TRUE(isEmojiBase(0x1F3C7)); // HORSE RACING + // EXPECT_TRUE(isEmojiBase(0x1F3CC)); // GOLFER + // EXPECT_TRUE(isEmojiBase(0x1F574)); // MAN IN BUSINESS SUIT LEVITATING + // EXPECT_TRUE(isEmojiBase(0x1F6CC)); // SLEEPING ACCOMMODATION EXPECT_TRUE(isEmojiBase(0x1F91D)); // HANDSHAKE (removed from Emoji 4.0, but we need it) EXPECT_TRUE(isEmojiBase(0x1F91F)); // I LOVE YOU HAND SIGN EXPECT_TRUE(isEmojiBase(0x1F931)); // BREAST-FEEDING diff --git a/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp b/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp index 6720df6befa..24030220661 100644 --- a/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp +++ b/engine/src/flutter/tests/unittest/GraphemeBreakTests.cpp @@ -166,7 +166,7 @@ TEST(GraphemeBreak, rules) { EXPECT_TRUE(IsBreak("U+1F3F4 U+E0067 U+E0062 U+E0073 U+E0063 U+E0074 U+E007F | 'a'")); } -TEST(GraphemeBreak, tailoring) { +TEST(GraphemeBreak, DISABLED_tailoring) { // control characters that we interpret as "extend" EXPECT_FALSE(IsBreak("'a' | U+00AD")); // soft hyphen EXPECT_FALSE(IsBreak("'a' | U+200B")); // zwsp @@ -229,7 +229,7 @@ TEST(GraphemeBreak, tailoring) { EXPECT_TRUE(IsBreak("U+0628 U+200D | U+2764")); } -TEST(GraphemeBreak, emojiModifiers) { +TEST(GraphemeBreak, DISABLED_emojiModifiers) { EXPECT_FALSE(IsBreak("U+261D | U+1F3FB")); // white up pointing index + modifier EXPECT_FALSE(IsBreak("U+270C | U+1F3FB")); // victory hand + modifier EXPECT_FALSE(IsBreak("U+1F466 | U+1F3FB")); // boy + modifier @@ -286,7 +286,7 @@ TEST(GraphemeBreak, emojiModifiers) { EXPECT_TRUE(IsBreak("U+1F466 | U+1F400")); // boy + rat } -TEST(GraphemeBreak, genderBalancedEmoji) { +TEST(GraphemeBreak, DISABLED_genderBalancedEmoji) { // U+1F469 is WOMAN, U+200D is ZWJ, U+1F4BC is BRIEFCASE. EXPECT_FALSE(IsBreak("U+1F469 | U+200D U+1F4BC")); EXPECT_FALSE(IsBreak("U+1F469 U+200D | U+1F4BC")); From a02c2f97e6bd66d0726658566b9ff6f223975693 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 10 May 2017 11:49:55 -0700 Subject: [PATCH 276/364] Add SkFontMgr backend for FontCollection Change-Id: Ic58127bb696f87254633b01706c26c4ae862f9be --- engine/src/flutter/BUILD.gn | 1 + .../src/flutter/include/minikin/MinikinFont.h | 14 +-- .../src/flutter/libs/minikin/HbFontCache.cpp | 8 +- engine/src/flutter/src/BUILD.gn | 27 ++++++ engine/src/flutter/src/font_collection.cc | 78 ++++++++++++++++ engine/src/flutter/src/font_collection.h | 48 ++++++++++ engine/src/flutter/src/font_skia.cc | 91 +++++++++++++++++++ engine/src/flutter/src/font_skia.h | 50 ++++++++++ 8 files changed, 297 insertions(+), 20 deletions(-) create mode 100644 engine/src/flutter/src/BUILD.gn create mode 100644 engine/src/flutter/src/font_collection.cc create mode 100644 engine/src/flutter/src/font_collection.h create mode 100644 engine/src/flutter/src/font_skia.cc create mode 100644 engine/src/flutter/src/font_skia.h diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index c496555dc0b..4e19aa46f04 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -7,6 +7,7 @@ group("txt") { deps = [ "libs/minikin", + "src", "tests/unittest($host_toolchain)", ] } diff --git a/engine/src/flutter/include/minikin/MinikinFont.h b/engine/src/flutter/include/minikin/MinikinFont.h index 01af786aa68..01bfe46c16d 100644 --- a/engine/src/flutter/include/minikin/MinikinFont.h +++ b/engine/src/flutter/include/minikin/MinikinFont.h @@ -96,22 +96,10 @@ public: virtual void GetBounds(MinikinRect* bounds, uint32_t glyph_id, const MinikinPaint &paint) const = 0; - // Override if font can provide access to raw data - virtual const void* GetFontData() const { + virtual hb_face_t* CreateHarfBuzzFace() const { return nullptr; } - // Override if font can provide access to raw data - virtual size_t GetFontSize() const { - return 0; - } - - // Override if font can provide access to raw data. - // Returns index within OpenType collection - virtual int GetFontIndex() const { - return 0; - } - virtual const std::vector& GetAxes() const = 0; virtual std::shared_ptr createFontWithVariation( diff --git a/engine/src/flutter/libs/minikin/HbFontCache.cpp b/engine/src/flutter/libs/minikin/HbFontCache.cpp index a7647c016c2..0de40113a0f 100644 --- a/engine/src/flutter/libs/minikin/HbFontCache.cpp +++ b/engine/src/flutter/libs/minikin/HbFontCache.cpp @@ -102,13 +102,7 @@ hb_font_t* getHbFontLocked(const MinikinFont* minikinFont) { return hb_font_reference(font); } - hb_face_t* face; - const void* buf = minikinFont->GetFontData(); - size_t size = minikinFont->GetFontSize(); - hb_blob_t* blob = hb_blob_create(reinterpret_cast(buf), size, - HB_MEMORY_MODE_READONLY, nullptr, nullptr); - face = hb_face_create(blob, minikinFont->GetFontIndex()); - hb_blob_destroy(blob); + hb_face_t* face = minikinFont->CreateHarfBuzzFace(); hb_font_t* parent_font = hb_font_create(face); hb_ot_font_set_funcs(parent_font); diff --git a/engine/src/flutter/src/BUILD.gn b/engine/src/flutter/src/BUILD.gn new file mode 100644 index 00000000000..e10013e470d --- /dev/null +++ b/engine/src/flutter/src/BUILD.gn @@ -0,0 +1,27 @@ +# Copyright 2017 Google Inc. +# +# 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. + +static_library("src") { + sources = [ + "font_collection.cc", + "font_collection.h", + "font_skia.cc", + "font_skia.h", + ] + + deps = [ + "//lib/txt/libs/minikin", + "//third_party/skia", + ] +} diff --git a/engine/src/flutter/src/font_collection.cc b/engine/src/flutter/src/font_collection.cc new file mode 100644 index 00000000000..d94df028fab --- /dev/null +++ b/engine/src/flutter/src/font_collection.cc @@ -0,0 +1,78 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 "lib/txt/src/font_collection.h" + +#include + +#include "lib/ftl/logging.h" +#include "lib/txt/src/font_skia.h" +#include "third_party/skia/include/ports/SkFontMgr.h" + +namespace txt { +namespace { + +bool IsItalic(SkFontStyle::Slant slant) { + return slant != SkFontStyle::Slant::kUpright_Slant; +} + +} // namespace + +FontCollection& FontCollection::GetDefaultFontCollection() { + static FontCollection* collection = nullptr; + static std::once_flag once; + std::call_once(once, []() { collection = new FontCollection(); }); + return *collection; +} + +FontCollection::FontCollection() = default; + +FontCollection::~FontCollection() = default; + +std::shared_ptr +FontCollection::GetAndroidFontCollectionForFamily(const std::string& family) { + // Get the Skia font manager. + auto skia_font_manager = SkFontMgr::RefDefault(); + FTL_DCHECK(skia_font_manager != nullptr); + + // Ask Skia to resolve a font style set for a font family name. + // FIXME(chinmaygarde): The name "Hevetica" is hardcoded because CoreText + // crashes when passed a null string. This seems to be a bug in Skia as + // SkFontMgr explicitly says passing in nullptr gives the default font. + auto font_style_set = skia_font_manager->matchFamily( + family.length() == 0 ? "Helvetica" : family.c_str()); + FTL_DCHECK(font_style_set != nullptr); + + std::vector fonts; + + // Add fonts to the Minikin font family. + for (int i = 0, style_count = font_style_set->count(); i < style_count; ++i) { + auto skia_typeface = + sk_ref_sp(font_style_set->createTypeface(i)); + auto typeface = std::make_shared(std::move(skia_typeface)); + + SkFontStyle skia_font_style; + font_style_set->getStyle(i, &skia_font_style, nullptr); + minikin::FontStyle style(skia_font_style.weight(), IsItalic(skia_font_style.slant())); + + fonts.push_back(minikin::Font(std::move(typeface), style)); + } + + auto minikin_family = std::make_shared(std::move(fonts)); + return std::make_shared(std::move(minikin_family)); +} + +} // namespace txt diff --git a/engine/src/flutter/src/font_collection.h b/engine/src/flutter/src/font_collection.h new file mode 100644 index 00000000000..d4df45b0e97 --- /dev/null +++ b/engine/src/flutter/src/font_collection.h @@ -0,0 +1,48 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 LIB_TXT_SRC_FONT_COLLECTION_H_ +#define LIB_TXT_SRC_FONT_COLLECTION_H_ + +#include +#include +#include + +#include "lib/ftl/macros.h" +#include "lib/txt/include/minikin/FontCollection.h" +#include "lib/txt/include/minikin/FontFamily.h" + +namespace txt { + +class FontCollection { + public: + static FontCollection& GetDefaultFontCollection(); + + FontCollection(); + + ~FontCollection(); + + std::shared_ptr GetAndroidFontCollectionForFamily( + const std::string& family); + + private: + // TODO(chinmaygarde): Caches go here. + FTL_DISALLOW_COPY_AND_ASSIGN(FontCollection); +}; + +} // namespace txt + +#endif // LIB_TXT_SRC_FONT_COLLECTION_H_ diff --git a/engine/src/flutter/src/font_skia.cc b/engine/src/flutter/src/font_skia.cc new file mode 100644 index 00000000000..a70c391858d --- /dev/null +++ b/engine/src/flutter/src/font_skia.cc @@ -0,0 +1,91 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 "lib/txt/src/font_skia.h" + +#include + +namespace txt { +namespace { + +hb_blob_t* GetTable(hb_face_t* face, hb_tag_t tag, void* context) { + SkTypeface* typeface = reinterpret_cast(context); + + const size_t table_size = typeface->getTableSize(tag); + if (table_size == 0) + return nullptr; + void* buffer = malloc(table_size); + if (buffer == nullptr) + return nullptr; + + size_t actual_size = typeface->getTableData(tag, 0, table_size, buffer); + if (table_size != actual_size) { + free(buffer); + return nullptr; + } + return hb_blob_create(reinterpret_cast(buffer), table_size, + HB_MEMORY_MODE_WRITABLE, buffer, free); +} + +} // namespace + +FontSkia::FontSkia(sk_sp typeface) + : MinikinFont(typeface->uniqueID()), typeface_(std::move(typeface)) {} + +FontSkia::~FontSkia() = default; + +static void FontSkia_SetSkiaPaint(sk_sp typeface, + SkPaint* skPaint, + const minikin::MinikinPaint& paint) { + skPaint->setTypeface(std::move(typeface)); + skPaint->setTextEncoding(SkPaint::kGlyphID_TextEncoding); + // TODO: set more paint parameters from Minikin + skPaint->setTextSize(paint.size); +} + +float FontSkia::GetHorizontalAdvance(uint32_t glyph_id, + const minikin::MinikinPaint& paint) const { + SkPaint skPaint; + uint16_t glyph16 = glyph_id; + SkScalar skWidth; + FontSkia_SetSkiaPaint(typeface_, &skPaint, paint); + skPaint.getTextWidths(&glyph16, sizeof(glyph16), &skWidth, NULL); + return skWidth; +} + +void FontSkia::GetBounds(minikin::MinikinRect* bounds, + uint32_t glyph_id, + const minikin::MinikinPaint& paint) const { + SkPaint skPaint; + uint16_t glyph16 = glyph_id; + SkRect skBounds; + FontSkia_SetSkiaPaint(typeface_, &skPaint, paint); + skPaint.getTextWidths(&glyph16, sizeof(glyph16), NULL, &skBounds); + bounds->mLeft = skBounds.fLeft; + bounds->mTop = skBounds.fTop; + bounds->mRight = skBounds.fRight; + bounds->mBottom = skBounds.fBottom; +} + +hb_face_t* FontSkia::CreateHarfBuzzFace() const { + return hb_face_create_for_tables(GetTable, typeface_.get(), 0); +} + +const sk_sp& FontSkia::GetSkTypeface() { + return typeface_; +} + +} // namespace txt diff --git a/engine/src/flutter/src/font_skia.h b/engine/src/flutter/src/font_skia.h new file mode 100644 index 00000000000..788af74ad3a --- /dev/null +++ b/engine/src/flutter/src/font_skia.h @@ -0,0 +1,50 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 +#include +#include +#include "lib/ftl/macros.h" + +namespace txt { + +class FontSkia : public minikin::MinikinFont { + public: + explicit FontSkia(sk_sp typeface); + + ~FontSkia(); + + float GetHorizontalAdvance(uint32_t glyph_id, + const minikin::MinikinPaint& paint) const override; + + void GetBounds(minikin::MinikinRect* bounds, + uint32_t glyph_id, + const minikin::MinikinPaint& paint) const override; + + hb_face_t* CreateHarfBuzzFace() const override; + + const std::vector& GetAxes() const override; + + const sk_sp& GetSkTypeface(); + + private: + sk_sp typeface_; + std::vector variations_; + + FTL_DISALLOW_COPY_AND_ASSIGN(FontSkia); +}; + +} // namespace txt From ef1a552f3c999b770403f5f49f31421c7c1c1a2d Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 10 May 2017 20:58:52 -0700 Subject: [PATCH 277/364] Remove libxml2 dependency --- engine/src/flutter/tests/util/BUILD.gn | 8 -------- 1 file changed, 8 deletions(-) diff --git a/engine/src/flutter/tests/util/BUILD.gn b/engine/src/flutter/tests/util/BUILD.gn index d8906e969dd..cbb03350155 100644 --- a/engine/src/flutter/tests/util/BUILD.gn +++ b/engine/src/flutter/tests/util/BUILD.gn @@ -20,10 +20,6 @@ source_set("util") { sources = [ "FileUtils.cpp", "FileUtils.h", - "FontTestUtils.cpp", - "FontTestUtils.h", - "MinikinFontForTest.cpp", - "MinikinFontForTest.h", "UnicodeUtils.cpp", "UnicodeUtils.h", ] @@ -33,8 +29,4 @@ source_set("util") { public_deps = [ "//lib/txt/libs/minikin", ] - - deps = [ - "//third_party/libxml2", - ] } From 966ef0ace4e00dc15c2a648edd98931f54556831 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 11 May 2017 09:12:22 -0700 Subject: [PATCH 278/364] Import more code from the prototype Change-Id: Ic5656c3ffcc3c3da8ed1fb4a44355b16c21c2f1e --- engine/src/flutter/.clang-format | 8 +++ engine/src/flutter/.gitattributes | 10 +++ engine/src/flutter/.gitignore | 17 +++++ engine/src/flutter/src/BUILD.gn | 13 +++- .../{font_collection.cc => font_provider.cc} | 28 ++++---- .../{font_collection.h => font_provider.h} | 12 ++-- engine/src/flutter/src/font_style.h | 29 ++++++++ engine/src/flutter/src/font_weight.h | 36 ++++++++++ engine/src/flutter/src/paragraph_builder.cc | 49 +++++++++++++ engine/src/flutter/src/paragraph_builder.h | 52 ++++++++++++++ engine/src/flutter/src/paragraph_style.h | 38 ++++++++++ engine/src/flutter/src/styled_runs.h | 69 +++++++++++++++++++ engine/src/flutter/src/text_align.h | 31 +++++++++ engine/src/flutter/src/text_style.h | 46 +++++++++++++ 14 files changed, 416 insertions(+), 22 deletions(-) create mode 100644 engine/src/flutter/.clang-format create mode 100644 engine/src/flutter/.gitattributes create mode 100644 engine/src/flutter/.gitignore rename engine/src/flutter/src/{font_collection.cc => font_provider.cc} (72%) rename engine/src/flutter/src/{font_collection.h => font_provider.h} (81%) create mode 100644 engine/src/flutter/src/font_style.h create mode 100644 engine/src/flutter/src/font_weight.h create mode 100644 engine/src/flutter/src/paragraph_builder.cc create mode 100644 engine/src/flutter/src/paragraph_builder.h create mode 100644 engine/src/flutter/src/paragraph_style.h create mode 100644 engine/src/flutter/src/styled_runs.h create mode 100644 engine/src/flutter/src/text_align.h create mode 100644 engine/src/flutter/src/text_style.h diff --git a/engine/src/flutter/.clang-format b/engine/src/flutter/.clang-format new file mode 100644 index 00000000000..6fdf1dc888c --- /dev/null +++ b/engine/src/flutter/.clang-format @@ -0,0 +1,8 @@ +# Defines the Chromium style for automatic reformatting. +# http://clang.llvm.org/docs/ClangFormatStyleOptions.html +BasedOnStyle: Chromium +# This defaults to 'Auto'. Explicitly set it for a while, so that +# 'vector >' in existing files gets formatted to +# 'vector>'. ('Auto' means that clang-format will only use +# 'int>>' if the file already contains at least one such instance.) +Standard: Cpp11 diff --git a/engine/src/flutter/.gitattributes b/engine/src/flutter/.gitattributes new file mode 100644 index 00000000000..da2e8a59e51 --- /dev/null +++ b/engine/src/flutter/.gitattributes @@ -0,0 +1,10 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Always perform LF normalization on these files +*.c text +*.cc text +*.cpp text +*.h text +*.gn text +*.md text diff --git a/engine/src/flutter/.gitignore b/engine/src/flutter/.gitignore new file mode 100644 index 00000000000..59ec4abf164 --- /dev/null +++ b/engine/src/flutter/.gitignore @@ -0,0 +1,17 @@ +*.pyc +*~ +.*.sw? +.DS_Store +.classpath +.cproject +.gdb_history +.gdbinit +.landmines +.project +.pydevproject +.checkstyle +.vscode +cscope.* +Session.vim +tags +Thumbs.db diff --git a/engine/src/flutter/src/BUILD.gn b/engine/src/flutter/src/BUILD.gn index e10013e470d..44b6cfa1f89 100644 --- a/engine/src/flutter/src/BUILD.gn +++ b/engine/src/flutter/src/BUILD.gn @@ -14,13 +14,22 @@ static_library("src") { sources = [ - "font_collection.cc", - "font_collection.h", + "font_provider.cc", + "font_provider.h", "font_skia.cc", "font_skia.h", + "font_style.h", + "font_weight.h", + "paragraph_builder.cc", + "paragraph_builder.h", + "paragraph_style.h", + "styled_runs.h", + "text_align.h", + "text_style.h", ] deps = [ + "//lib/ftl", "//lib/txt/libs/minikin", "//third_party/skia", ] diff --git a/engine/src/flutter/src/font_collection.cc b/engine/src/flutter/src/font_provider.cc similarity index 72% rename from engine/src/flutter/src/font_collection.cc rename to engine/src/flutter/src/font_provider.cc index d94df028fab..a8a3c8fe9cc 100644 --- a/engine/src/flutter/src/font_collection.cc +++ b/engine/src/flutter/src/font_provider.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "lib/txt/src/font_collection.h" +#include "lib/txt/src/font_provider.h" #include @@ -31,28 +31,28 @@ bool IsItalic(SkFontStyle::Slant slant) { } // namespace -FontCollection& FontCollection::GetDefaultFontCollection() { - static FontCollection* collection = nullptr; +FontProvider& FontProvider::GetDefault() { + static FontProvider* provider = nullptr; static std::once_flag once; - std::call_once(once, []() { collection = new FontCollection(); }); - return *collection; + std::call_once(once, []() { provider = new FontProvider(); }); + return *provider; } -FontCollection::FontCollection() = default; +FontProvider::FontProvider() = default; -FontCollection::~FontCollection() = default; +FontProvider::~FontProvider() = default; std::shared_ptr -FontCollection::GetAndroidFontCollectionForFamily(const std::string& family) { +FontProvider::GetFontCollectionForFamily(const std::string& family) { // Get the Skia font manager. - auto skia_font_manager = SkFontMgr::RefDefault(); - FTL_DCHECK(skia_font_manager != nullptr); + auto font_manager = SkFontMgr::RefDefault(); + FTL_DCHECK(font_manager != nullptr); // Ask Skia to resolve a font style set for a font family name. // FIXME(chinmaygarde): The name "Hevetica" is hardcoded because CoreText // crashes when passed a null string. This seems to be a bug in Skia as // SkFontMgr explicitly says passing in nullptr gives the default font. - auto font_style_set = skia_font_manager->matchFamily( + auto font_style_set = font_manager->matchFamily( family.length() == 0 ? "Helvetica" : family.c_str()); FTL_DCHECK(font_style_set != nullptr); @@ -64,9 +64,9 @@ FontCollection::GetAndroidFontCollectionForFamily(const std::string& family) { sk_ref_sp(font_style_set->createTypeface(i)); auto typeface = std::make_shared(std::move(skia_typeface)); - SkFontStyle skia_font_style; - font_style_set->getStyle(i, &skia_font_style, nullptr); - minikin::FontStyle style(skia_font_style.weight(), IsItalic(skia_font_style.slant())); + SkFontStyle font_style; + font_style_set->getStyle(i, &font_style, nullptr); + minikin::FontStyle style(font_style.weight(), IsItalic(font_style.slant())); fonts.push_back(minikin::Font(std::move(typeface), style)); } diff --git a/engine/src/flutter/src/font_collection.h b/engine/src/flutter/src/font_provider.h similarity index 81% rename from engine/src/flutter/src/font_collection.h rename to engine/src/flutter/src/font_provider.h index d4df45b0e97..264ee149fcc 100644 --- a/engine/src/flutter/src/font_collection.h +++ b/engine/src/flutter/src/font_provider.h @@ -27,20 +27,20 @@ namespace txt { -class FontCollection { +class FontProvider { public: - static FontCollection& GetDefaultFontCollection(); + static FontProvider& GetDefault(); - FontCollection(); + FontProvider(); - ~FontCollection(); + ~FontProvider(); - std::shared_ptr GetAndroidFontCollectionForFamily( + std::shared_ptr GetFontCollectionForFamily( const std::string& family); private: // TODO(chinmaygarde): Caches go here. - FTL_DISALLOW_COPY_AND_ASSIGN(FontCollection); + FTL_DISALLOW_COPY_AND_ASSIGN(FontProvider); }; } // namespace txt diff --git a/engine/src/flutter/src/font_style.h b/engine/src/flutter/src/font_style.h new file mode 100644 index 00000000000..ee903dbea01 --- /dev/null +++ b/engine/src/flutter/src/font_style.h @@ -0,0 +1,29 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 LIB_TXT_SRC_FONT_STYLE_H_ +#define LIB_TXT_SRC_FONT_STYLE_H_ + +namespace txt { + +enum class FontStyle { + normal, + italic, +}; + +} // namespace txt + +#endif // LIB_TXT_SRC_FONT_STYLE_H_ diff --git a/engine/src/flutter/src/font_weight.h b/engine/src/flutter/src/font_weight.h new file mode 100644 index 00000000000..cd1811e14d1 --- /dev/null +++ b/engine/src/flutter/src/font_weight.h @@ -0,0 +1,36 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 LIB_TXT_SRC_FONT_WEIGHT_H_ +#define LIB_TXT_SRC_FONT_WEIGHT_H_ + +namespace txt { + +enum class FontWeight { + w100, + w200, + w300, + w400, + w500, + w600, + w700, + w800, + w900, +}; + +} // namespace txt + +#endif // LIB_TXT_SRC_FONT_WEIGHT_H_ diff --git a/engine/src/flutter/src/paragraph_builder.cc b/engine/src/flutter/src/paragraph_builder.cc new file mode 100644 index 00000000000..3fd1738d9ed --- /dev/null +++ b/engine/src/flutter/src/paragraph_builder.cc @@ -0,0 +1,49 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 "lib/txt/src/paragraph_builder.h" + +namespace txt { + +ParagraphBuilder::ParagraphBuilder(ParagraphStyle style) {} + +ParagraphBuilder::~ParagraphBuilder() = default; + +void ParagraphBuilder::PushStyle(const TextStyle& style) { + const size_t text_index = text_.size(); + runs_.EndRunIfNeeded(text_index); + const size_t style_index = runs_.AddStyle(style); + runs_.StartRun(style_index, text_index); + style_stack_.push_back(style_index); +} + +void ParagraphBuilder::Pop() { + if (style_stack_.empty()) + return; + const size_t text_index = text_.size(); + runs_.EndRunIfNeeded(text_index); + style_stack_.pop_back(); + if (style_stack_.empty()) + return; + const size_t style_index = style_stack_.back(); + runs_.StartRun(style_index, text_index); +} + +void ParagraphBuilder::AddText(const uint16_t* text, size_t length) { + text_.insert(text_.end(), text, text + length); +} + +} // namespace txt diff --git a/engine/src/flutter/src/paragraph_builder.h b/engine/src/flutter/src/paragraph_builder.h new file mode 100644 index 00000000000..cb313b01f0b --- /dev/null +++ b/engine/src/flutter/src/paragraph_builder.h @@ -0,0 +1,52 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 LIB_TXT_SRC_PARAGRAPH_BUILDER_H_ +#define LIB_TXT_SRC_PARAGRAPH_BUILDER_H_ + +#include +#include + +#include "lib/ftl/macros.h" +#include "lib/txt/src/paragraph_style.h" +#include "lib/txt/src/styled_runs.h" +#include "lib/txt/src/text_style.h" + +namespace txt { + +class ParagraphBuilder { + public: + explicit ParagraphBuilder(ParagraphStyle style); + + ~ParagraphBuilder(); + + void PushStyle(const TextStyle& style); + + void Pop(); + + void AddText(const uint16_t* text, size_t length); + + private: + std::vector text_; + std::vector style_stack_; + StyledRuns runs_; + + FTL_DISALLOW_COPY_AND_ASSIGN(ParagraphBuilder); +}; + +} // namespace txt + +#endif // LIB_TXT_SRC_PARAGRAPH_BUILDER_H_ diff --git a/engine/src/flutter/src/paragraph_style.h b/engine/src/flutter/src/paragraph_style.h new file mode 100644 index 00000000000..eec58159da6 --- /dev/null +++ b/engine/src/flutter/src/paragraph_style.h @@ -0,0 +1,38 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 LIB_TXT_SRC_PARAGRAPH_STYLE_H_ +#define LIB_TXT_SRC_PARAGRAPH_STYLE_H_ + +#include + +#include "lib/txt/src/font_style.h" +#include "lib/txt/src/font_weight.h" +#include "lib/txt/src/text_align.h" + +namespace txt { + +class ParagraphStyle { + public: + TextAlign text_align = TextAlign::left; + int max_lines = 0; + double line_height = 1.0; + std::string ellipsis; +}; + +} // namespace txt + +#endif // LIB_TXT_SRC_PARAGRAPH_STYLE_H_ diff --git a/engine/src/flutter/src/styled_runs.h b/engine/src/flutter/src/styled_runs.h new file mode 100644 index 00000000000..781e1eb69bb --- /dev/null +++ b/engine/src/flutter/src/styled_runs.h @@ -0,0 +1,69 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 LIB_TXT_SRC_STYLED_RUNS_H_ +#define LIB_TXT_SRC_STYLED_RUNS_H_ + +#include + +#include "lib/txt/src/text_style.h" + +namespace txt { + +class StyledRuns { + public: + struct Run { + const TextStyle& style; + size_t start; + size_t end; + }; + + StyledRuns(); + + ~StyledRuns(); + + StyledRuns(const StyledRuns& other) = delete; + + StyledRuns(StyledRuns&& other); + + const StyledRuns& operator=(StyledRuns&& other); + + void swap(StyledRuns& other); + + size_t AddStyle(const TextStyle& style); + + void StartRun(size_t style_index, size_t start); + + void EndRunIfNeeded(size_t end); + + size_t size() const { return runs_.size(); } + + Run GetRun(size_t index) const; + + private: + struct IndexedRun { + size_t style_index = 0; + size_t start = 0; + size_t end = 0; + }; + + std::vector styles_; + std::vector runs_; +}; + +} // namespace txt + +#endif // LIB_TXT_SRC_STYLED_RUNS_H_ diff --git a/engine/src/flutter/src/text_align.h b/engine/src/flutter/src/text_align.h new file mode 100644 index 00000000000..91a291ff9ff --- /dev/null +++ b/engine/src/flutter/src/text_align.h @@ -0,0 +1,31 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 LIB_TXT_SRC_TEXT_ALIGN_H_ +#define LIB_TXT_SRC_TEXT_ALIGN_H_ + +namespace txt { + +enum class TextAlign { + left, + right, + center, + // justify, +}; + +} // namespace txt + +#endif // LIB_TXT_SRC_TEXT_ALIGN_H_ diff --git a/engine/src/flutter/src/text_style.h b/engine/src/flutter/src/text_style.h new file mode 100644 index 00000000000..f2482dd4065 --- /dev/null +++ b/engine/src/flutter/src/text_style.h @@ -0,0 +1,46 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 LIB_TXT_SRC_TEXT_STYLE_H_ +#define LIB_TXT_SRC_TEXT_STYLE_H_ + +#include + +#include "lib/txt/src/font_style.h" +#include "lib/txt/src/font_weight.h" +#include "third_party/skia/include/core/SkColor.h" + +namespace txt { + +class TextStyle { + public: + SkColor color = SK_ColorWHITE; + // TextDecoration decoration, + // SkColor decoration_color; + // TextDecorationStyle decoration_style + FontWeight font_weight = FontWeight::w400; + FontStyle font_style = FontStyle::normal; + // TextBaseline text_baseline; + std::string font_family; + double font_size = 14.0; + double letter_spacing = 0.0; + double word_spacing = 0.0; + double height = 1.0; +}; + +} // namespace txt + +#endif // LIB_TXT_SRC_TEXT_STYLE_H_ From cdbb8b0c9d84fb313226ef0b5ac7f9bd5aa9b299 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 11 May 2017 09:25:35 -0700 Subject: [PATCH 279/364] Add Paragraph class from prototype Change-Id: Id38e4261c4d6f8fa99f405d9b21bdd9e259a9384 --- .../src/flutter/include/minikin/LineBreaker.h | 2 + engine/src/flutter/src/BUILD.gn | 4 + engine/src/flutter/src/font_skia.cc | 2 +- engine/src/flutter/src/font_skia.h | 2 +- engine/src/flutter/src/paint_record.cc | 41 ++++ engine/src/flutter/src/paint_record.h | 53 +++++ engine/src/flutter/src/paragraph.cc | 210 ++++++++++++++++++ engine/src/flutter/src/paragraph.h | 60 +++++ engine/src/flutter/src/paragraph_builder.cc | 7 + engine/src/flutter/src/paragraph_builder.h | 3 + 10 files changed, 382 insertions(+), 2 deletions(-) create mode 100644 engine/src/flutter/src/paint_record.cc create mode 100644 engine/src/flutter/src/paint_record.h create mode 100644 engine/src/flutter/src/paragraph.cc create mode 100644 engine/src/flutter/src/paragraph.h diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index c91c0b3da7f..46936bbd57a 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -26,7 +26,9 @@ #include "unicode/locid.h" #include #include +#include "minikin/FontCollection.h" #include "minikin/Hyphenator.h" +#include "minikin/MinikinFont.h" #include "minikin/WordBreaker.h" namespace minikin { diff --git a/engine/src/flutter/src/BUILD.gn b/engine/src/flutter/src/BUILD.gn index 44b6cfa1f89..a790b4e4d6c 100644 --- a/engine/src/flutter/src/BUILD.gn +++ b/engine/src/flutter/src/BUILD.gn @@ -20,6 +20,10 @@ static_library("src") { "font_skia.h", "font_style.h", "font_weight.h", + "paint_record.cc", + "paint_record.h", + "paragraph.cc", + "paragraph.h", "paragraph_builder.cc", "paragraph_builder.h", "paragraph_style.h", diff --git a/engine/src/flutter/src/font_skia.cc b/engine/src/flutter/src/font_skia.cc index a70c391858d..295a749bc2f 100644 --- a/engine/src/flutter/src/font_skia.cc +++ b/engine/src/flutter/src/font_skia.cc @@ -84,7 +84,7 @@ hb_face_t* FontSkia::CreateHarfBuzzFace() const { return hb_face_create_for_tables(GetTable, typeface_.get(), 0); } -const sk_sp& FontSkia::GetSkTypeface() { +const sk_sp& FontSkia::GetSkTypeface() const { return typeface_; } diff --git a/engine/src/flutter/src/font_skia.h b/engine/src/flutter/src/font_skia.h index 788af74ad3a..96e808d9fb8 100644 --- a/engine/src/flutter/src/font_skia.h +++ b/engine/src/flutter/src/font_skia.h @@ -38,7 +38,7 @@ class FontSkia : public minikin::MinikinFont { const std::vector& GetAxes() const override; - const sk_sp& GetSkTypeface(); + const sk_sp& GetSkTypeface() const; private: sk_sp typeface_; diff --git a/engine/src/flutter/src/paint_record.cc b/engine/src/flutter/src/paint_record.cc new file mode 100644 index 00000000000..226b803d42f --- /dev/null +++ b/engine/src/flutter/src/paint_record.cc @@ -0,0 +1,41 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 "lib/txt/src/paint_record.h" + +namespace txt { + +PaintRecord::PaintRecord() = default; + +PaintRecord::~PaintRecord() = default; + +PaintRecord::PaintRecord(SkColor color, SkPoint offset, sk_sp text) + : color_(color), offset_(offset), text_(std::move(text)) {} + +PaintRecord::PaintRecord(PaintRecord&& other) { + color_ = other.color_; + offset_ = other.offset_; + text_ = std::move(other.text_); +} + +PaintRecord& PaintRecord::operator=(PaintRecord&& other) { + color_ = other.color_; + offset_ = other.offset_; + text_ = std::move(other.text_); + return *this; +} + +} // namespace txt diff --git a/engine/src/flutter/src/paint_record.h b/engine/src/flutter/src/paint_record.h new file mode 100644 index 00000000000..04d6f300d6b --- /dev/null +++ b/engine/src/flutter/src/paint_record.h @@ -0,0 +1,53 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 LIB_TXT_SRC_PAINT_RECORD_H_ +#define LIB_TXT_SRC_PAINT_RECORD_H_ + +#include "lib/ftl/macros.h" +#include "third_party/skia/include/core/SkTextBlob.h" + +namespace txt { + +class PaintRecord { + public: + PaintRecord(); + + ~PaintRecord(); + + PaintRecord(SkColor color, SkPoint offset, sk_sp text); + + PaintRecord(const PaintRecord& other) = delete; + + PaintRecord(PaintRecord&& other); + + PaintRecord& operator=(PaintRecord&& other); + + SkColor color() const { return color_; } + + SkPoint offset() const { return offset_; } + + SkTextBlob* text() const { return text_.get(); } + + private: + SkColor color_; + SkPoint offset_; + sk_sp text_; +}; + +} // namespace txt + +#endif // LIB_TXT_SRC_PAINT_RECORD_H_ diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc new file mode 100644 index 00000000000..e4a35e7ed4d --- /dev/null +++ b/engine/src/flutter/src/paragraph.cc @@ -0,0 +1,210 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 "lib/txt/src/paragraph.h" + +#include +#include +#include +#include + +#include +#include + +#include "lib/ftl/logging.h" + +#include "lib/txt/src/font_provider.h" +#include "lib/txt/src/font_skia.h" +#include "third_party/skia/include/core/SkCanvas.h" +#include "third_party/skia/include/core/SkPaint.h" +#include "third_party/skia/include/core/SkTextBlob.h" +#include "third_party/skia/include/core/SkTypeface.h" + +namespace txt { +namespace { + +const sk_sp& GetTypefaceForGlyph(const minikin::Layout& layout, + size_t index) { + const FontSkia* font = static_cast(layout.getFont(index)); + return font->GetSkTypeface(); +} + +size_t GetBlobLength(const minikin::Layout& layout, size_t blob_start) { + const size_t glyph_count = layout.nGlyphs(); + const sk_sp& typeface = GetTypefaceForGlyph(layout, blob_start); + for (size_t blob_end = blob_start + 1; blob_end < glyph_count; ++blob_end) { + if (GetTypefaceForGlyph(layout, blob_end).get() != typeface.get()) + return blob_end - blob_start; + } + return glyph_count - blob_start; +} + +int GetWeight(const TextStyle& style) { + switch (style.font_weight) { + case FontWeight::w100: + return 1; + case FontWeight::w200: + return 2; + case FontWeight::w300: + return 3; + case FontWeight::w400: + return 4; + case FontWeight::w500: + return 5; + case FontWeight::w600: + return 6; + case FontWeight::w700: + return 7; + case FontWeight::w800: + return 8; + case FontWeight::w900: + return 9; + } +} + +bool GetItalic(const TextStyle& style) { + switch (style.font_style) { + case FontStyle::normal: + return false; + case FontStyle::italic: + return true; + } +} + +void GetFontAndMinikinPaint(const TextStyle& style, + minikin::FontStyle* font, + minikin::MinikinPaint* paint) { + *font = minikin::FontStyle(GetWeight(style), GetItalic(style)); + paint->size = style.font_size; + paint->letterSpacing = style.letter_spacing; + // TODO(abarth): font_family, word_spacing. +} + +void GetPaint(const TextStyle& style, SkPaint* paint) { + paint->setTextSize(style.font_size); +} + +} // namespace + +Paragraph::Paragraph() = default; + +Paragraph::~Paragraph() = default; + +void Paragraph::SetText(std::vector text, StyledRuns runs) { + text_ = std::move(text); + runs_ = std::move(runs); + + breaker_.setLocale(icu::Locale(), nullptr); + breaker_.resize(text_.size()); + memcpy(breaker_.buffer(), text_.data(), text_.size() * sizeof(text_[0])); + breaker_.setText(); +} + +void Paragraph::AddRunsToLineBreaker() { + auto collection = FontProvider::GetDefault().GetFontCollectionForFamily(""); + minikin::FontStyle font; + minikin::MinikinPaint paint; + for (size_t i = 0; i < runs_.size(); ++i) { + auto run = runs_.GetRun(i); + GetFontAndMinikinPaint(run.style, &font, &paint); + breaker_.addStyleRun(&paint, collection, font, run.start, run.end, false); + } +} + +void Paragraph::Layout(double width) { + breaker_.setLineWidths(0.0f, 0, width); + AddRunsToLineBreaker(); + size_t breaks_count = breaker_.computeBreaks(); + const int* breaks = breaker_.getBreaks(); + + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); + + minikin::FontStyle font; + minikin::MinikinPaint minikin_paint; + + SkTextBlobBuilder builder; + auto collection = FontProvider::GetDefault().GetFontCollectionForFamily(""); + minikin::Layout layout; + SkScalar x = 0.0f; + SkScalar y = 0.0f; + size_t break_index = 0; + for (size_t run_index = 0; run_index < runs_.size(); ++run_index) { + auto run = runs_.GetRun(run_index); + GetFontAndMinikinPaint(run.style, &font, &minikin_paint); + GetPaint(run.style, &paint); + + size_t layout_start = run.start; + while (layout_start < run.end) { + const size_t next_break = (break_index > breaks_count - 1) + ? std::numeric_limits::max() + : breaks[break_index]; + const size_t layout_end = std::min(run.end, next_break); + + int bidiFlags = 0; + layout.doLayout(text_.data(), layout_start, layout_end - layout_start, + text_.size(), bidiFlags, font, minikin_paint, collection); + + const size_t glyph_count = layout.nGlyphs(); + size_t blob_start = 0; + while (blob_start < glyph_count) { + const size_t blob_length = GetBlobLength(layout, blob_start); + // TODO(abarth): Precompute when we can use allocRunPosH. + paint.setTypeface(GetTypefaceForGlyph(layout, blob_start)); + + auto buffer = builder.allocRunPos(paint, blob_length); + + for (size_t blob_index = 0; blob_index < blob_length; ++blob_index) { + const size_t glyph_index = blob_start + blob_index; + buffer.glyphs[blob_index] = layout.getGlyphId(glyph_index); + const size_t pos_index = 2 * blob_index; + buffer.pos[pos_index] = layout.getX(glyph_index); + buffer.pos[pos_index + 1] = layout.getY(glyph_index); + } + blob_start += blob_length; + } + + // TODO(abarth): We could keep the same SkTextBlobBuilder as long as the + // color stayed the same. + records_.push_back( + PaintRecord(run.style.color, SkPoint::Make(x, y), builder.make())); + + if (layout_end == next_break) { + x = 0.0f; + // TODO(abarth): Use the line height, which is something like the max + // font_size for runs in this line times the paragraph's line height. + y += run.style.font_size; + break_index += 1; + } else { + x += layout.getAdvance(); + } + + layout_start = layout_end; + } + } +} + +void Paragraph::Paint(SkCanvas* canvas, double x, double y) { + SkPaint paint; + for (const auto& record : records_) { + paint.setColor(record.color()); + const SkPoint& offset = record.offset(); + canvas->drawTextBlob(record.text(), x + offset.x(), y + offset.y(), paint); + } +} + +} // namespace txt diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h new file mode 100644 index 00000000000..3b4bcb8757a --- /dev/null +++ b/engine/src/flutter/src/paragraph.h @@ -0,0 +1,60 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 LIB_TXT_SRC_PARAGRAPH_H_ +#define LIB_TXT_SRC_PARAGRAPH_H_ + +#include + +#include + +#include "lib/ftl/macros.h" +#include "lib/txt/src/paint_record.h" +#include "lib/txt/src/styled_runs.h" +#include "third_party/skia/include/core/SkTextBlob.h" + +class SkCanvas; + +namespace txt { + +class Paragraph { + public: + Paragraph(); + + ~Paragraph(); + + void Layout(double width); + + void Paint(SkCanvas* canvas, double x, double y); + + private: + friend class ParagraphBuilder; + + std::vector text_; + StyledRuns runs_; + minikin::LineBreaker breaker_; + std::vector records_; + + void SetText(std::vector text, StyledRuns runs); + + void AddRunsToLineBreaker(); + + FTL_DISALLOW_COPY_AND_ASSIGN(Paragraph); +}; + +} // namespace txt + +#endif // LIB_TXT_SRC_PARAGRAPH_H_ diff --git a/engine/src/flutter/src/paragraph_builder.cc b/engine/src/flutter/src/paragraph_builder.cc index 3fd1738d9ed..342279cd32c 100644 --- a/engine/src/flutter/src/paragraph_builder.cc +++ b/engine/src/flutter/src/paragraph_builder.cc @@ -46,4 +46,11 @@ void ParagraphBuilder::AddText(const uint16_t* text, size_t length) { text_.insert(text_.end(), text, text + length); } +std::unique_ptr ParagraphBuilder::Build() { + runs_.EndRunIfNeeded(text_.size()); + std::unique_ptr paragraph = std::make_unique(); + paragraph->SetText(std::move(text_), std::move(runs_)); + return paragraph; +} + } // namespace txt diff --git a/engine/src/flutter/src/paragraph_builder.h b/engine/src/flutter/src/paragraph_builder.h index cb313b01f0b..243e6394c8d 100644 --- a/engine/src/flutter/src/paragraph_builder.h +++ b/engine/src/flutter/src/paragraph_builder.h @@ -21,6 +21,7 @@ #include #include "lib/ftl/macros.h" +#include "lib/txt/src/paragraph.h" #include "lib/txt/src/paragraph_style.h" #include "lib/txt/src/styled_runs.h" #include "lib/txt/src/text_style.h" @@ -39,6 +40,8 @@ class ParagraphBuilder { void AddText(const uint16_t* text, size_t length); + std::unique_ptr Build(); + private: std::vector text_; std::vector style_stack_; From 2697ab61cb778b26d1e7e04fb2b23479b65d5f52 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 11 May 2017 09:38:03 -0700 Subject: [PATCH 280/364] Add example program from prototype Change-Id: Ia6f6c442db57abe484a3efe33ecbc7553743bbb3 --- engine/src/flutter/BUILD.gn | 17 +++++-- engine/src/flutter/examples/BUILD.gn | 27 ++++++++++ engine/src/flutter/examples/main.cc | 73 +++++++++++++++++++++++++++ engine/src/flutter/src/BUILD.gn | 3 +- engine/src/flutter/src/font_skia.cc | 4 ++ engine/src/flutter/src/styled_runs.cc | 68 +++++++++++++++++++++++++ 6 files changed, 188 insertions(+), 4 deletions(-) create mode 100644 engine/src/flutter/examples/BUILD.gn create mode 100644 engine/src/flutter/examples/main.cc create mode 100644 engine/src/flutter/src/styled_runs.cc diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index 4e19aa46f04..36804272fdf 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -1,6 +1,16 @@ -# Copyright 2017 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. +# Copyright 2017 Google Inc. +# +# 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. group("txt") { testonly = true @@ -9,5 +19,6 @@ group("txt") { "libs/minikin", "src", "tests/unittest($host_toolchain)", + "examples:txt_example($host_toolchain)", ] } diff --git a/engine/src/flutter/examples/BUILD.gn b/engine/src/flutter/examples/BUILD.gn new file mode 100644 index 00000000000..bd19515179a --- /dev/null +++ b/engine/src/flutter/examples/BUILD.gn @@ -0,0 +1,27 @@ +# Copyright 2017 Google Inc. +# +# 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. + +executable("txt_example") { + sources = [ + "main.cc", + ] + + deps = [ + "//dart/runtime:libdart_jit", + "//flutter/fml", + "//lib/txt/src", + "//third_party/icu:icuuc", + "//third_party/skia", + ] +} diff --git a/engine/src/flutter/examples/main.cc b/engine/src/flutter/examples/main.cc new file mode 100644 index 00000000000..4d1b5b88a52 --- /dev/null +++ b/engine/src/flutter/examples/main.cc @@ -0,0 +1,73 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 + +#include +#include +#include + +#include "flutter/fml/icu_util.h" +#include "lib/txt/src/paragraph_builder.h" + +namespace txt { + +int runTest() { + const char* utf8_text = + "fine world that we live in is called Earth. It's pretty nice, as far as " + "I can tell. Rock, rock on. " + "\xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa5" + "\x87"; + icu::UnicodeString text = icu::UnicodeString::fromUTF8(utf8_text); + + ParagraphStyle paragraph_style; + ParagraphBuilder builder(paragraph_style); + TextStyle style; + style.color = SK_ColorBLUE; + style.font_size = 32.0; + builder.PushStyle(style); + builder.AddText(text.getBuffer(), text.length()); + style.color = SK_ColorYELLOW; + builder.PushStyle(style); + builder.AddText(text.getBuffer(), text.length()); + builder.Pop(); + builder.AddText(text.getBuffer(), text.length()); + builder.Pop(); + auto paragraph = builder.Build(); + + int width = 800; + int height = 600; + paragraph->Layout(width); + + SkAutoGraphics ag; + SkBitmap bitmap; + bitmap.allocN32Pixels(width, height); + SkCanvas canvas(bitmap); + paragraph->Paint(&canvas, 10.0, 200.0); + + SkFILEWStream file("foo.png"); + + return SkEncodeImage(&file, bitmap, SkEncodedImageFormat::kPNG, 100) + ? EXIT_SUCCESS + : EXIT_FAILURE; +} + +} // namespace txt + +int main(int argc, const char** argv) { + fml::icu::InitializeICU(); + return txt::runTest(); +} diff --git a/engine/src/flutter/src/BUILD.gn b/engine/src/flutter/src/BUILD.gn index a790b4e4d6c..2d603bb38a9 100644 --- a/engine/src/flutter/src/BUILD.gn +++ b/engine/src/flutter/src/BUILD.gn @@ -27,12 +27,13 @@ static_library("src") { "paragraph_builder.cc", "paragraph_builder.h", "paragraph_style.h", + "styled_runs.cc", "styled_runs.h", "text_align.h", "text_style.h", ] - deps = [ + public_deps = [ "//lib/ftl", "//lib/txt/libs/minikin", "//third_party/skia", diff --git a/engine/src/flutter/src/font_skia.cc b/engine/src/flutter/src/font_skia.cc index 295a749bc2f..c6b3bc8d8f2 100644 --- a/engine/src/flutter/src/font_skia.cc +++ b/engine/src/flutter/src/font_skia.cc @@ -84,6 +84,10 @@ hb_face_t* FontSkia::CreateHarfBuzzFace() const { return hb_face_create_for_tables(GetTable, typeface_.get(), 0); } +const std::vector& FontSkia::GetAxes() const { + return variations_; +} + const sk_sp& FontSkia::GetSkTypeface() const { return typeface_; } diff --git a/engine/src/flutter/src/styled_runs.cc b/engine/src/flutter/src/styled_runs.cc new file mode 100644 index 00000000000..3f5f79da62b --- /dev/null +++ b/engine/src/flutter/src/styled_runs.cc @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2017 Google, Inc. + * + * 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 "lib/txt/src/styled_runs.h" + +namespace txt { + +StyledRuns::StyledRuns() = default; + +StyledRuns::~StyledRuns() = default; + +StyledRuns::StyledRuns(StyledRuns&& other) { + styles_.swap(other.styles_); + runs_.swap(other.runs_); +} + +const StyledRuns& StyledRuns::operator=(StyledRuns&& other) { + styles_.swap(other.styles_); + runs_.swap(other.runs_); + return *this; +} + +void StyledRuns::swap(StyledRuns& other) { + styles_.swap(other.styles_); + runs_.swap(other.runs_); +} + +size_t StyledRuns::AddStyle(const TextStyle& style) { + const size_t style_index = styles_.size(); + styles_.push_back(style); + return style_index; +} + +void StyledRuns::StartRun(size_t style_index, size_t start) { + runs_.push_back(IndexedRun{style_index, start, start}); +} + +void StyledRuns::EndRunIfNeeded(size_t end) { + if (runs_.empty()) + return; + IndexedRun& run = runs_.back(); + if (run.start == end) { + // The run is empty. We can skip it. + runs_.pop_back(); + } else { + run.end = end; + } +} + +StyledRuns::Run StyledRuns::GetRun(size_t index) const { + const IndexedRun& run = runs_[index]; + return Run{styles_[run.style_index], run.start, run.end}; +} + +} // namespace txt From 79f20a88865c362f2caa3f4c8325eebc1f82ff47 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Fri, 2 Jun 2017 14:43:10 -0700 Subject: [PATCH 281/364] Update libTXT sources and tests from initial prototype. This separates libTXT tests and Minikin tests and accounts for building with an older version of ICU. Once ICU has been updated, the workarounds for emoji handling will be removed. Change-Id: Ic184e653a2561629b01f98aeb4f6fb88aebbfa88 --- engine/src/flutter/BUILD.gn | 6 +- engine/src/flutter/examples/BUILD.gn | 1 + engine/src/flutter/examples/main.cc | 12 +-- .../src/flutter/include/minikin/Hyphenator.h | 4 + .../src/flutter/include/minikin/LineBreaker.h | 4 + engine/src/flutter/libs/minikin/BUILD.gn | 2 + engine/src/flutter/libs/minikin/Emoji.cpp | 12 +++ engine/src/flutter/libs/minikin/Layout.cpp | 5 ++ engine/src/flutter/src/BUILD.gn | 13 +-- engine/src/flutter/src/font_collection.cc | 87 +++++++++++++++++++ .../{font_provider.h => font_collection.h} | 16 ++-- engine/src/flutter/src/font_provider.cc | 78 ----------------- engine/src/flutter/src/paragraph.cc | 12 +-- engine/src/flutter/src/paragraph.h | 6 +- engine/src/flutter/src/paragraph_builder.cc | 4 +- engine/src/flutter/src/paragraph_builder.h | 2 +- .../src/flutter/src/paragraph_constraints.cc | 23 +++++ .../src/flutter/src/paragraph_constraints.h | 38 ++++++++ engine/src/flutter/src/paragraph_style.cc | 17 ++++ engine/src/flutter/src/text_style.cc | 17 ++++ engine/src/flutter/tests/txt/BUILD.gn | 40 +++++++++ .../tests/txt/font_collection_unittests.cc | 25 ++++++ .../flutter/tests/txt/paragraph_unittests.cc | 47 ++++++++++ engine/src/flutter/tests/txt/render_test.cc | 67 ++++++++++++++ engine/src/flutter/tests/txt/render_test.h | 52 +++++++++++ .../tests/txt/txt_run_all_unittests.cc | 26 ++++++ engine/src/flutter/tests/unittest/BUILD.gn | 15 ++-- 27 files changed, 514 insertions(+), 117 deletions(-) create mode 100644 engine/src/flutter/src/font_collection.cc rename engine/src/flutter/src/{font_provider.h => font_collection.h} (75%) delete mode 100644 engine/src/flutter/src/font_provider.cc create mode 100644 engine/src/flutter/src/paragraph_constraints.cc create mode 100644 engine/src/flutter/src/paragraph_constraints.h create mode 100644 engine/src/flutter/src/paragraph_style.cc create mode 100644 engine/src/flutter/src/text_style.cc create mode 100644 engine/src/flutter/tests/txt/BUILD.gn create mode 100644 engine/src/flutter/tests/txt/font_collection_unittests.cc create mode 100644 engine/src/flutter/tests/txt/paragraph_unittests.cc create mode 100644 engine/src/flutter/tests/txt/render_test.cc create mode 100644 engine/src/flutter/tests/txt/render_test.h create mode 100644 engine/src/flutter/tests/txt/txt_run_all_unittests.cc diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index 36804272fdf..34c9c145fa9 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -16,9 +16,9 @@ group("txt") { testonly = true deps = [ - "libs/minikin", - "src", - "tests/unittest($host_toolchain)", "examples:txt_example($host_toolchain)", + "src", + "tests/txt($host_toolchain)", # txt_unittests + "tests/unittest($host_toolchain)", # minikin_unittest ] } diff --git a/engine/src/flutter/examples/BUILD.gn b/engine/src/flutter/examples/BUILD.gn index bd19515179a..20780a3d655 100644 --- a/engine/src/flutter/examples/BUILD.gn +++ b/engine/src/flutter/examples/BUILD.gn @@ -20,6 +20,7 @@ executable("txt_example") { deps = [ "//dart/runtime:libdart_jit", "//flutter/fml", + "//lib/txt/libs/minikin", "//lib/txt/src", "//third_party/icu:icuuc", "//third_party/skia", diff --git a/engine/src/flutter/examples/main.cc b/engine/src/flutter/examples/main.cc index 4d1b5b88a52..3137207c38a 100644 --- a/engine/src/flutter/examples/main.cc +++ b/engine/src/flutter/examples/main.cc @@ -31,7 +31,9 @@ int runTest() { "I can tell. Rock, rock on. " "\xe0\xa4\xa8\xe0\xa4\xae\xe0\xa4\xb8\xe0\xa5\x8d\xe0\xa4\xa4\xe0\xa5" "\x87"; - icu::UnicodeString text = icu::UnicodeString::fromUTF8(utf8_text); + icu::UnicodeString icu_text = icu::UnicodeString::fromUTF8(utf8_text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); ParagraphStyle paragraph_style; ParagraphBuilder builder(paragraph_style); @@ -39,18 +41,18 @@ int runTest() { style.color = SK_ColorBLUE; style.font_size = 32.0; builder.PushStyle(style); - builder.AddText(text.getBuffer(), text.length()); + builder.AddText(u16_text); style.color = SK_ColorYELLOW; builder.PushStyle(style); - builder.AddText(text.getBuffer(), text.length()); + builder.AddText(u16_text); builder.Pop(); - builder.AddText(text.getBuffer(), text.length()); + builder.AddText(u16_text); builder.Pop(); auto paragraph = builder.Build(); int width = 800; int height = 600; - paragraph->Layout(width); + paragraph->Layout(ParagraphConstraints(width)); SkAutoGraphics ag; SkBitmap bitmap; diff --git a/engine/src/flutter/include/minikin/Hyphenator.h b/engine/src/flutter/include/minikin/Hyphenator.h index 2b8ccb71a7d..c2d9d3b63a0 100644 --- a/engine/src/flutter/include/minikin/Hyphenator.h +++ b/engine/src/flutter/include/minikin/Hyphenator.h @@ -18,6 +18,10 @@ * An implementation of Liang's hyphenation algorithm. */ +#ifndef U_USING_ICU_NAMESPACE +#define U_USING_ICU_NAMESPACE 0 +#endif // U_USING_ICU_NAMESPACE + #include "unicode/locid.h" #include #include diff --git a/engine/src/flutter/include/minikin/LineBreaker.h b/engine/src/flutter/include/minikin/LineBreaker.h index 46936bbd57a..c2f546db762 100644 --- a/engine/src/flutter/include/minikin/LineBreaker.h +++ b/engine/src/flutter/include/minikin/LineBreaker.h @@ -22,6 +22,10 @@ #ifndef MINIKIN_LINE_BREAKER_H #define MINIKIN_LINE_BREAKER_H +#ifndef U_USING_ICU_NAMESPACE +#define U_USING_ICU_NAMESPACE 0 +#endif // U_USING_ICU_NAMESPACE + #include "unicode/brkiter.h" #include "unicode/locid.h" #include diff --git a/engine/src/flutter/libs/minikin/BUILD.gn b/engine/src/flutter/libs/minikin/BUILD.gn index 5ce005f45a0..f723d0a8e1b 100644 --- a/engine/src/flutter/libs/minikin/BUILD.gn +++ b/engine/src/flutter/libs/minikin/BUILD.gn @@ -17,6 +17,8 @@ config("minikin_config") { } static_library("minikin") { + defines = [ "WIP_NEEDS_ICU_UPDATE" ] + sources = [ "CmapCoverage.cpp", "Emoji.cpp", diff --git a/engine/src/flutter/libs/minikin/Emoji.cpp b/engine/src/flutter/libs/minikin/Emoji.cpp index fbe68ca8432..df43c75b36f 100644 --- a/engine/src/flutter/libs/minikin/Emoji.cpp +++ b/engine/src/flutter/libs/minikin/Emoji.cpp @@ -37,16 +37,27 @@ bool isNewEmoji(uint32_t c) { } bool isEmoji(uint32_t c) { +#if WIP_NEEDS_ICU_UPDATE + return false; +#else // WIP_NEEDS_ICU_UPDATE return isNewEmoji(c) || u_hasBinaryProperty(c, UCHAR_EMOJI); +#endif // WIP_NEEDS_ICU_UPDATE } bool isEmojiModifier(uint32_t c) { +#if WIP_NEEDS_ICU_UPDATE + return false; +#else // WIP_NEEDS_ICU_UPDATE // Emoji modifier are not expected to change, so there's a small change we need to customize // this. return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER); +#endif // WIP_NEEDS_ICU_UPDATE } bool isEmojiBase(uint32_t c) { +#if WIP_NEEDS_ICU_UPDATE + return false; +#else // WIP_NEEDS_ICU_UPDATE // These two characters were removed from Emoji_Modifier_Base in Emoji 4.0, but we need to keep // them as emoji modifier bases since there are fonts and user-generated text out there that // treats these as potential emoji bases. @@ -62,6 +73,7 @@ bool isEmojiBase(uint32_t c) { return true; } return u_hasBinaryProperty(c, UCHAR_EMOJI_MODIFIER_BASE); +#endif // WIP_NEEDS_ICU_UPDATE } UCharDirection emojiBidiOverride(const void* /* context */, UChar32 c) { diff --git a/engine/src/flutter/libs/minikin/Layout.cpp b/engine/src/flutter/libs/minikin/Layout.cpp index e6c5bc912db..697fbc2ba2f 100644 --- a/engine/src/flutter/libs/minikin/Layout.cpp +++ b/engine/src/flutter/libs/minikin/Layout.cpp @@ -711,6 +711,10 @@ static void addFeatures(const string &str, vector* features) { static const hb_codepoint_t CHAR_HYPHEN = 0x2010; /* HYPHEN */ static inline hb_codepoint_t determineHyphenChar(hb_codepoint_t preferredHyphen, hb_font_t* font) { +#if WIP_NEEDS_ICU_UPDATE + (void)CHAR_HYPHEN; + return 0x002D; // HYPHEN-MINUS +#else // WIP_NEEDS_ICU_UPDATE hb_codepoint_t glyph; if (preferredHyphen == 0x058A /* ARMENIAN_HYPHEN */ || preferredHyphen == 0x05BE /* HEBREW PUNCTUATION MAQAF */ @@ -732,6 +736,7 @@ static inline hb_codepoint_t determineHyphenChar(hb_codepoint_t preferredHyphen, } } return preferredHyphen; +#endif // WIP_NEEDS_ICU_UPDATE } static inline void addHyphenToHbBuffer(hb_buffer_t* buffer, hb_font_t* font, uint32_t hyphen, diff --git a/engine/src/flutter/src/BUILD.gn b/engine/src/flutter/src/BUILD.gn index 2d603bb38a9..e8520ec1132 100644 --- a/engine/src/flutter/src/BUILD.gn +++ b/engine/src/flutter/src/BUILD.gn @@ -12,10 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -static_library("src") { +source_set("src") { sources = [ - "font_provider.cc", - "font_provider.h", + "font_collection.cc", + "font_collection.h", "font_skia.cc", "font_skia.h", "font_style.h", @@ -26,15 +26,18 @@ static_library("src") { "paragraph.h", "paragraph_builder.cc", "paragraph_builder.h", + "paragraph_constraints.cc", + "paragraph_constraints.h", + "paragraph_style.cc", "paragraph_style.h", "styled_runs.cc", "styled_runs.h", "text_align.h", + "text_style.cc", "text_style.h", ] - public_deps = [ - "//lib/ftl", + deps = [ "//lib/txt/libs/minikin", "//third_party/skia", ] diff --git a/engine/src/flutter/src/font_collection.cc b/engine/src/flutter/src/font_collection.cc new file mode 100644 index 00000000000..dc0207b4e53 --- /dev/null +++ b/engine/src/flutter/src/font_collection.cc @@ -0,0 +1,87 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 "lib/txt/src/font_collection.h" + +#include + +#include "lib/ftl/logging.h" +#include "lib/txt/src/font_skia.h" +#include "third_party/skia/include/ports/SkFontMgr.h" + +namespace txt { + +FontCollection& FontCollection::GetDefaultFontCollection() { + static FontCollection* collection = nullptr; + static std::once_flag once; + std::call_once(once, []() { collection = new FontCollection(); }); + return *collection; +} + +FontCollection::FontCollection() = default; + +FontCollection::~FontCollection() = default; + +std::shared_ptr +FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) { + // Get the Skia font manager. + auto skia_font_manager = SkFontMgr::RefDefault(); + FTL_DCHECK(skia_font_manager != nullptr); + + // Ask Skia to resolve a font style set for a font family name. + // FIXME(chinmaygarde): The name "Hevetica" is hardcoded because CoreText + // crashes when passed a null string. This seems to be a bug in Skia as + // SkFontMgr explicitly says passing in nullptr gives the default font. + auto font_style_set = skia_font_manager->matchFamily( + family.length() == 0 ? "Helvetica" : family.c_str()); + FTL_DCHECK(font_style_set != nullptr); + + std::vector minikin_fonts; + + // Add fonts to the Minikin font family. + for (int i = 0, style_count = font_style_set->count(); i < style_count; ++i) { + // Create the skia typeface + auto skia_typeface = + sk_ref_sp(font_style_set->createTypeface(i)); + + if (skia_typeface == nullptr) { + continue; + } + + // Create the minikin font from the skia typeface. + minikin::Font minikin_font( + std::make_shared(skia_typeface), + minikin::FontStyle{skia_typeface->fontStyle().weight(), + skia_typeface->isItalic()}); + + minikin_fonts.emplace_back(std::move(minikin_font)); + } + + // Create a Minikin font family. + auto minikin_family = + std::make_shared(std::move(minikin_fonts)); + + // Create a vector of font families for the Minkin font collection. For now, + // we only have one family in our collection. + std::vector> minikin_families = { + minikin_family, + }; + + // Return the font collection. + return std::make_shared(minikin_families); +} + +} // namespace txt diff --git a/engine/src/flutter/src/font_provider.h b/engine/src/flutter/src/font_collection.h similarity index 75% rename from engine/src/flutter/src/font_provider.h rename to engine/src/flutter/src/font_collection.h index 264ee149fcc..efca9e35c29 100644 --- a/engine/src/flutter/src/font_provider.h +++ b/engine/src/flutter/src/font_collection.h @@ -22,25 +22,25 @@ #include #include "lib/ftl/macros.h" -#include "lib/txt/include/minikin/FontCollection.h" -#include "lib/txt/include/minikin/FontFamily.h" +#include "minikin/FontCollection.h" +#include "minikin/FontFamily.h" namespace txt { -class FontProvider { +class FontCollection { public: - static FontProvider& GetDefault(); + static FontCollection& GetDefaultFontCollection(); - FontProvider(); + FontCollection(); - ~FontProvider(); + ~FontCollection(); - std::shared_ptr GetFontCollectionForFamily( + std::shared_ptr GetMinikinFontCollectionForFamily( const std::string& family); private: // TODO(chinmaygarde): Caches go here. - FTL_DISALLOW_COPY_AND_ASSIGN(FontProvider); + FTL_DISALLOW_COPY_AND_ASSIGN(FontCollection); }; } // namespace txt diff --git a/engine/src/flutter/src/font_provider.cc b/engine/src/flutter/src/font_provider.cc deleted file mode 100644 index a8a3c8fe9cc..00000000000 --- a/engine/src/flutter/src/font_provider.cc +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2017 Google Inc. - * - * 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 "lib/txt/src/font_provider.h" - -#include - -#include "lib/ftl/logging.h" -#include "lib/txt/src/font_skia.h" -#include "third_party/skia/include/ports/SkFontMgr.h" - -namespace txt { -namespace { - -bool IsItalic(SkFontStyle::Slant slant) { - return slant != SkFontStyle::Slant::kUpright_Slant; -} - -} // namespace - -FontProvider& FontProvider::GetDefault() { - static FontProvider* provider = nullptr; - static std::once_flag once; - std::call_once(once, []() { provider = new FontProvider(); }); - return *provider; -} - -FontProvider::FontProvider() = default; - -FontProvider::~FontProvider() = default; - -std::shared_ptr -FontProvider::GetFontCollectionForFamily(const std::string& family) { - // Get the Skia font manager. - auto font_manager = SkFontMgr::RefDefault(); - FTL_DCHECK(font_manager != nullptr); - - // Ask Skia to resolve a font style set for a font family name. - // FIXME(chinmaygarde): The name "Hevetica" is hardcoded because CoreText - // crashes when passed a null string. This seems to be a bug in Skia as - // SkFontMgr explicitly says passing in nullptr gives the default font. - auto font_style_set = font_manager->matchFamily( - family.length() == 0 ? "Helvetica" : family.c_str()); - FTL_DCHECK(font_style_set != nullptr); - - std::vector fonts; - - // Add fonts to the Minikin font family. - for (int i = 0, style_count = font_style_set->count(); i < style_count; ++i) { - auto skia_typeface = - sk_ref_sp(font_style_set->createTypeface(i)); - auto typeface = std::make_shared(std::move(skia_typeface)); - - SkFontStyle font_style; - font_style_set->getStyle(i, &font_style, nullptr); - minikin::FontStyle style(font_style.weight(), IsItalic(font_style.slant())); - - fonts.push_back(minikin::Font(std::move(typeface), style)); - } - - auto minikin_family = std::make_shared(std::move(fonts)); - return std::make_shared(std::move(minikin_family)); -} - -} // namespace txt diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index e4a35e7ed4d..4fe7d785e7d 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -26,7 +26,7 @@ #include "lib/ftl/logging.h" -#include "lib/txt/src/font_provider.h" +#include "lib/txt/src/font_collection.h" #include "lib/txt/src/font_skia.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkPaint.h" @@ -114,7 +114,8 @@ void Paragraph::SetText(std::vector text, StyledRuns runs) { } void Paragraph::AddRunsToLineBreaker() { - auto collection = FontProvider::GetDefault().GetFontCollectionForFamily(""); + auto collection = FontCollection::GetDefaultFontCollection() + .GetMinikinFontCollectionForFamily(""); minikin::FontStyle font; minikin::MinikinPaint paint; for (size_t i = 0; i < runs_.size(); ++i) { @@ -124,8 +125,8 @@ void Paragraph::AddRunsToLineBreaker() { } } -void Paragraph::Layout(double width) { - breaker_.setLineWidths(0.0f, 0, width); +void Paragraph::Layout(const ParagraphConstraints& constraints) { + breaker_.setLineWidths(0.0f, 0, constraints.width()); AddRunsToLineBreaker(); size_t breaks_count = breaker_.computeBreaks(); const int* breaks = breaker_.getBreaks(); @@ -138,7 +139,8 @@ void Paragraph::Layout(double width) { minikin::MinikinPaint minikin_paint; SkTextBlobBuilder builder; - auto collection = FontProvider::GetDefault().GetFontCollectionForFamily(""); + auto collection = FontCollection::GetDefaultFontCollection() + .GetMinikinFontCollectionForFamily(""); minikin::Layout layout; SkScalar x = 0.0f; SkScalar y = 0.0f; diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 3b4bcb8757a..4fd5d5aff2a 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -19,11 +19,11 @@ #include -#include - #include "lib/ftl/macros.h" #include "lib/txt/src/paint_record.h" +#include "lib/txt/src/paragraph_constraints.h" #include "lib/txt/src/styled_runs.h" +#include "minikin/LineBreaker.h" #include "third_party/skia/include/core/SkTextBlob.h" class SkCanvas; @@ -36,7 +36,7 @@ class Paragraph { ~Paragraph(); - void Layout(double width); + void Layout(const ParagraphConstraints& constraints); void Paint(SkCanvas* canvas, double x, double y); diff --git a/engine/src/flutter/src/paragraph_builder.cc b/engine/src/flutter/src/paragraph_builder.cc index 342279cd32c..a6db3492a8e 100644 --- a/engine/src/flutter/src/paragraph_builder.cc +++ b/engine/src/flutter/src/paragraph_builder.cc @@ -42,8 +42,8 @@ void ParagraphBuilder::Pop() { runs_.StartRun(style_index, text_index); } -void ParagraphBuilder::AddText(const uint16_t* text, size_t length) { - text_.insert(text_.end(), text, text + length); +void ParagraphBuilder::AddText(const std::u16string& text) { + text_.insert(text_.end(), text.begin(), text.end()); } std::unique_ptr ParagraphBuilder::Build() { diff --git a/engine/src/flutter/src/paragraph_builder.h b/engine/src/flutter/src/paragraph_builder.h index 243e6394c8d..8c6941af9bc 100644 --- a/engine/src/flutter/src/paragraph_builder.h +++ b/engine/src/flutter/src/paragraph_builder.h @@ -38,7 +38,7 @@ class ParagraphBuilder { void Pop(); - void AddText(const uint16_t* text, size_t length); + void AddText(const std::u16string& text); std::unique_ptr Build(); diff --git a/engine/src/flutter/src/paragraph_constraints.cc b/engine/src/flutter/src/paragraph_constraints.cc new file mode 100644 index 00000000000..26a85e04637 --- /dev/null +++ b/engine/src/flutter/src/paragraph_constraints.cc @@ -0,0 +1,23 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 "lib/txt/src/paragraph_constraints.h" + +namespace txt { + +ParagraphConstraints::ParagraphConstraints(double width) : width_(width) {} + +} // namespace txt diff --git a/engine/src/flutter/src/paragraph_constraints.h b/engine/src/flutter/src/paragraph_constraints.h new file mode 100644 index 00000000000..e6664515270 --- /dev/null +++ b/engine/src/flutter/src/paragraph_constraints.h @@ -0,0 +1,38 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 LIB_TXT_SRC_PARAGRAPH_CONSTRAINTS_H_ +#define LIB_TXT_SRC_PARAGRAPH_CONSTRAINTS_H_ + +#include "lib/ftl/macros.h" + +namespace txt { + +class ParagraphConstraints { + public: + explicit ParagraphConstraints(double width); + + double width() const { return width_; } + + private: + double width_; + + FTL_DISALLOW_COPY_AND_ASSIGN(ParagraphConstraints); +}; + +} // namespace txt + +#endif // LIB_TXT_SRC_PARAGRAPH_CONSTRAINTS_H_ diff --git a/engine/src/flutter/src/paragraph_style.cc b/engine/src/flutter/src/paragraph_style.cc new file mode 100644 index 00000000000..a55c3a37b2c --- /dev/null +++ b/engine/src/flutter/src/paragraph_style.cc @@ -0,0 +1,17 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 "lib/txt/src/paragraph_style.h" diff --git a/engine/src/flutter/src/text_style.cc b/engine/src/flutter/src/text_style.cc new file mode 100644 index 00000000000..d7d0ab7a2d7 --- /dev/null +++ b/engine/src/flutter/src/text_style.cc @@ -0,0 +1,17 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 "lib/txt/src/text_style.h" diff --git a/engine/src/flutter/tests/txt/BUILD.gn b/engine/src/flutter/tests/txt/BUILD.gn new file mode 100644 index 00000000000..93e97a1c86d --- /dev/null +++ b/engine/src/flutter/tests/txt/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright 2017 Google, Inc. +# +# 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. + +executable("txt") { + output_name = "txt_unittests" + + include_dirs = [ + "//lib/txt/src", + "//lib/txt/include", + "//third_party/icu/source/common", + ] + + sources = [ + "font_collection_unittests.cc", + "paragraph_unittests.cc", + "render_test.cc", + "txt_run_all_unittests.cc", + ] + + deps = [ + "//dart/runtime:libdart_jit", # Logging + "//flutter/fml", + "//lib/txt/shims", + "//lib/txt/src", + "//third_party/gtest", + "//third_party/harfbuzz", + "//third_party/skia", + ] +} diff --git a/engine/src/flutter/tests/txt/font_collection_unittests.cc b/engine/src/flutter/tests/txt/font_collection_unittests.cc new file mode 100644 index 00000000000..9eaf955daae --- /dev/null +++ b/engine/src/flutter/tests/txt/font_collection_unittests.cc @@ -0,0 +1,25 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 "font_collection.h" +#include "gtest/gtest.h" + +TEST(FontCollection, HasDefaultRegistrations) { + auto collection = txt::FontCollection::GetDefaultFontCollection() + .GetMinikinFontCollectionForFamily(""); + + ASSERT_NE(collection.get(), nullptr); +} diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc new file mode 100644 index 00000000000..9ea2d3d306e --- /dev/null +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -0,0 +1,47 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 "paragraph.h" +#include "paragraph_builder.h" +#include "render_test.h" +#include "third_party/icu/source/common/unicode/unistr.h" +#include "third_party/skia/include/core/SkColor.h" + +TEST_F(RenderTest, SimpleParagraph) { + const char* text = "Hello World"; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; + builder.PushStyle(text_style); + + builder.AddText(u16_text); + + builder.Pop(); + + auto paragraph = builder.Build(); + + paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}); + + paragraph->Paint(GetCanvas(), 10.0, 10.0); + + ASSERT_TRUE(Snapshot()); +} diff --git a/engine/src/flutter/tests/txt/render_test.cc b/engine/src/flutter/tests/txt/render_test.cc new file mode 100644 index 00000000000..68b45e98ac4 --- /dev/null +++ b/engine/src/flutter/tests/txt/render_test.cc @@ -0,0 +1,67 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 "render_test.h" +#include "third_party/skia/include/core/SkImageEncoder.h" +#include "third_party/skia/include/core/SkStream.h" + +RenderTest::RenderTest() : snapshots_(0) {} + +RenderTest::~RenderTest() {} + +SkCanvas* RenderTest::GetCanvas() { + return canvas_ == nullptr ? nullptr : canvas_.get(); +} + +std::string RenderTest::GetNextSnapshotName() { + const auto& test_info = + ::testing::UnitTest::GetInstance()->current_test_info(); + + std::stringstream stream; + stream << test_info->test_case_name() << "_" << test_info->name(); + stream << "_" << ++snapshots_ << ".png"; + + return stream.str(); +} + +bool RenderTest::Snapshot() { + if (!canvas_ || !bitmap_) { + return false; + } + auto file_name = GetNextSnapshotName(); + SkFILEWStream file(file_name.c_str()); + return SkEncodeImage(&file, *bitmap_, SkEncodedImageFormat::kPNG, 100); +} + +size_t RenderTest::GetTestCanvasWidth() const { + return 800; +} + +size_t RenderTest::GetTestCanvasHeight() const { + return 600; +} + +void RenderTest::SetUp() { + bitmap_ = std::make_unique(); + bitmap_->allocN32Pixels(GetTestCanvasWidth(), GetTestCanvasHeight()); + canvas_ = std::make_unique(*bitmap_); + canvas_->clear(SK_ColorTRANSPARENT); +} + +void RenderTest::TearDown() { + canvas_ = nullptr; + bitmap_ = nullptr; +} diff --git a/engine/src/flutter/tests/txt/render_test.h b/engine/src/flutter/tests/txt/render_test.h new file mode 100644 index 00000000000..ef323111560 --- /dev/null +++ b/engine/src/flutter/tests/txt/render_test.h @@ -0,0 +1,52 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 +#include + +#include "gtest/gtest.h" +#include "lib/ftl/macros.h" +#include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkCanvas.h" + +class RenderTest : public ::testing::Test { + public: + RenderTest(); + + ~RenderTest(); + + SkCanvas* GetCanvas(); + + bool Snapshot(); + + size_t GetTestCanvasWidth() const; + + size_t GetTestCanvasHeight() const; + + protected: + void SetUp() override; + + void TearDown() override; + + private: + size_t snapshots_; + std::unique_ptr bitmap_; + std::unique_ptr canvas_; + + std::string GetNextSnapshotName(); + + FTL_DISALLOW_COPY_AND_ASSIGN(RenderTest); +}; diff --git a/engine/src/flutter/tests/txt/txt_run_all_unittests.cc b/engine/src/flutter/tests/txt/txt_run_all_unittests.cc new file mode 100644 index 00000000000..a105847feae --- /dev/null +++ b/engine/src/flutter/tests/txt/txt_run_all_unittests.cc @@ -0,0 +1,26 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 "flutter/fml/icu_util.h" +#include "gtest/gtest.h" +#include "third_party/skia/include/core/SkGraphics.h" + +int main(int argc, char** argv) { + fml::icu::InitializeICU(); + SkGraphics::Init(); + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/engine/src/flutter/tests/unittest/BUILD.gn b/engine/src/flutter/tests/unittest/BUILD.gn index 5f747f7e597..3355b6880eb 100644 --- a/engine/src/flutter/tests/unittest/BUILD.gn +++ b/engine/src/flutter/tests/unittest/BUILD.gn @@ -3,38 +3,39 @@ # found in the LICENSE file. executable("unittest") { - output_name = "txt_unittests" + output_name = "minikin_unittests" testonly = true sources = [ + # "WordBreakerTests.cpp", + "//lib/ftl/test/run_all_unittests.cc", "CmapCoverageTest.cpp", "EmojiTest.cpp", + # TODO(abarth): Re-enable once we have wired up SkFontMgr. # "FontCollectionItemizeTest.cpp", # "FontCollectionTest.cpp", # "FontFamilyTest.cpp", # "FontLanguageListCacheTest.cpp", "GraphemeBreakTests.cpp", + # "HbFontCacheTest.cpp", # "HyphenatorTest.cpp", "ICUTestBase.h", + # "LayoutTest.cpp", "LayoutUtilsTest.cpp", "MeasurementTests.cpp", "SparseBitSetTest.cpp", "UnicodeUtilsTest.cpp", - # "WordBreakerTests.cpp", - "//lib/ftl/test/run_all_unittests.cc", ] - defines = [ - "kTestFontDir=\"/data/nativetest/minikin_tests/data/\"", - ] + defines = [ "kTestFontDir=\"/data/nativetest/minikin_tests/data/\"" ] deps = [ - "//lib/txt/tests/util", "//lib/txt/libs/minikin", + "//lib/txt/tests/util", "//third_party/gtest", ] } From 63bc51106ccad2fa07646bfe76da9505da1fb32d Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Mon, 5 Jun 2017 12:08:21 -0700 Subject: [PATCH 282/364] Add command line option to supply --font-directory= Change-Id: If3036a32a82249c9c95d2c5722bdb5ab097c20a1 --- engine/src/flutter/src/font_collection.cc | 14 +++--- engine/src/flutter/src/font_collection.h | 3 +- engine/src/flutter/src/paragraph.cc | 11 ++--- engine/src/flutter/src/paragraph.h | 5 ++- engine/src/flutter/tests/txt/BUILD.gn | 3 ++ .../tests/txt/font_collection_unittests.cc | 8 +++- .../flutter/tests/txt/paragraph_unittests.cc | 6 ++- .../tests/txt/txt_run_all_unittests.cc | 17 ++++++++ engine/src/flutter/tests/txt/utils.cc | 43 +++++++++++++++++++ engine/src/flutter/tests/txt/utils.h | 31 +++++++++++++ engine/src/flutter/tests/util/FileUtils.cpp | 17 ++++---- engine/src/flutter/tests/util/FileUtils.h | 1 - 12 files changed, 133 insertions(+), 26 deletions(-) create mode 100644 engine/src/flutter/tests/txt/utils.cc create mode 100644 engine/src/flutter/tests/txt/utils.h diff --git a/engine/src/flutter/src/font_collection.cc b/engine/src/flutter/src/font_collection.cc index dc0207b4e53..74596e102f0 100644 --- a/engine/src/flutter/src/font_collection.cc +++ b/engine/src/flutter/src/font_collection.cc @@ -21,6 +21,7 @@ #include "lib/ftl/logging.h" #include "lib/txt/src/font_skia.h" #include "third_party/skia/include/ports/SkFontMgr.h" +#include "third_party/skia/include/ports/SkFontMgr_directory.h" namespace txt { @@ -36,17 +37,21 @@ FontCollection::FontCollection() = default; FontCollection::~FontCollection() = default; std::shared_ptr -FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) { +FontCollection::GetMinikinFontCollectionForFamily(const std::string& family, + const std::string& dir) { // Get the Skia font manager. - auto skia_font_manager = SkFontMgr::RefDefault(); + auto skia_font_manager = dir.length() != 0 + ? SkFontMgr_New_Custom_Directory(dir.c_str()) + : SkFontMgr::RefDefault(); + FTL_DCHECK(skia_font_manager != nullptr); // Ask Skia to resolve a font style set for a font family name. - // FIXME(chinmaygarde): The name "Hevetica" is hardcoded because CoreText + // FIXME(chinmaygarde): The name "Sample Font" is hardcoded because CoreText // crashes when passed a null string. This seems to be a bug in Skia as // SkFontMgr explicitly says passing in nullptr gives the default font. auto font_style_set = skia_font_manager->matchFamily( - family.length() == 0 ? "Helvetica" : family.c_str()); + family.length() == 0 ? "Sample Font" : family.c_str()); FTL_DCHECK(font_style_set != nullptr); std::vector minikin_fonts; @@ -56,7 +61,6 @@ FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) { // Create the skia typeface auto skia_typeface = sk_ref_sp(font_style_set->createTypeface(i)); - if (skia_typeface == nullptr) { continue; } diff --git a/engine/src/flutter/src/font_collection.h b/engine/src/flutter/src/font_collection.h index efca9e35c29..a85963a6bf3 100644 --- a/engine/src/flutter/src/font_collection.h +++ b/engine/src/flutter/src/font_collection.h @@ -36,7 +36,8 @@ class FontCollection { ~FontCollection(); std::shared_ptr GetMinikinFontCollectionForFamily( - const std::string& family); + const std::string& family, + const std::string& dir = ""); private: // TODO(chinmaygarde): Caches go here. diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 4fe7d785e7d..dad0c691278 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -113,9 +113,9 @@ void Paragraph::SetText(std::vector text, StyledRuns runs) { breaker_.setText(); } -void Paragraph::AddRunsToLineBreaker() { +void Paragraph::AddRunsToLineBreaker(const std::string& rootdir) { auto collection = FontCollection::GetDefaultFontCollection() - .GetMinikinFontCollectionForFamily(""); + .GetMinikinFontCollectionForFamily("", rootdir); minikin::FontStyle font; minikin::MinikinPaint paint; for (size_t i = 0; i < runs_.size(); ++i) { @@ -125,9 +125,10 @@ void Paragraph::AddRunsToLineBreaker() { } } -void Paragraph::Layout(const ParagraphConstraints& constraints) { +void Paragraph::Layout(const ParagraphConstraints& constraints, + const std::string& rootdir) { breaker_.setLineWidths(0.0f, 0, constraints.width()); - AddRunsToLineBreaker(); + AddRunsToLineBreaker(rootdir); size_t breaks_count = breaker_.computeBreaks(); const int* breaks = breaker_.getBreaks(); @@ -140,7 +141,7 @@ void Paragraph::Layout(const ParagraphConstraints& constraints) { SkTextBlobBuilder builder; auto collection = FontCollection::GetDefaultFontCollection() - .GetMinikinFontCollectionForFamily(""); + .GetMinikinFontCollectionForFamily("", rootdir); minikin::Layout layout; SkScalar x = 0.0f; SkScalar y = 0.0f; diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 4fd5d5aff2a..eee7f435834 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -36,7 +36,8 @@ class Paragraph { ~Paragraph(); - void Layout(const ParagraphConstraints& constraints); + void Layout(const ParagraphConstraints& constraints, + const std::string& rootdir = ""); void Paint(SkCanvas* canvas, double x, double y); @@ -50,7 +51,7 @@ class Paragraph { void SetText(std::vector text, StyledRuns runs); - void AddRunsToLineBreaker(); + void AddRunsToLineBreaker(const std::string& rootdir = ""); FTL_DISALLOW_COPY_AND_ASSIGN(Paragraph); }; diff --git a/engine/src/flutter/tests/txt/BUILD.gn b/engine/src/flutter/tests/txt/BUILD.gn index 93e97a1c86d..3fb10196282 100644 --- a/engine/src/flutter/tests/txt/BUILD.gn +++ b/engine/src/flutter/tests/txt/BUILD.gn @@ -25,7 +25,10 @@ executable("txt") { "font_collection_unittests.cc", "paragraph_unittests.cc", "render_test.cc", + "render_test.h", "txt_run_all_unittests.cc", + "utils.cc", + "utils.h", ] deps = [ diff --git a/engine/src/flutter/tests/txt/font_collection_unittests.cc b/engine/src/flutter/tests/txt/font_collection_unittests.cc index 9eaf955daae..1be73be10fa 100644 --- a/engine/src/flutter/tests/txt/font_collection_unittests.cc +++ b/engine/src/flutter/tests/txt/font_collection_unittests.cc @@ -16,10 +16,14 @@ #include "font_collection.h" #include "gtest/gtest.h" +#include "lib/ftl/command_line.h" +#include "lib/ftl/logging.h" +#include "lib/txt/tests/txt/utils.h" TEST(FontCollection, HasDefaultRegistrations) { - auto collection = txt::FontCollection::GetDefaultFontCollection() - .GetMinikinFontCollectionForFamily(""); + auto collection = + txt::FontCollection::GetDefaultFontCollection() + .GetMinikinFontCollectionForFamily("", txt::GetFontDir()); ASSERT_NE(collection.get(), nullptr); } diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 9ea2d3d306e..723b5d828ff 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "lib/ftl/logging.h" +#include "lib/txt/tests/txt/utils.h" #include "paragraph.h" #include "paragraph_builder.h" #include "render_test.h" @@ -38,8 +40,8 @@ TEST_F(RenderTest, SimpleParagraph) { builder.Pop(); auto paragraph = builder.Build(); - - paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}); + paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, + txt::GetFontDir()); paragraph->Paint(GetCanvas(), 10.0, 10.0); diff --git a/engine/src/flutter/tests/txt/txt_run_all_unittests.cc b/engine/src/flutter/tests/txt/txt_run_all_unittests.cc index a105847feae..d5c62a171f6 100644 --- a/engine/src/flutter/tests/txt/txt_run_all_unittests.cc +++ b/engine/src/flutter/tests/txt/txt_run_all_unittests.cc @@ -16,9 +16,26 @@ #include "flutter/fml/icu_util.h" #include "gtest/gtest.h" +#include "lib/ftl/command_line.h" +#include "lib/ftl/logging.h" +#include "lib/txt/tests/txt/utils.h" #include "third_party/skia/include/core/SkGraphics.h" +#include + int main(int argc, char** argv) { + ftl::CommandLine cmd = ftl::CommandLineFromArgcArgv(argc, argv); + txt::SetCommandLine(cmd); + std::string dir = txt::GetCommandLineForProcess().GetOptionValueWithDefault( + "font-directory", ""); + txt::SetFontDir(dir); + if (txt::GetFontDir().length() <= 0) { + FTL_LOG(ERROR) << "Font directory must be specified with " + "--font-directoy=\"\" to run this test."; + return EXIT_FAILURE; + } + FTL_DCHECK(txt::GetFontDir().length() > 0); + fml::icu::InitializeICU(); SkGraphics::Init(); testing::InitGoogleTest(&argc, argv); diff --git a/engine/src/flutter/tests/txt/utils.cc b/engine/src/flutter/tests/txt/utils.cc new file mode 100644 index 00000000000..3f853b8a926 --- /dev/null +++ b/engine/src/flutter/tests/txt/utils.cc @@ -0,0 +1,43 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 + +#include "lib/ftl/command_line.h" +#include "lib/txt/tests/txt/utils.h" + +namespace txt { + +static std::string gFontdir; +static ftl::CommandLine gCommandLine; + +const std::string GetFontDir() { + return gFontdir; +} + +void SetFontDir(std::string& dir) { + gFontdir = dir; +} + +const ftl::CommandLine& GetCommandLineForProcess() { + return gCommandLine; +} + +void SetCommandLine(ftl::CommandLine cmd) { + gCommandLine = std::move(cmd); +} + +} // namespace txt diff --git a/engine/src/flutter/tests/txt/utils.h b/engine/src/flutter/tests/txt/utils.h new file mode 100644 index 00000000000..ed42b820739 --- /dev/null +++ b/engine/src/flutter/tests/txt/utils.h @@ -0,0 +1,31 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 + +#include "lib/ftl/command_line.h" + +namespace txt { + +const std::string GetFontDir(); + +void SetFontDir(std::string& dir); + +const ftl::CommandLine& GetCommandLineForProcess(); + +void SetCommandLine(ftl::CommandLine cmd); + +} // namespace txt diff --git a/engine/src/flutter/tests/util/FileUtils.cpp b/engine/src/flutter/tests/util/FileUtils.cpp index 92cf9191bc4..07f65342ab1 100644 --- a/engine/src/flutter/tests/util/FileUtils.cpp +++ b/engine/src/flutter/tests/util/FileUtils.cpp @@ -23,13 +23,14 @@ #include std::vector readWholeFile(const std::string& filePath) { - FILE* fp = fopen(filePath.c_str(), "r"); - LOG_ALWAYS_FATAL_IF(fp == nullptr); - struct stat st; - LOG_ALWAYS_FATAL_IF(fstat(fileno(fp), &st) != 0); + FILE* fp = fopen(filePath.c_str(), "r"); + LOG_ALWAYS_FATAL_IF(fp == nullptr); + struct stat st; + LOG_ALWAYS_FATAL_IF(fstat(fileno(fp), &st) != 0); - std::vector result(st.st_size); - LOG_ALWAYS_FATAL_IF(fread(result.data(), 1, st.st_size, fp) != static_cast(st.st_size)); - fclose(fp); - return result; + std::vector result(st.st_size); + LOG_ALWAYS_FATAL_IF(fread(result.data(), 1, st.st_size, fp) != + static_cast(st.st_size)); + fclose(fp); + return result; } diff --git a/engine/src/flutter/tests/util/FileUtils.h b/engine/src/flutter/tests/util/FileUtils.h index 1e66d1b701a..e9c5ef1c34d 100644 --- a/engine/src/flutter/tests/util/FileUtils.h +++ b/engine/src/flutter/tests/util/FileUtils.h @@ -15,4 +15,3 @@ */ std::vector readWholeFile(const std::string& filePath); - From 22345d608eece1cef845b8781d0f67ec3458fc58 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Mon, 5 Jun 2017 17:33:38 -0700 Subject: [PATCH 283/364] Add fonts to Paragraph and additional tests. Change-Id: I023cc9bc413975dabc770f6b59d4ffd1fc842ab2 --- engine/src/flutter/src/font_collection.cc | 5 +- engine/src/flutter/src/paragraph.cc | 11 +- engine/src/flutter/src/text_style.h | 2 +- .../flutter/tests/txt/paragraph_unittests.cc | 119 ++++++++++++++++++ 4 files changed, 130 insertions(+), 7 deletions(-) diff --git a/engine/src/flutter/src/font_collection.cc b/engine/src/flutter/src/font_collection.cc index 74596e102f0..dfbfbc14b29 100644 --- a/engine/src/flutter/src/font_collection.cc +++ b/engine/src/flutter/src/font_collection.cc @@ -47,11 +47,12 @@ FontCollection::GetMinikinFontCollectionForFamily(const std::string& family, FTL_DCHECK(skia_font_manager != nullptr); // Ask Skia to resolve a font style set for a font family name. - // FIXME(chinmaygarde): The name "Sample Font" is hardcoded because CoreText + // FIXME(chinmaygarde): The name "Coolvetica" is hardcoded because CoreText // crashes when passed a null string. This seems to be a bug in Skia as // SkFontMgr explicitly says passing in nullptr gives the default font. + auto font_style_set = skia_font_manager->matchFamily( - family.length() == 0 ? "Sample Font" : family.c_str()); + family.length() == 0 ? "Roboto" : family.c_str()); FTL_DCHECK(font_style_set != nullptr); std::vector minikin_fonts; diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index dad0c691278..705a1379214 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -114,12 +114,13 @@ void Paragraph::SetText(std::vector text, StyledRuns runs) { } void Paragraph::AddRunsToLineBreaker(const std::string& rootdir) { - auto collection = FontCollection::GetDefaultFontCollection() - .GetMinikinFontCollectionForFamily("", rootdir); minikin::FontStyle font; minikin::MinikinPaint paint; for (size_t i = 0; i < runs_.size(); ++i) { auto run = runs_.GetRun(i); + auto collection = + FontCollection::GetDefaultFontCollection() + .GetMinikinFontCollectionForFamily(run.style.font_family, rootdir); GetFontAndMinikinPaint(run.style, &font, &paint); breaker_.addStyleRun(&paint, collection, font, run.start, run.end, false); } @@ -140,14 +141,16 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, minikin::MinikinPaint minikin_paint; SkTextBlobBuilder builder; - auto collection = FontCollection::GetDefaultFontCollection() - .GetMinikinFontCollectionForFamily("", rootdir); + minikin::Layout layout; SkScalar x = 0.0f; SkScalar y = 0.0f; size_t break_index = 0; for (size_t run_index = 0; run_index < runs_.size(); ++run_index) { auto run = runs_.GetRun(run_index); + auto collection = + FontCollection::GetDefaultFontCollection() + .GetMinikinFontCollectionForFamily(run.style.font_family, rootdir); GetFontAndMinikinPaint(run.style, &font, &minikin_paint); GetPaint(run.style, &paint); diff --git a/engine/src/flutter/src/text_style.h b/engine/src/flutter/src/text_style.h index f2482dd4065..2b6c2cc632d 100644 --- a/engine/src/flutter/src/text_style.h +++ b/engine/src/flutter/src/text_style.h @@ -34,7 +34,7 @@ class TextStyle { FontWeight font_weight = FontWeight::w400; FontStyle font_style = FontStyle::normal; // TextBaseline text_baseline; - std::string font_family; + std::string font_family = ""; double font_size = 14.0; double letter_spacing = 0.0; double word_spacing = 0.0; diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 723b5d828ff..dd98be7ea22 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -34,6 +34,31 @@ TEST_F(RenderTest, SimpleParagraph) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; builder.PushStyle(text_style); + builder.AddText(u16_text); + + builder.Pop(); + + auto paragraph = builder.Build(); + paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, + txt::GetFontDir()); + + paragraph->Paint(GetCanvas(), 10.0, 10.0); + + ASSERT_TRUE(Snapshot()); +} + +TEST_F(RenderTest, SimpleRedParagraph) { + const char* text = "I am RED"; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.color = SK_ColorRED; + builder.PushStyle(text_style); builder.AddText(u16_text); @@ -47,3 +72,97 @@ TEST_F(RenderTest, SimpleParagraph) { ASSERT_TRUE(Snapshot()); } + +TEST_F(RenderTest, LongParagraph) { + const char* text1 = "RedRoboto"; + auto icu_text1 = icu::UnicodeString::fromUTF8(text1); + std::u16string u16_text1(icu_text1.getBuffer(), + icu_text1.getBuffer() + icu_text1.length()); + const char* text2 = "BigGreenDefault"; + auto icu_text2 = icu::UnicodeString::fromUTF8(text2); + std::u16string u16_text2(icu_text2.getBuffer(), + icu_text2.getBuffer() + icu_text2.length()); + const char* text3 = "DefcolorHomemadeApple"; + auto icu_text3 = icu::UnicodeString::fromUTF8(text3); + std::u16string u16_text3(icu_text3.getBuffer(), + icu_text3.getBuffer() + icu_text3.length()); + const char* text4 = "SmallBlueRoboto"; + auto icu_text4 = icu::UnicodeString::fromUTF8(text4); + std::u16string u16_text4(icu_text4.getBuffer(), + icu_text4.getBuffer() + icu_text4.length()); + const char* text5 = "ContinueLastStyle"; + auto icu_text5 = icu::UnicodeString::fromUTF8(text5); + std::u16string u16_text5(icu_text5.getBuffer(), + icu_text5.getBuffer() + icu_text5.length()); + + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style1; + text_style1.color = SK_ColorRED; + text_style1.font_family = "Roboto"; + builder.PushStyle(text_style1); + + builder.AddText(u16_text1); + + txt::TextStyle text_style2; + text_style2.font_size = 30; + // Letter spacing not yet implemented + text_style2.letter_spacing = 10; + text_style2.color = SK_ColorGREEN; + builder.PushStyle(text_style2); + + builder.AddText(u16_text2); + + txt::TextStyle text_style3; + text_style3.font_family = "Homemade Apple"; + builder.PushStyle(text_style3); + + builder.AddText(u16_text3); + + txt::TextStyle text_style4; + text_style4.font_size = 10; + text_style4.color = SK_ColorBLUE; + text_style4.font_family = "Roboto"; + builder.PushStyle(text_style4); + + builder.AddText(u16_text4); + + // extra text to see if it goes to default + builder.AddText(u16_text5); + + builder.Pop(); + + auto paragraph = builder.Build(); + paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, + txt::GetFontDir()); + + paragraph->Paint(GetCanvas(), 10.0, 30.0); + + ASSERT_TRUE(Snapshot()); +} + +TEST_F(RenderTest, DefaultStyleParagraph) { + const char* text = "No TextStyle! Uh Oh!"; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.color = SK_ColorRED; + + builder.AddText(u16_text); + + builder.Pop(); + + auto paragraph = builder.Build(); + paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, + txt::GetFontDir()); + + paragraph->Paint(GetCanvas(), 10.0, 10.0); + + ASSERT_TRUE(Snapshot()); +} \ No newline at end of file From 75752cc8d28e9fec7738b763e02a7eb126cd0a5f Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Tue, 6 Jun 2017 11:08:00 -0700 Subject: [PATCH 284/364] Support for 'fake bold' text and additional tests Change-Id: Ic9863052365316ea188fcf79b15378be90f440f6 --- engine/src/flutter/src/BUILD.gn | 1 + engine/src/flutter/src/font_collection.cc | 8 +- engine/src/flutter/src/font_collection.h | 12 ++ engine/src/flutter/src/paragraph.cc | 3 +- engine/src/flutter/src/text_style.h | 1 + .../tests/txt/font_collection_unittests.cc | 36 +++++- .../flutter/tests/txt/paragraph_unittests.cc | 113 ++++++++++++++++-- 7 files changed, 160 insertions(+), 14 deletions(-) diff --git a/engine/src/flutter/src/BUILD.gn b/engine/src/flutter/src/BUILD.gn index e8520ec1132..2d5792f88a3 100644 --- a/engine/src/flutter/src/BUILD.gn +++ b/engine/src/flutter/src/BUILD.gn @@ -40,5 +40,6 @@ source_set("src") { deps = [ "//lib/txt/libs/minikin", "//third_party/skia", + "//third_party/gtest", ] } diff --git a/engine/src/flutter/src/font_collection.cc b/engine/src/flutter/src/font_collection.cc index dfbfbc14b29..6763617d710 100644 --- a/engine/src/flutter/src/font_collection.cc +++ b/engine/src/flutter/src/font_collection.cc @@ -36,6 +36,10 @@ FontCollection::FontCollection() = default; FontCollection::~FontCollection() = default; +const std::string FontCollection::ProcessFamilyName(const std::string& family) { + return family.length() == 0 ? DEFAULT_FAMILY_NAME : family; +} + std::shared_ptr FontCollection::GetMinikinFontCollectionForFamily(const std::string& family, const std::string& dir) { @@ -51,8 +55,8 @@ FontCollection::GetMinikinFontCollectionForFamily(const std::string& family, // crashes when passed a null string. This seems to be a bug in Skia as // SkFontMgr explicitly says passing in nullptr gives the default font. - auto font_style_set = skia_font_manager->matchFamily( - family.length() == 0 ? "Roboto" : family.c_str()); + auto font_style_set = + skia_font_manager->matchFamily(ProcessFamilyName(family).c_str()); FTL_DCHECK(font_style_set != nullptr); std::vector minikin_fonts; diff --git a/engine/src/flutter/src/font_collection.h b/engine/src/flutter/src/font_collection.h index a85963a6bf3..b78de954d80 100644 --- a/engine/src/flutter/src/font_collection.h +++ b/engine/src/flutter/src/font_collection.h @@ -17,11 +17,14 @@ #ifndef LIB_TXT_SRC_FONT_COLLECTION_H_ #define LIB_TXT_SRC_FONT_COLLECTION_H_ +#define DEFAULT_FAMILY_NAME "Roboto" + #include #include #include #include "lib/ftl/macros.h" +#include "lib/txt/tests/txt/render_test.h" #include "minikin/FontCollection.h" #include "minikin/FontFamily.h" @@ -38,8 +41,17 @@ class FontCollection { std::shared_ptr GetMinikinFontCollectionForFamily( const std::string& family, const std::string& dir = ""); + // Temporarily public. + const std::string ProcessFamilyName(const std::string& family); + + // For Testing. Temporarily public. + static const std::string GetDefaultFamilyName() { + return DEFAULT_FAMILY_NAME; + }; private: + friend RenderTest; + // TODO(chinmaygarde): Caches go here. FTL_DISALLOW_COPY_AND_ASSIGN(FontCollection); }; diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 705a1379214..44caeada369 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -90,11 +90,12 @@ void GetFontAndMinikinPaint(const TextStyle& style, *font = minikin::FontStyle(GetWeight(style), GetItalic(style)); paint->size = style.font_size; paint->letterSpacing = style.letter_spacing; - // TODO(abarth): font_family, word_spacing. + // TODO(abarth): word_spacing. } void GetPaint(const TextStyle& style, SkPaint* paint) { paint->setTextSize(style.font_size); + paint->setFakeBoldText(style.fake_bold); } } // namespace diff --git a/engine/src/flutter/src/text_style.h b/engine/src/flutter/src/text_style.h index 2b6c2cc632d..21c122abfe0 100644 --- a/engine/src/flutter/src/text_style.h +++ b/engine/src/flutter/src/text_style.h @@ -33,6 +33,7 @@ class TextStyle { // TextDecorationStyle decoration_style FontWeight font_weight = FontWeight::w400; FontStyle font_style = FontStyle::normal; + bool fake_bold = false; // TextBaseline text_baseline; std::string font_family = ""; double font_size = 14.0; diff --git a/engine/src/flutter/tests/txt/font_collection_unittests.cc b/engine/src/flutter/tests/txt/font_collection_unittests.cc index 1be73be10fa..1851f04af96 100644 --- a/engine/src/flutter/tests/txt/font_collection_unittests.cc +++ b/engine/src/flutter/tests/txt/font_collection_unittests.cc @@ -21,9 +21,43 @@ #include "lib/txt/tests/txt/utils.h" TEST(FontCollection, HasDefaultRegistrations) { + std::string defaultFamilyName = txt::FontCollection::GetDefaultFamilyName(); + auto collection = txt::FontCollection::GetDefaultFontCollection() .GetMinikinFontCollectionForFamily("", txt::GetFontDir()); - + ASSERT_EQ( + defaultFamilyName, + txt::FontCollection::GetDefaultFontCollection().ProcessFamilyName("")); + ASSERT_NE(defaultFamilyName, + txt::FontCollection::GetDefaultFontCollection().ProcessFamilyName( + "NotARealFont!")); + ASSERT_EQ("NotARealFont!", + txt::FontCollection::GetDefaultFontCollection().ProcessFamilyName( + "NotARealFont!")); ASSERT_NE(collection.get(), nullptr); } + +TEST(FontCollection, GetMinikinFontCollections) { + std::string defaultFamilyName = txt::FontCollection::GetDefaultFamilyName(); + + auto collectionDef = + txt::FontCollection::GetDefaultFontCollection() + .GetMinikinFontCollectionForFamily("", txt::GetFontDir()); + auto collectionRoboto = + txt::FontCollection::GetDefaultFontCollection() + .GetMinikinFontCollectionForFamily("Roboto", txt::GetFontDir()); + auto collectionHomemadeApple = txt::FontCollection::GetDefaultFontCollection() + .GetMinikinFontCollectionForFamily( + "Homemade Apple", txt::GetFontDir()); + for (size_t base = 0; base < 50; base++) { + for (size_t variation = 0; variation < 50; variation++) { + ASSERT_EQ(collectionDef->hasVariationSelector(base, variation), + collectionRoboto->hasVariationSelector(base, variation)); + } + } + + ASSERT_NE(collectionDef, collectionHomemadeApple); + ASSERT_NE(collectionHomemadeApple, collectionRoboto); + ASSERT_NE(collectionDef.get(), nullptr); +} diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index dd98be7ea22..9aa842ee28f 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -15,6 +15,8 @@ */ #include "lib/ftl/logging.h" +#include "lib/txt/src/font_style.h" +#include "lib/txt/src/font_weight.h" #include "lib/txt/tests/txt/utils.h" #include "paragraph.h" #include "paragraph_builder.h" @@ -42,7 +44,7 @@ TEST_F(RenderTest, SimpleParagraph) { paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, txt::GetFontDir()); - paragraph->Paint(GetCanvas(), 10.0, 10.0); + paragraph->Paint(GetCanvas(), 10.0, 15.0); ASSERT_TRUE(Snapshot()); } @@ -68,25 +70,25 @@ TEST_F(RenderTest, SimpleRedParagraph) { paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, txt::GetFontDir()); - paragraph->Paint(GetCanvas(), 10.0, 10.0); + paragraph->Paint(GetCanvas(), 10.0, 15.0); ASSERT_TRUE(Snapshot()); } -TEST_F(RenderTest, LongParagraph) { - const char* text1 = "RedRoboto"; +TEST_F(RenderTest, RainbowParagraph) { + const char* text1 = "RedRoboto "; auto icu_text1 = icu::UnicodeString::fromUTF8(text1); std::u16string u16_text1(icu_text1.getBuffer(), icu_text1.getBuffer() + icu_text1.length()); - const char* text2 = "BigGreenDefault"; + const char* text2 = "BigGreenDefault "; auto icu_text2 = icu::UnicodeString::fromUTF8(text2); std::u16string u16_text2(icu_text2.getBuffer(), icu_text2.getBuffer() + icu_text2.length()); - const char* text3 = "DefcolorHomemadeApple"; + const char* text3 = "DefcolorHomemadeApple "; auto icu_text3 = icu::UnicodeString::fromUTF8(text3); std::u16string u16_text3(icu_text3.getBuffer(), icu_text3.getBuffer() + icu_text3.length()); - const char* text4 = "SmallBlueRoboto"; + const char* text4 = "SmallBlueRoboto "; auto icu_text4 = icu::UnicodeString::fromUTF8(text4); std::u16string u16_text4(icu_text4.getBuffer(), icu_text4.getBuffer() + icu_text4.length()); @@ -108,7 +110,9 @@ TEST_F(RenderTest, LongParagraph) { txt::TextStyle text_style2; text_style2.font_size = 30; // Letter spacing not yet implemented - text_style2.letter_spacing = 10; + text_style2.letter_spacing = 100; + text_style2.font_weight = txt::FontWeight::w600; + text_style2.fake_bold = true; text_style2.color = SK_ColorGREEN; builder.PushStyle(text_style2); @@ -128,7 +132,8 @@ TEST_F(RenderTest, LongParagraph) { builder.AddText(u16_text4); - // extra text to see if it goes to default + // Extra text to see if it goes to default when there is more text chunks than + // styles. builder.AddText(u16_text5); builder.Pop(); @@ -142,6 +147,7 @@ TEST_F(RenderTest, LongParagraph) { ASSERT_TRUE(Snapshot()); } +// Currently, this should render nothing without a supplied TextStyle. TEST_F(RenderTest, DefaultStyleParagraph) { const char* text = "No TextStyle! Uh Oh!"; auto icu_text = icu::UnicodeString::fromUTF8(text); @@ -162,7 +168,94 @@ TEST_F(RenderTest, DefaultStyleParagraph) { paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, txt::GetFontDir()); - paragraph->Paint(GetCanvas(), 10.0, 10.0); + paragraph->Paint(GetCanvas(), 10.0, 15.0); + + ASSERT_TRUE(Snapshot()); +} + +TEST_F(RenderTest, BoldParagraph) { + const char* text = "This is Red max bold text!"; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.font_size = 60; + // Letter spacing not yet implemented + text_style.letter_spacing = 10; + text_style.font_weight = txt::FontWeight::w900; + text_style.fake_bold = true; + text_style.color = SK_ColorRED; + builder.PushStyle(text_style); + + builder.AddText(u16_text); + + builder.Pop(); + + auto paragraph = builder.Build(); + paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, + txt::GetFontDir()); + + paragraph->Paint(GetCanvas(), 10.0, 60.0); + + ASSERT_TRUE(Snapshot()); +} + +TEST_F(RenderTest, LinebreakParagraph) { + const char* text = + "This is a very long sentence to test if the text will properly wrap " + "around and go to the next line. Sometimes, short sentence. Longer " + "sentences are okay too because they are nessecary. Very short." + "This is a very long sentence to test if the text will properly wrap " + "around and go to the next line. Sometimes, short sentence. Longer " + "sentences are okay too because they are nessecary. Very short." + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum." + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum." + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum."; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.font_size = 26; + // Letter spacing not yet implemented + text_style.letter_spacing = 10; + text_style.color = SK_ColorBLACK; + builder.PushStyle(text_style); + + builder.AddText(u16_text); + + builder.Pop(); + + auto paragraph = builder.Build(); + paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, + txt::GetFontDir()); + + paragraph->Paint(GetCanvas(), 5.0, 30.0); ASSERT_TRUE(Snapshot()); } \ No newline at end of file From 4e5639d921ed567a2007088279c49244866255f1 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Tue, 6 Jun 2017 16:23:28 -0700 Subject: [PATCH 285/364] Add additional test framework and tests for Italics. Overloaded paragraph text entry methods. Change-Id: I0ae9abd6130edd276b1144a0092e03e47373427d --- engine/src/flutter/src/font_collection.cc | 16 +++++ engine/src/flutter/src/font_collection.h | 17 +++-- engine/src/flutter/src/paragraph.cc | 4 +- engine/src/flutter/src/paragraph.h | 8 +++ engine/src/flutter/src/paragraph_builder.cc | 15 ++++ engine/src/flutter/src/paragraph_builder.h | 4 ++ .../tests/txt/font_collection_unittests.cc | 11 +++ .../flutter/tests/txt/paragraph_unittests.cc | 70 +++++++++++++++++-- 8 files changed, 132 insertions(+), 13 deletions(-) diff --git a/engine/src/flutter/src/font_collection.cc b/engine/src/flutter/src/font_collection.cc index 6763617d710..da244103880 100644 --- a/engine/src/flutter/src/font_collection.cc +++ b/engine/src/flutter/src/font_collection.cc @@ -17,9 +17,12 @@ #include "lib/txt/src/font_collection.h" #include +#include +#include #include "lib/ftl/logging.h" #include "lib/txt/src/font_skia.h" +#include "third_party/skia/include/core/SkString.h" #include "third_party/skia/include/ports/SkFontMgr.h" #include "third_party/skia/include/ports/SkFontMgr_directory.h" @@ -36,6 +39,19 @@ FontCollection::FontCollection() = default; FontCollection::~FontCollection() = default; +std::set FontCollection::GetFamilyNames(const std::string& dir) { + auto skia_font_manager = dir.length() != 0 + ? SkFontMgr_New_Custom_Directory(dir.c_str()) + : SkFontMgr::RefDefault(); + std::set names; + SkString str; + for (int i = 0; i < skia_font_manager->countFamilies(); i++) { + skia_font_manager->getFamilyName(i, &str); + names.insert(std::string{str.writable_str()}); + } + return names; +} + const std::string FontCollection::ProcessFamilyName(const std::string& family) { return family.length() == 0 ? DEFAULT_FAMILY_NAME : family; } diff --git a/engine/src/flutter/src/font_collection.h b/engine/src/flutter/src/font_collection.h index b78de954d80..43bdbec16f1 100644 --- a/engine/src/flutter/src/font_collection.h +++ b/engine/src/flutter/src/font_collection.h @@ -20,13 +20,14 @@ #define DEFAULT_FAMILY_NAME "Roboto" #include +#include #include #include #include "lib/ftl/macros.h" -#include "lib/txt/tests/txt/render_test.h" #include "minikin/FontCollection.h" #include "minikin/FontFamily.h" +#include "third_party/gtest/include/gtest/gtest_prod.h" namespace txt { @@ -41,17 +42,21 @@ class FontCollection { std::shared_ptr GetMinikinFontCollectionForFamily( const std::string& family, const std::string& dir = ""); - // Temporarily public. + + // Provides a vector of all available family names. + static std::set GetFamilyNames(const std::string& dir = ""); + + private: + FRIEND_TEST(FontCollection, HasDefaultRegistrations); + FRIEND_TEST(FontCollection, GetMinikinFontCollections); + FRIEND_TEST(FontCollection, GetFamilyNames); + const std::string ProcessFamilyName(const std::string& family); - // For Testing. Temporarily public. static const std::string GetDefaultFamilyName() { return DEFAULT_FAMILY_NAME; }; - private: - friend RenderTest; - // TODO(chinmaygarde): Caches go here. FTL_DISALLOW_COPY_AND_ASSIGN(FontCollection); }; diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 44caeada369..ce2edaa8661 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -60,13 +60,13 @@ int GetWeight(const TextStyle& style) { return 2; case FontWeight::w300: return 3; - case FontWeight::w400: + case FontWeight::w400: // Normal. return 4; case FontWeight::w500: return 5; case FontWeight::w600: return 6; - case FontWeight::w700: + case FontWeight::w700: // Bold. return 7; case FontWeight::w800: return 8; diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index eee7f435834..0ec43df1298 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -24,6 +24,7 @@ #include "lib/txt/src/paragraph_constraints.h" #include "lib/txt/src/styled_runs.h" #include "minikin/LineBreaker.h" +#include "third_party/gtest/include/gtest/gtest_prod.h" #include "third_party/skia/include/core/SkTextBlob.h" class SkCanvas; @@ -43,6 +44,13 @@ class Paragraph { private: friend class ParagraphBuilder; + FRIEND_TEST(RenderTest, SimpleParagraph); + FRIEND_TEST(RenderTest, SimpleRedParagraph); + FRIEND_TEST(RenderTest, RainbowParagraph); + FRIEND_TEST(RenderTest, DefaultStyleParagraph); + FRIEND_TEST(RenderTest, BoldParagraph); + FRIEND_TEST(RenderTest, LinebreakParagraph); + FRIEND_TEST(RenderTest, ItalicsParagraph); std::vector text_; StyledRuns runs_; diff --git a/engine/src/flutter/src/paragraph_builder.cc b/engine/src/flutter/src/paragraph_builder.cc index a6db3492a8e..4976b861260 100644 --- a/engine/src/flutter/src/paragraph_builder.cc +++ b/engine/src/flutter/src/paragraph_builder.cc @@ -15,6 +15,7 @@ */ #include "lib/txt/src/paragraph_builder.h" +#include "third_party/icu/source/common/unicode/unistr.h" namespace txt { @@ -46,6 +47,20 @@ void ParagraphBuilder::AddText(const std::u16string& text) { text_.insert(text_.end(), text.begin(), text.end()); } +void ParagraphBuilder::AddText(const std::string& text) { + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + AddText(u16_text); +} + +void ParagraphBuilder::AddText(const char* text) { + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + AddText(u16_text); +} + std::unique_ptr ParagraphBuilder::Build() { runs_.EndRunIfNeeded(text_.size()); std::unique_ptr paragraph = std::make_unique(); diff --git a/engine/src/flutter/src/paragraph_builder.h b/engine/src/flutter/src/paragraph_builder.h index 8c6941af9bc..71598af0b58 100644 --- a/engine/src/flutter/src/paragraph_builder.h +++ b/engine/src/flutter/src/paragraph_builder.h @@ -40,6 +40,10 @@ class ParagraphBuilder { void AddText(const std::u16string& text); + void AddText(const std::string& text); + + void AddText(const char* text); + std::unique_ptr Build(); private: diff --git a/engine/src/flutter/tests/txt/font_collection_unittests.cc b/engine/src/flutter/tests/txt/font_collection_unittests.cc index 1851f04af96..ab15710e964 100644 --- a/engine/src/flutter/tests/txt/font_collection_unittests.cc +++ b/engine/src/flutter/tests/txt/font_collection_unittests.cc @@ -20,6 +20,8 @@ #include "lib/ftl/logging.h" #include "lib/txt/tests/txt/utils.h" +namespace txt { + TEST(FontCollection, HasDefaultRegistrations) { std::string defaultFamilyName = txt::FontCollection::GetDefaultFamilyName(); @@ -61,3 +63,12 @@ TEST(FontCollection, GetMinikinFontCollections) { ASSERT_NE(collectionHomemadeApple, collectionRoboto); ASSERT_NE(collectionDef.get(), nullptr); } + +TEST(FontCollection, GetFamilyNames) { + std::set names = + txt::FontCollection::GetFamilyNames(txt::GetFontDir()); + + ASSERT_EQ(names.size(), 19ull); +} + +} // namespace txt \ No newline at end of file diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 9aa842ee28f..11b816241be 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -17,13 +17,15 @@ #include "lib/ftl/logging.h" #include "lib/txt/src/font_style.h" #include "lib/txt/src/font_weight.h" +#include "lib/txt/src/paragraph.h" #include "lib/txt/tests/txt/utils.h" -#include "paragraph.h" #include "paragraph_builder.h" #include "render_test.h" #include "third_party/icu/source/common/unicode/unistr.h" #include "third_party/skia/include/core/SkColor.h" +namespace txt { + TEST_F(RenderTest, SimpleParagraph) { const char* text = "Hello World"; auto icu_text = icu::UnicodeString::fromUTF8(text); @@ -46,6 +48,10 @@ TEST_F(RenderTest, SimpleParagraph) { paragraph->Paint(GetCanvas(), 10.0, 15.0); + ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); + for (size_t i = 0; i < u16_text.length(); i++) { + ASSERT_EQ(paragraph->text_[i], u16_text[i]); + } ASSERT_TRUE(Snapshot()); } @@ -72,6 +78,10 @@ TEST_F(RenderTest, SimpleRedParagraph) { paragraph->Paint(GetCanvas(), 10.0, 15.0); + ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); + for (size_t i = 0; i < u16_text.length(); i++) { + ASSERT_EQ(paragraph->text_[i], u16_text[i]); + } ASSERT_TRUE(Snapshot()); } @@ -108,7 +118,7 @@ TEST_F(RenderTest, RainbowParagraph) { builder.AddText(u16_text1); txt::TextStyle text_style2; - text_style2.font_size = 30; + text_style2.font_size = 50; // Letter spacing not yet implemented text_style2.letter_spacing = 100; text_style2.font_weight = txt::FontWeight::w600; @@ -142,8 +152,12 @@ TEST_F(RenderTest, RainbowParagraph) { paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, txt::GetFontDir()); - paragraph->Paint(GetCanvas(), 10.0, 30.0); + paragraph->Paint(GetCanvas(), 10.0, 50.0); + u16_text1 += u16_text2 + u16_text3 + u16_text4; + for (size_t i = 0; i < u16_text1.length(); i++) { + ASSERT_EQ(paragraph->text_[i], u16_text1[i]); + } ASSERT_TRUE(Snapshot()); } @@ -170,6 +184,10 @@ TEST_F(RenderTest, DefaultStyleParagraph) { paragraph->Paint(GetCanvas(), 10.0, 15.0); + ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); + for (size_t i = 0; i < u16_text.length(); i++) { + ASSERT_EQ(paragraph->text_[i], u16_text[i]); + } ASSERT_TRUE(Snapshot()); } @@ -186,7 +204,7 @@ TEST_F(RenderTest, BoldParagraph) { text_style.font_size = 60; // Letter spacing not yet implemented text_style.letter_spacing = 10; - text_style.font_weight = txt::FontWeight::w900; + text_style.font_weight = txt::FontWeight::w700; text_style.fake_bold = true; text_style.color = SK_ColorRED; builder.PushStyle(text_style); @@ -201,6 +219,10 @@ TEST_F(RenderTest, BoldParagraph) { paragraph->Paint(GetCanvas(), 10.0, 60.0); + ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); + for (size_t i = 0; i < u16_text.length(); i++) { + ASSERT_EQ(paragraph->text_[i], u16_text[i]); + } ASSERT_TRUE(Snapshot()); } @@ -257,5 +279,43 @@ TEST_F(RenderTest, LinebreakParagraph) { paragraph->Paint(GetCanvas(), 5.0, 30.0); + ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); + for (size_t i = 0; i < u16_text.length(); i++) { + ASSERT_EQ(paragraph->text_[i], u16_text[i]); + } ASSERT_TRUE(Snapshot()); -} \ No newline at end of file +} + +TEST_F(RenderTest, ItalicsParagraph) { + const char* text = "I am Italicized!"; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.color = SK_ColorRED; + text_style.font_style = txt::FontStyle::italic; + text_style.font_size = 35; + builder.PushStyle(text_style); + + builder.AddText(u16_text); + + builder.Pop(); + + auto paragraph = builder.Build(); + paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, + txt::GetFontDir()); + + paragraph->Paint(GetCanvas(), 10.0, 35.0); + + ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); + for (size_t i = 0; i < u16_text.length(); i++) { + ASSERT_EQ(paragraph->text_[i], u16_text[i]); + } + ASSERT_TRUE(Snapshot()); +} + +} // namespace txt From d86d3c526a1e24716b404b85e52278b528935167 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Wed, 7 Jun 2017 14:51:09 -0700 Subject: [PATCH 286/364] Add more testing for Paragraph and FontCollection. Change-Id: Idec0077f44225f0af8bbcd6464d226555f79beae --- engine/src/flutter/src/styled_runs.h | 9 ++++++ engine/src/flutter/src/text_style.cc | 28 ++++++++++++++++ engine/src/flutter/src/text_style.h | 2 ++ .../tests/txt/font_collection_unittests.cc | 29 ++++++++++++++++- .../flutter/tests/txt/paragraph_unittests.cc | 32 +++++++++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/src/styled_runs.h b/engine/src/flutter/src/styled_runs.h index 781e1eb69bb..8b757658a44 100644 --- a/engine/src/flutter/src/styled_runs.h +++ b/engine/src/flutter/src/styled_runs.h @@ -20,6 +20,7 @@ #include #include "lib/txt/src/text_style.h" +#include "third_party/gtest/include/gtest/gtest_prod.h" namespace txt { @@ -54,6 +55,14 @@ class StyledRuns { Run GetRun(size_t index) const; private: + FRIEND_TEST(RenderTest, SimpleParagraph); + FRIEND_TEST(RenderTest, SimpleRedParagraph); + FRIEND_TEST(RenderTest, RainbowParagraph); + FRIEND_TEST(RenderTest, DefaultStyleParagraph); + FRIEND_TEST(RenderTest, BoldParagraph); + FRIEND_TEST(RenderTest, LinebreakParagraph); + FRIEND_TEST(RenderTest, ItalicsParagraph); + struct IndexedRun { size_t style_index = 0; size_t start = 0; diff --git a/engine/src/flutter/src/text_style.cc b/engine/src/flutter/src/text_style.cc index d7d0ab7a2d7..bacb9a55fea 100644 --- a/engine/src/flutter/src/text_style.cc +++ b/engine/src/flutter/src/text_style.cc @@ -15,3 +15,31 @@ */ #include "lib/txt/src/text_style.h" +#include "lib/txt/src/font_style.h" +#include "lib/txt/src/font_weight.h" +#include "third_party/skia/include/core/SkColor.h" + +namespace txt { + +bool TextStyle::equals(TextStyle& other) { + if (color != other.color) + return false; + if (font_weight != other.font_weight) + return false; + if (font_style != other.font_style) + return false; + if (fake_bold != other.fake_bold) + return false; + if (font_family != other.font_family) + return false; + if (letter_spacing != other.letter_spacing) + return false; + if (word_spacing != other.word_spacing) + return false; + if (height != other.height) + return false; + + return true; +} + +} // namespace txt diff --git a/engine/src/flutter/src/text_style.h b/engine/src/flutter/src/text_style.h index 21c122abfe0..13b322f2c9f 100644 --- a/engine/src/flutter/src/text_style.h +++ b/engine/src/flutter/src/text_style.h @@ -40,6 +40,8 @@ class TextStyle { double letter_spacing = 0.0; double word_spacing = 0.0; double height = 1.0; + + bool equals(TextStyle& other); }; } // namespace txt diff --git a/engine/src/flutter/tests/txt/font_collection_unittests.cc b/engine/src/flutter/tests/txt/font_collection_unittests.cc index ab15710e964..4a069a3661e 100644 --- a/engine/src/flutter/tests/txt/font_collection_unittests.cc +++ b/engine/src/flutter/tests/txt/font_collection_unittests.cc @@ -69,6 +69,33 @@ TEST(FontCollection, GetFamilyNames) { txt::FontCollection::GetFamilyNames(txt::GetFontDir()); ASSERT_EQ(names.size(), 19ull); + + ASSERT_EQ(names.count("Roboto"), 1ull); + ASSERT_EQ(names.count("Homemade Apple"), 1ull); + + ASSERT_EQ(names.count("KoreanFont Test"), 1ull); + ASSERT_EQ(names.count("JapaneseFont Test"), 1ull); + ASSERT_EQ(names.count("EmojiFont Test"), 1ull); + ASSERT_EQ(names.count("ItalicFont Test"), 1ull); + ASSERT_EQ(names.count("VariationSelector Test"), 1ull); + ASSERT_EQ(names.count("ColorEmojiFont Test"), 1ull); + ASSERT_EQ(names.count("TraditionalChinese Test"), 1ull); + ASSERT_EQ(names.count("Sample Font"), 1ull); + ASSERT_EQ(names.count("MultiAxisFont Test"), 1ull); + ASSERT_EQ(names.count("TextEmojiFont Test"), 1ull); + ASSERT_EQ(names.count("No Cmap Format 14 Subtable Test"), 1ull); + ASSERT_EQ(names.count("ColorTextMixedEmojiFont Test"), 1ull); + ASSERT_EQ(names.count("BoldFont Test"), 1ull); + ASSERT_EQ(names.count("EmptyFont Test"), 1ull); + ASSERT_EQ(names.count("SimplifiedChinese Test"), 1ull); + ASSERT_EQ(names.count("BoldItalicFont Test"), 1ull); + ASSERT_EQ(names.count("RegularFont Test"), 1ull); + + ASSERT_EQ(names.count("Not a real font!"), 0ull); + ASSERT_EQ(names.count(""), 0ull); + ASSERT_EQ(names.count("Helvetica"), 0ull); + ASSERT_EQ(names.count("TimesNewRoman"), 0ull); + ASSERT_EQ(names.count("Arial"), 0ull); } -} // namespace txt \ No newline at end of file +} // namespace txt diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 11b816241be..344418efa28 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -52,6 +52,10 @@ TEST_F(RenderTest, SimpleParagraph) { for (size_t i = 0; i < u16_text.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text[i]); } + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].color(), text_style.color); ASSERT_TRUE(Snapshot()); } @@ -82,6 +86,10 @@ TEST_F(RenderTest, SimpleRedParagraph) { for (size_t i = 0; i < u16_text.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text[i]); } + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].color(), text_style.color); ASSERT_TRUE(Snapshot()); } @@ -158,6 +166,16 @@ TEST_F(RenderTest, RainbowParagraph) { for (size_t i = 0; i < u16_text1.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text1[i]); } + ASSERT_EQ(paragraph->runs_.runs_.size(), 4ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 4ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style1)); + ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style2)); + ASSERT_TRUE(paragraph->runs_.styles_[2].equals(text_style3)); + ASSERT_TRUE(paragraph->runs_.styles_[3].equals(text_style4)); + ASSERT_EQ(paragraph->records_[0].color(), text_style1.color); + ASSERT_EQ(paragraph->records_[1].color(), text_style2.color); + ASSERT_EQ(paragraph->records_[2].color(), text_style3.color); + ASSERT_EQ(paragraph->records_[3].color(), text_style4.color); ASSERT_TRUE(Snapshot()); } @@ -188,6 +206,8 @@ TEST_F(RenderTest, DefaultStyleParagraph) { for (size_t i = 0; i < u16_text.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text[i]); } + ASSERT_EQ(paragraph->runs_.runs_.size(), 0ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 0ull); ASSERT_TRUE(Snapshot()); } @@ -223,6 +243,10 @@ TEST_F(RenderTest, BoldParagraph) { for (size_t i = 0; i < u16_text.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text[i]); } + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].color(), text_style.color); ASSERT_TRUE(Snapshot()); } @@ -283,6 +307,10 @@ TEST_F(RenderTest, LinebreakParagraph) { for (size_t i = 0; i < u16_text.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text[i]); } + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].color(), text_style.color); ASSERT_TRUE(Snapshot()); } @@ -315,6 +343,10 @@ TEST_F(RenderTest, ItalicsParagraph) { for (size_t i = 0; i < u16_text.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text[i]); } + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].color(), text_style.color); ASSERT_TRUE(Snapshot()); } From cf223546c47bbbe2e63c073f26b5ef222ee2a3d7 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Thu, 8 Jun 2017 10:47:39 -0700 Subject: [PATCH 287/364] Add TextStyle properties to better support Flutter API Change-Id: I13174dafa497328c80aada02fe144bd1b3d7f396 --- engine/src/flutter/src/BUILD.gn | 3 ++ engine/src/flutter/src/paragraph.cc | 2 +- engine/src/flutter/src/text_align.h | 2 +- engine/src/flutter/src/text_baseline.h | 29 ++++++++++++++ engine/src/flutter/src/text_decoration.cc | 22 +++++++++++ engine/src/flutter/src/text_decoration.h | 39 +++++++++++++++++++ engine/src/flutter/src/text_style.h | 10 +++-- .../flutter/tests/txt/paragraph_unittests.cc | 1 + 8 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 engine/src/flutter/src/text_baseline.h create mode 100644 engine/src/flutter/src/text_decoration.cc create mode 100644 engine/src/flutter/src/text_decoration.h diff --git a/engine/src/flutter/src/BUILD.gn b/engine/src/flutter/src/BUILD.gn index 2d5792f88a3..3ff3e9c6b07 100644 --- a/engine/src/flutter/src/BUILD.gn +++ b/engine/src/flutter/src/BUILD.gn @@ -33,6 +33,9 @@ source_set("src") { "styled_runs.cc", "styled_runs.h", "text_align.h", + "text_baseline.h", + "text_decoration.cc", + "text_decoration.h", "text_style.cc", "text_style.h", ] diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index ce2edaa8661..517be88eb6f 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -194,7 +194,7 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, x = 0.0f; // TODO(abarth): Use the line height, which is something like the max // font_size for runs in this line times the paragraph's line height. - y += run.style.font_size; + y += run.style.font_size * run.style.height; break_index += 1; } else { x += layout.getAdvance(); diff --git a/engine/src/flutter/src/text_align.h b/engine/src/flutter/src/text_align.h index 91a291ff9ff..52922a2f72f 100644 --- a/engine/src/flutter/src/text_align.h +++ b/engine/src/flutter/src/text_align.h @@ -23,7 +23,7 @@ enum class TextAlign { left, right, center, - // justify, + justify, }; } // namespace txt diff --git a/engine/src/flutter/src/text_baseline.h b/engine/src/flutter/src/text_baseline.h new file mode 100644 index 00000000000..67f88cac8ca --- /dev/null +++ b/engine/src/flutter/src/text_baseline.h @@ -0,0 +1,29 @@ +/* + * Copyright 2017 Google Inc. + * + * 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 LIB_TXT_SRC_TEXT_BASELINE_H_ +#define LIB_TXT_SRC_TEXT_BASELINE_H_ + +namespace txt { + +enum TextBaseline { + kAlphabetic, + kIdeographic, +}; + +} // namespace txt + +#endif // LIB_TXT_SRC_TEXT_BASELINE_H_ diff --git a/engine/src/flutter/src/text_decoration.cc b/engine/src/flutter/src/text_decoration.cc new file mode 100644 index 00000000000..28804c144f9 --- /dev/null +++ b/engine/src/flutter/src/text_decoration.cc @@ -0,0 +1,22 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 +#include + +#include "lib/txt/src/text_decoration.h" + +namespace txt {} // namespace txt diff --git a/engine/src/flutter/src/text_decoration.h b/engine/src/flutter/src/text_decoration.h new file mode 100644 index 00000000000..8e7b1654a49 --- /dev/null +++ b/engine/src/flutter/src/text_decoration.h @@ -0,0 +1,39 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 LIB_TXT_SRC_TEXT_DECORATION_H_ +#define LIB_TXT_SRC_TEXT_DECORATION_H_ + +namespace txt { + +enum TextDecoration { + kNone = 0x0, + kUnderline = 0x1, + kOverline = 0x2, + kLineThrough = 0x4, +}; + +enum TextDecorationStyle { + kSolid, + kDouble, // "double" is reserved. + kDotted, + kDashed, + kWavy +}; + +} // namespace txt + +#endif // LIB_TXT_SRC_TEXT_DECORATION_H_ \ No newline at end of file diff --git a/engine/src/flutter/src/text_style.h b/engine/src/flutter/src/text_style.h index 13b322f2c9f..23c2043b0a0 100644 --- a/engine/src/flutter/src/text_style.h +++ b/engine/src/flutter/src/text_style.h @@ -21,6 +21,8 @@ #include "lib/txt/src/font_style.h" #include "lib/txt/src/font_weight.h" +#include "lib/txt/src/text_baseline.h" +#include "lib/txt/src/text_decoration.h" #include "third_party/skia/include/core/SkColor.h" namespace txt { @@ -28,13 +30,13 @@ namespace txt { class TextStyle { public: SkColor color = SK_ColorWHITE; - // TextDecoration decoration, - // SkColor decoration_color; - // TextDecorationStyle decoration_style + TextDecoration decoration = TextDecoration::kNone; + SkColor decoration_color = SK_ColorWHITE; + TextDecorationStyle decoration_style = TextDecorationStyle::kSolid; FontWeight font_weight = FontWeight::w400; FontStyle font_style = FontStyle::normal; bool fake_bold = false; - // TextBaseline text_baseline; + TextBaseline text_baseline = TextBaseline::kAlphabetic; std::string font_family = ""; double font_size = 14.0; double letter_spacing = 0.0; diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 344418efa28..e3901f02f0b 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -291,6 +291,7 @@ TEST_F(RenderTest, LinebreakParagraph) { // Letter spacing not yet implemented text_style.letter_spacing = 10; text_style.color = SK_ColorBLACK; + text_style.height = 1.15; builder.PushStyle(text_style); builder.AddText(u16_text); From ef3b6d0b6e1ce26c65b164329fb8b060864b166b Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Thu, 8 Jun 2017 18:27:29 -0700 Subject: [PATCH 288/364] Restructure Building and new features for Flutter support. Change-Id: Ia0454fabcd89806cfb0e07148696e9ae66c351b6 --- engine/src/flutter/BUILD.gn | 51 +++++++++++++++++---- engine/src/flutter/examples/BUILD.gn | 2 +- engine/src/flutter/src/BUILD.gn | 33 +------------ engine/src/flutter/src/paragraph.cc | 26 +++++++++-- engine/src/flutter/src/paragraph.h | 12 +++++ engine/src/flutter/src/paragraph_builder.cc | 5 +- engine/src/flutter/src/paragraph_builder.h | 1 + engine/src/flutter/tests/txt/BUILD.gn | 2 +- 8 files changed, 85 insertions(+), 47 deletions(-) diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index 34c9c145fa9..8cb56f42a91 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -12,13 +12,48 @@ # See the License for the specific language governing permissions and # limitations under the License. -group("txt") { - testonly = true - - deps = [ - "examples:txt_example($host_toolchain)", - "src", - "tests/txt($host_toolchain)", # txt_unittests - "tests/unittest($host_toolchain)", # minikin_unittest +config("txt_config") { + include_dirs = [ + "//lib/txt/include", + "//third_party/harfbuzz/src", + "//lib/txt/shims", ] } + +static_library("txt") { + sources = [ + "src/font_collection.cc", + "src/font_collection.h", + "src/font_skia.cc", + "src/font_skia.h", + "src/font_style.h", + "src/font_weight.h", + "src/paint_record.cc", + "src/paint_record.h", + "src/paragraph.cc", + "src/paragraph.h", + "src/paragraph_builder.cc", + "src/paragraph_builder.h", + "src/paragraph_constraints.cc", + "src/paragraph_constraints.h", + "src/paragraph_style.cc", + "src/paragraph_style.h", + "src/styled_runs.cc", + "src/styled_runs.h", + "src/text_align.h", + "src/text_baseline.h", + "src/text_decoration.cc", + "src/text_decoration.h", + "src/text_style.cc", + "src/text_style.h", + ] + + public_configs = [ ":txt_config" ] + + deps = [ + "//lib/txt/libs/minikin", + "//third_party/skia", + "//third_party/gtest", + ] + +} diff --git a/engine/src/flutter/examples/BUILD.gn b/engine/src/flutter/examples/BUILD.gn index 20780a3d655..b0452feb4cb 100644 --- a/engine/src/flutter/examples/BUILD.gn +++ b/engine/src/flutter/examples/BUILD.gn @@ -21,7 +21,7 @@ executable("txt_example") { "//dart/runtime:libdart_jit", "//flutter/fml", "//lib/txt/libs/minikin", - "//lib/txt/src", + "//lib/txt", "//third_party/icu:icuuc", "//third_party/skia", ] diff --git a/engine/src/flutter/src/BUILD.gn b/engine/src/flutter/src/BUILD.gn index 3ff3e9c6b07..024820767e7 100644 --- a/engine/src/flutter/src/BUILD.gn +++ b/engine/src/flutter/src/BUILD.gn @@ -13,36 +13,5 @@ # limitations under the License. source_set("src") { - sources = [ - "font_collection.cc", - "font_collection.h", - "font_skia.cc", - "font_skia.h", - "font_style.h", - "font_weight.h", - "paint_record.cc", - "paint_record.h", - "paragraph.cc", - "paragraph.h", - "paragraph_builder.cc", - "paragraph_builder.h", - "paragraph_constraints.cc", - "paragraph_constraints.h", - "paragraph_style.cc", - "paragraph_style.h", - "styled_runs.cc", - "styled_runs.h", - "text_align.h", - "text_baseline.h", - "text_decoration.cc", - "text_decoration.h", - "text_style.cc", - "text_style.h", - ] - - deps = [ - "//lib/txt/libs/minikin", - "//third_party/skia", - "//third_party/gtest", - ] + } diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 517be88eb6f..0912565557e 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -22,7 +22,7 @@ #include #include -#include +#include "minikin/LineBreaker.h" #include "lib/ftl/logging.h" @@ -145,7 +145,6 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, minikin::Layout layout; SkScalar x = 0.0f; - SkScalar y = 0.0f; size_t break_index = 0; for (size_t run_index = 0; run_index < runs_.size(); ++run_index) { auto run = runs_.GetRun(run_index); @@ -188,13 +187,14 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, // TODO(abarth): We could keep the same SkTextBlobBuilder as long as the // color stayed the same. records_.push_back( - PaintRecord(run.style.color, SkPoint::Make(x, y), builder.make())); + PaintRecord(run.style.color, SkPoint::Make(x, y_), builder.make())); if (layout_end == next_break) { x = 0.0f; // TODO(abarth): Use the line height, which is something like the max // font_size for runs in this line times the paragraph's line height. - y += run.style.font_size * run.style.height; + y_ += run.style.font_size * run.style.height; + lines_++; break_index += 1; } else { x += layout.getAdvance(); @@ -205,6 +205,18 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, } } +const ParagraphStyle& Paragraph::GetParagraphStyle() const { + return paragraph_style_; +} + +double Paragraph::GetHeight() const { + return y_; +} + +void Paragraph::SetParagraphStyle(const ParagraphStyle& style) { + paragraph_style_ = style; +} + void Paragraph::Paint(SkCanvas* canvas, double x, double y) { SkPaint paint; for (const auto& record : records_) { @@ -214,4 +226,10 @@ void Paragraph::Paint(SkCanvas* canvas, double x, double y) { } } +bool Paragraph::DidExceedMaxLines() const { + if (lines_ > paragraph_style_.max_lines) + return true; + return false; +} + } // namespace txt diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 0ec43df1298..c515e9839d2 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -22,6 +22,7 @@ #include "lib/ftl/macros.h" #include "lib/txt/src/paint_record.h" #include "lib/txt/src/paragraph_constraints.h" +#include "lib/txt/src/paragraph_style.h" #include "lib/txt/src/styled_runs.h" #include "minikin/LineBreaker.h" #include "third_party/gtest/include/gtest/gtest_prod.h" @@ -42,6 +43,12 @@ class Paragraph { void Paint(SkCanvas* canvas, double x, double y); + const ParagraphStyle& GetParagraphStyle() const; + + double GetHeight() const; + + bool DidExceedMaxLines() const; + private: friend class ParagraphBuilder; FRIEND_TEST(RenderTest, SimpleParagraph); @@ -56,9 +63,14 @@ class Paragraph { StyledRuns runs_; minikin::LineBreaker breaker_; std::vector records_; + ParagraphStyle paragraph_style_; + int lines_ = 1; // Number of lines after Layout(). + SkScalar y_ = 0.0f; // Height of the paragraph after Layout(). void SetText(std::vector text, StyledRuns runs); + void SetParagraphStyle(const ParagraphStyle& style); + void AddRunsToLineBreaker(const std::string& rootdir = ""); FTL_DISALLOW_COPY_AND_ASSIGN(Paragraph); diff --git a/engine/src/flutter/src/paragraph_builder.cc b/engine/src/flutter/src/paragraph_builder.cc index 4976b861260..116936e1844 100644 --- a/engine/src/flutter/src/paragraph_builder.cc +++ b/engine/src/flutter/src/paragraph_builder.cc @@ -15,11 +15,13 @@ */ #include "lib/txt/src/paragraph_builder.h" +#include "lib/txt/src/paragraph_style.h" #include "third_party/icu/source/common/unicode/unistr.h" namespace txt { -ParagraphBuilder::ParagraphBuilder(ParagraphStyle style) {} +ParagraphBuilder::ParagraphBuilder(ParagraphStyle style) + : paragraph_style_(style) {} ParagraphBuilder::~ParagraphBuilder() = default; @@ -65,6 +67,7 @@ std::unique_ptr ParagraphBuilder::Build() { runs_.EndRunIfNeeded(text_.size()); std::unique_ptr paragraph = std::make_unique(); paragraph->SetText(std::move(text_), std::move(runs_)); + paragraph->SetParagraphStyle(paragraph_style_); return paragraph; } diff --git a/engine/src/flutter/src/paragraph_builder.h b/engine/src/flutter/src/paragraph_builder.h index 71598af0b58..41bd6a02a26 100644 --- a/engine/src/flutter/src/paragraph_builder.h +++ b/engine/src/flutter/src/paragraph_builder.h @@ -50,6 +50,7 @@ class ParagraphBuilder { std::vector text_; std::vector style_stack_; StyledRuns runs_; + ParagraphStyle paragraph_style_; FTL_DISALLOW_COPY_AND_ASSIGN(ParagraphBuilder); }; diff --git a/engine/src/flutter/tests/txt/BUILD.gn b/engine/src/flutter/tests/txt/BUILD.gn index 3fb10196282..dad5c408f3c 100644 --- a/engine/src/flutter/tests/txt/BUILD.gn +++ b/engine/src/flutter/tests/txt/BUILD.gn @@ -35,7 +35,7 @@ executable("txt") { "//dart/runtime:libdart_jit", # Logging "//flutter/fml", "//lib/txt/shims", - "//lib/txt/src", + "//lib/txt", "//third_party/gtest", "//third_party/harfbuzz", "//third_party/skia", From 56e4048b17c66510a1c72bece0ebeab89f5ae187 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Fri, 9 Jun 2017 12:20:35 -0700 Subject: [PATCH 289/364] Fix Minikin to allow proper compilation in Hyphenator. Change-Id: I2aeb3d5e494ce941dcc8baec2f0bacd15c163094 --- engine/src/flutter/include/minikin/Hyphenator.h | 1 + 1 file changed, 1 insertion(+) diff --git a/engine/src/flutter/include/minikin/Hyphenator.h b/engine/src/flutter/include/minikin/Hyphenator.h index c2d9d3b63a0..937fc646f55 100644 --- a/engine/src/flutter/include/minikin/Hyphenator.h +++ b/engine/src/flutter/include/minikin/Hyphenator.h @@ -25,6 +25,7 @@ #include "unicode/locid.h" #include #include +#include #ifndef MINIKIN_HYPHENATOR_H #define MINIKIN_HYPHENATOR_H From 94900efe1d17760bfd1e77e90c7108f7c3baf1f8 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Fri, 9 Jun 2017 17:48:57 -0700 Subject: [PATCH 290/364] Now supporting initial integration with Flutter. Change-Id: Id71461bd96e08eae0e24ab35a040874d960af8e0 --- engine/src/flutter/BUILD.gn | 7 ++-- engine/src/flutter/src/font_collection.cc | 36 +++++++++++++-------- engine/src/flutter/src/font_collection.h | 16 +++++---- engine/src/flutter/src/paragraph.cc | 28 ++++++++++++---- engine/src/flutter/src/paragraph.h | 11 +++++-- engine/src/flutter/src/paragraph_builder.cc | 7 ++++ engine/src/flutter/src/paragraph_builder.h | 4 +++ engine/src/flutter/src/paragraph_style.h | 6 +++- 8 files changed, 85 insertions(+), 30 deletions(-) diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index 8cb56f42a91..d5e1d7596e9 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -21,6 +21,10 @@ config("txt_config") { } static_library("txt") { + if (current_toolchain == host_toolchain) { + defines = [ "DIRECTORY_FONT_MANAGER_AVAILABLE" ] + } + sources = [ "src/font_collection.cc", "src/font_collection.h", @@ -52,8 +56,7 @@ static_library("txt") { deps = [ "//lib/txt/libs/minikin", - "//third_party/skia", "//third_party/gtest", + "//third_party/skia", ] - } diff --git a/engine/src/flutter/src/font_collection.cc b/engine/src/flutter/src/font_collection.cc index da244103880..e7b55875bd7 100644 --- a/engine/src/flutter/src/font_collection.cc +++ b/engine/src/flutter/src/font_collection.cc @@ -35,36 +35,46 @@ FontCollection& FontCollection::GetDefaultFontCollection() { return *collection; } -FontCollection::FontCollection() = default; +FontCollection::FontCollection() { +#ifdef DIRECTORY_FONT_MANAGER_AVAILABLE + skia_font_manager_ = dir.length() != 0 + ? SkFontMgr_New_Custom_Directory(dir.c_str()) + : SkFontMgr::RefDefault(); +#else + skia_font_manager_ = SkFontMgr::RefDefault(); +#endif +} FontCollection::~FontCollection() = default; std::set FontCollection::GetFamilyNames(const std::string& dir) { - auto skia_font_manager = dir.length() != 0 - ? SkFontMgr_New_Custom_Directory(dir.c_str()) - : SkFontMgr::RefDefault(); std::set names; SkString str; - for (int i = 0; i < skia_font_manager->countFamilies(); i++) { - skia_font_manager->getFamilyName(i, &str); + for (int i = 0; i < skia_font_manager_->countFamilies(); i++) { + skia_font_manager_->getFamilyName(i, &str); names.insert(std::string{str.writable_str()}); } return names; } const std::string FontCollection::ProcessFamilyName(const std::string& family) { +#ifdef DIRECTORY_FONT_MANAGER_AVAILABLE return family.length() == 0 ? DEFAULT_FAMILY_NAME : family; +#else + if (family.length() == 0) { + return *GetFamilyNames().begin(); + } else if (GetFamilyNames().count(family) > 0) { // Ensure family exists. + return family; + } else { + return *GetFamilyNames().begin(); // First family available. + } +#endif } std::shared_ptr FontCollection::GetMinikinFontCollectionForFamily(const std::string& family, const std::string& dir) { - // Get the Skia font manager. - auto skia_font_manager = dir.length() != 0 - ? SkFontMgr_New_Custom_Directory(dir.c_str()) - : SkFontMgr::RefDefault(); - - FTL_DCHECK(skia_font_manager != nullptr); + FTL_DCHECK(skia_font_manager_ != nullptr); // Ask Skia to resolve a font style set for a font family name. // FIXME(chinmaygarde): The name "Coolvetica" is hardcoded because CoreText @@ -72,7 +82,7 @@ FontCollection::GetMinikinFontCollectionForFamily(const std::string& family, // SkFontMgr explicitly says passing in nullptr gives the default font. auto font_style_set = - skia_font_manager->matchFamily(ProcessFamilyName(family).c_str()); + skia_font_manager_->matchFamily(ProcessFamilyName(family).c_str()); FTL_DCHECK(font_style_set != nullptr); std::vector minikin_fonts; diff --git a/engine/src/flutter/src/font_collection.h b/engine/src/flutter/src/font_collection.h index 43bdbec16f1..531ef23e489 100644 --- a/engine/src/flutter/src/font_collection.h +++ b/engine/src/flutter/src/font_collection.h @@ -28,6 +28,8 @@ #include "minikin/FontCollection.h" #include "minikin/FontFamily.h" #include "third_party/gtest/include/gtest/gtest_prod.h" +#include "third_party/skia/include/core/SkRefCnt.h" +#include "third_party/skia/include/ports/SkFontMgr.h" namespace txt { @@ -35,18 +37,16 @@ class FontCollection { public: static FontCollection& GetDefaultFontCollection(); - FontCollection(); - - ~FontCollection(); - std::shared_ptr GetMinikinFontCollectionForFamily( const std::string& family, const std::string& dir = ""); - // Provides a vector of all available family names. - static std::set GetFamilyNames(const std::string& dir = ""); + // Provides a set of all available family names. + std::set GetFamilyNames(const std::string& dir = ""); private: + sk_sp skia_font_manager_; + FRIEND_TEST(FontCollection, HasDefaultRegistrations); FRIEND_TEST(FontCollection, GetMinikinFontCollections); FRIEND_TEST(FontCollection, GetFamilyNames); @@ -57,6 +57,10 @@ class FontCollection { return DEFAULT_FAMILY_NAME; }; + FontCollection(); + + ~FontCollection(); + // TODO(chinmaygarde): Caches go here. FTL_DISALLOW_COPY_AND_ASSIGN(FontCollection); }; diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 0912565557e..fd4ed256c3a 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -90,6 +90,7 @@ void GetFontAndMinikinPaint(const TextStyle& style, *font = minikin::FontStyle(GetWeight(style), GetItalic(style)); paint->size = style.font_size; paint->letterSpacing = style.letter_spacing; + paint->wordSpacing = style.word_spacing; // Likely not working yet. // TODO(abarth): word_spacing. } @@ -128,8 +129,11 @@ void Paragraph::AddRunsToLineBreaker(const std::string& rootdir) { } void Paragraph::Layout(const ParagraphConstraints& constraints, - const std::string& rootdir) { + const std::string& rootdir, + const double x_offset, + const double y_offset) { breaker_.setLineWidths(0.0f, 0, constraints.width()); + width_ = constraints.width(); AddRunsToLineBreaker(rootdir); size_t breaks_count = breaker_.computeBreaks(); const int* breaks = breaker_.getBreaks(); @@ -144,7 +148,8 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, SkTextBlobBuilder builder; minikin::Layout layout; - SkScalar x = 0.0f; + SkScalar x = x_offset; + y_ = y_offset; size_t break_index = 0; for (size_t run_index = 0; run_index < runs_.size(); ++run_index) { auto run = runs_.GetRun(run_index); @@ -155,7 +160,7 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, GetPaint(run.style, &paint); size_t layout_start = run.start; - while (layout_start < run.end) { + while (layout_start < run.end && !DidExceedMaxLines()) { const size_t next_break = (break_index > breaks_count - 1) ? std::numeric_limits::max() : breaks[break_index]; @@ -194,8 +199,8 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, // TODO(abarth): Use the line height, which is something like the max // font_size for runs in this line times the paragraph's line height. y_ += run.style.font_size * run.style.height; - lines_++; break_index += 1; + lines_++; } else { x += layout.getAdvance(); } @@ -209,8 +214,17 @@ const ParagraphStyle& Paragraph::GetParagraphStyle() const { return paragraph_style_; } +double Paragraph::GetAlphabeticBaseline() const { + return FLT_MAX; +} + +double Paragraph::GetIdeographicBaseline() const { + return FLT_MAX; +} + double Paragraph::GetHeight() const { - return y_; + return paragraph_style_.font_size * paragraph_style_.line_height * + paragraph_style_.max_lines; } void Paragraph::SetParagraphStyle(const ParagraphStyle& style) { @@ -227,7 +241,9 @@ void Paragraph::Paint(SkCanvas* canvas, double x, double y) { } bool Paragraph::DidExceedMaxLines() const { - if (lines_ > paragraph_style_.max_lines) + if (y_ / (paragraph_style_.font_size * paragraph_style_.line_height) > + paragraph_style_.max_lines) + // if (lines_ > paragraph_style_.max_lines) return true; return false; } diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index c515e9839d2..513d1fb57fb 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -39,7 +39,9 @@ class Paragraph { ~Paragraph(); void Layout(const ParagraphConstraints& constraints, - const std::string& rootdir = ""); + const std::string& rootdir = "", + const double x_offset = 0.0, + const double y_offset = 0.0); void Paint(SkCanvas* canvas, double x, double y); @@ -47,6 +49,10 @@ class Paragraph { double GetHeight() const; + double GetAlphabeticBaseline() const; + + double GetIdeographicBaseline() const; + bool DidExceedMaxLines() const; private: @@ -64,8 +70,9 @@ class Paragraph { minikin::LineBreaker breaker_; std::vector records_; ParagraphStyle paragraph_style_; - int lines_ = 1; // Number of lines after Layout(). SkScalar y_ = 0.0f; // Height of the paragraph after Layout(). + double width_ = 0.0f; + int lines_ = 0; void SetText(std::vector text, StyledRuns runs); diff --git a/engine/src/flutter/src/paragraph_builder.cc b/engine/src/flutter/src/paragraph_builder.cc index 116936e1844..3d980eae3a3 100644 --- a/engine/src/flutter/src/paragraph_builder.cc +++ b/engine/src/flutter/src/paragraph_builder.cc @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "lib/ftl/logging.h" #include "lib/txt/src/paragraph_builder.h" #include "lib/txt/src/paragraph_style.h" @@ -23,6 +24,12 @@ namespace txt { ParagraphBuilder::ParagraphBuilder(ParagraphStyle style) : paragraph_style_(style) {} +ParagraphBuilder::ParagraphBuilder() {} + +void ParagraphBuilder::SetParagraphStyle(const ParagraphStyle& style) { + paragraph_style_ = style; +} + ParagraphBuilder::~ParagraphBuilder() = default; void ParagraphBuilder::PushStyle(const TextStyle& style) { diff --git a/engine/src/flutter/src/paragraph_builder.h b/engine/src/flutter/src/paragraph_builder.h index 41bd6a02a26..5df84ca72aa 100644 --- a/engine/src/flutter/src/paragraph_builder.h +++ b/engine/src/flutter/src/paragraph_builder.h @@ -32,6 +32,8 @@ class ParagraphBuilder { public: explicit ParagraphBuilder(ParagraphStyle style); + ParagraphBuilder(); + ~ParagraphBuilder(); void PushStyle(const TextStyle& style); @@ -44,6 +46,8 @@ class ParagraphBuilder { void AddText(const char* text); + void SetParagraphStyle(const ParagraphStyle& style); + std::unique_ptr Build(); private: diff --git a/engine/src/flutter/src/paragraph_style.h b/engine/src/flutter/src/paragraph_style.h index eec58159da6..e1730287a61 100644 --- a/engine/src/flutter/src/paragraph_style.h +++ b/engine/src/flutter/src/paragraph_style.h @@ -28,7 +28,11 @@ namespace txt { class ParagraphStyle { public: TextAlign text_align = TextAlign::left; - int max_lines = 0; + FontWeight font_weight = FontWeight::w400; + FontStyle font_style = FontStyle::normal; + std::string font_family = ""; + double font_size = 14; + int max_lines = 1; double line_height = 1.0; std::string ellipsis; }; From 482348524544b0c7ebfe856151e233d3d2cb5092 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Thu, 15 Jun 2017 12:13:14 -0700 Subject: [PATCH 291/364] Restructure Building of tests and FontCollection Change-Id: Ifd7d9cd505b119684ccb42c998204d41ee7ef93e --- engine/src/flutter/src/font_collection.cc | 15 +++++--- engine/src/flutter/src/font_collection.h | 9 +++-- engine/src/flutter/src/paragraph.cc | 8 ++-- engine/src/flutter/tests/BUILD.gn | 22 +++++++++++ .../tests/txt/font_collection_unittests.cc | 37 +++++++++---------- 5 files changed, 58 insertions(+), 33 deletions(-) create mode 100644 engine/src/flutter/tests/BUILD.gn diff --git a/engine/src/flutter/src/font_collection.cc b/engine/src/flutter/src/font_collection.cc index e7b55875bd7..05b5d6b66f6 100644 --- a/engine/src/flutter/src/font_collection.cc +++ b/engine/src/flutter/src/font_collection.cc @@ -28,14 +28,18 @@ namespace txt { -FontCollection& FontCollection::GetDefaultFontCollection() { +FontCollection& FontCollection::GetFontCollection(std::string dir) { static FontCollection* collection = nullptr; static std::once_flag once; - std::call_once(once, []() { collection = new FontCollection(); }); + std::call_once(once, [dir]() { collection = new FontCollection(dir); }); return *collection; } -FontCollection::FontCollection() { +FontCollection& FontCollection::GetDefaultFontCollection() { + return GetFontCollection(""); +} + +FontCollection::FontCollection(std::string dir) { #ifdef DIRECTORY_FONT_MANAGER_AVAILABLE skia_font_manager_ = dir.length() != 0 ? SkFontMgr_New_Custom_Directory(dir.c_str()) @@ -47,7 +51,7 @@ FontCollection::FontCollection() { FontCollection::~FontCollection() = default; -std::set FontCollection::GetFamilyNames(const std::string& dir) { +std::set FontCollection::GetFamilyNames() { std::set names; SkString str; for (int i = 0; i < skia_font_manager_->countFamilies(); i++) { @@ -72,8 +76,7 @@ const std::string FontCollection::ProcessFamilyName(const std::string& family) { } std::shared_ptr -FontCollection::GetMinikinFontCollectionForFamily(const std::string& family, - const std::string& dir) { +FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) { FTL_DCHECK(skia_font_manager_ != nullptr); // Ask Skia to resolve a font style set for a font family name. diff --git a/engine/src/flutter/src/font_collection.h b/engine/src/flutter/src/font_collection.h index 531ef23e489..836e22e8ff7 100644 --- a/engine/src/flutter/src/font_collection.h +++ b/engine/src/flutter/src/font_collection.h @@ -37,12 +37,13 @@ class FontCollection { public: static FontCollection& GetDefaultFontCollection(); + static FontCollection& GetFontCollection(std::string dir = ""); + std::shared_ptr GetMinikinFontCollectionForFamily( - const std::string& family, - const std::string& dir = ""); + const std::string& family); // Provides a set of all available family names. - std::set GetFamilyNames(const std::string& dir = ""); + std::set GetFamilyNames(); private: sk_sp skia_font_manager_; @@ -57,7 +58,7 @@ class FontCollection { return DEFAULT_FAMILY_NAME; }; - FontCollection(); + FontCollection(std::string dir = ""); ~FontCollection(); diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index fd4ed256c3a..8f45e9f6b6f 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -121,8 +121,8 @@ void Paragraph::AddRunsToLineBreaker(const std::string& rootdir) { for (size_t i = 0; i < runs_.size(); ++i) { auto run = runs_.GetRun(i); auto collection = - FontCollection::GetDefaultFontCollection() - .GetMinikinFontCollectionForFamily(run.style.font_family, rootdir); + FontCollection::GetFontCollection(rootdir) + .GetMinikinFontCollectionForFamily(run.style.font_family); GetFontAndMinikinPaint(run.style, &font, &paint); breaker_.addStyleRun(&paint, collection, font, run.start, run.end, false); } @@ -154,8 +154,8 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, for (size_t run_index = 0; run_index < runs_.size(); ++run_index) { auto run = runs_.GetRun(run_index); auto collection = - FontCollection::GetDefaultFontCollection() - .GetMinikinFontCollectionForFamily(run.style.font_family, rootdir); + FontCollection::GetFontCollection(rootdir) + .GetMinikinFontCollectionForFamily(run.style.font_family); GetFontAndMinikinPaint(run.style, &font, &minikin_paint); GetPaint(run.style, &paint); diff --git a/engine/src/flutter/tests/BUILD.gn b/engine/src/flutter/tests/BUILD.gn new file mode 100644 index 00000000000..98defad50b8 --- /dev/null +++ b/engine/src/flutter/tests/BUILD.gn @@ -0,0 +1,22 @@ +# Copyright 2017 Google, Inc. +# +# 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. + +group("tests") { + testonly = true + + deps = [ + "txt", + "unittest", + ] +} \ No newline at end of file diff --git a/engine/src/flutter/tests/txt/font_collection_unittests.cc b/engine/src/flutter/tests/txt/font_collection_unittests.cc index 4a069a3661e..f501649a1c2 100644 --- a/engine/src/flutter/tests/txt/font_collection_unittests.cc +++ b/engine/src/flutter/tests/txt/font_collection_unittests.cc @@ -25,33 +25,31 @@ namespace txt { TEST(FontCollection, HasDefaultRegistrations) { std::string defaultFamilyName = txt::FontCollection::GetDefaultFamilyName(); - auto collection = - txt::FontCollection::GetDefaultFontCollection() - .GetMinikinFontCollectionForFamily("", txt::GetFontDir()); - ASSERT_EQ( - defaultFamilyName, - txt::FontCollection::GetDefaultFontCollection().ProcessFamilyName("")); + auto collection = txt::FontCollection::GetFontCollection(txt::GetFontDir()) + .GetMinikinFontCollectionForFamily(""); + ASSERT_EQ(defaultFamilyName, + txt::FontCollection::GetFontCollection(txt::GetFontDir()) + .ProcessFamilyName("")); ASSERT_NE(defaultFamilyName, - txt::FontCollection::GetDefaultFontCollection().ProcessFamilyName( - "NotARealFont!")); + txt::FontCollection::GetFontCollection(txt::GetFontDir()) + .ProcessFamilyName("NotARealFont!")); ASSERT_EQ("NotARealFont!", - txt::FontCollection::GetDefaultFontCollection().ProcessFamilyName( - "NotARealFont!")); + txt::FontCollection::GetFontCollection(txt::GetFontDir()) + .ProcessFamilyName("NotARealFont!")); ASSERT_NE(collection.get(), nullptr); } TEST(FontCollection, GetMinikinFontCollections) { std::string defaultFamilyName = txt::FontCollection::GetDefaultFamilyName(); - auto collectionDef = - txt::FontCollection::GetDefaultFontCollection() - .GetMinikinFontCollectionForFamily("", txt::GetFontDir()); + auto collectionDef = txt::FontCollection::GetFontCollection(txt::GetFontDir()) + .GetMinikinFontCollectionForFamily(""); auto collectionRoboto = - txt::FontCollection::GetDefaultFontCollection() - .GetMinikinFontCollectionForFamily("Roboto", txt::GetFontDir()); - auto collectionHomemadeApple = txt::FontCollection::GetDefaultFontCollection() - .GetMinikinFontCollectionForFamily( - "Homemade Apple", txt::GetFontDir()); + txt::FontCollection::GetFontCollection(txt::GetFontDir()) + .GetMinikinFontCollectionForFamily("Roboto"); + auto collectionHomemadeApple = + txt::FontCollection::GetFontCollection(txt::GetFontDir()) + .GetMinikinFontCollectionForFamily("Homemade Apple"); for (size_t base = 0; base < 50; base++) { for (size_t variation = 0; variation < 50; variation++) { ASSERT_EQ(collectionDef->hasVariationSelector(base, variation), @@ -66,7 +64,8 @@ TEST(FontCollection, GetMinikinFontCollections) { TEST(FontCollection, GetFamilyNames) { std::set names = - txt::FontCollection::GetFamilyNames(txt::GetFontDir()); + txt::FontCollection::GetFontCollection(txt::GetFontDir()) + .GetFamilyNames(); ASSERT_EQ(names.size(), 19ull); From 1493b676ffdd5cd6731dfd7927b7591b24163306 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Thu, 15 Jun 2017 18:13:45 -0700 Subject: [PATCH 292/364] Add Getters for intrinsic widths and implement MaxInstrinsicWidth. Update tests. Change-Id: I210fac9d47f55f8317ca77bca64cfcfd438a246a --- engine/src/flutter/src/paragraph.cc | 13 +++++++++++++ engine/src/flutter/src/paragraph.h | 6 ++++++ engine/src/flutter/tests/txt/paragraph_unittests.cc | 5 ++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 8f45e9f6b6f..e548f9d10be 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -147,6 +147,10 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, SkTextBlobBuilder builder; + // Reset member variables so Layout still works when called more than once + max_intrinsic_width_ = 0.0f; + lines_ = 0; + minikin::Layout layout; SkScalar x = x_offset; y_ = y_offset; @@ -187,6 +191,7 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, buffer.pos[pos_index + 1] = layout.getY(glyph_index); } blob_start += blob_length; + max_intrinsic_width_ += layout.getX(blob_start - 1); } // TODO(abarth): We could keep the same SkTextBlobBuilder as long as the @@ -222,6 +227,14 @@ double Paragraph::GetIdeographicBaseline() const { return FLT_MAX; } +double Paragraph::GetMaxIntrinsicWidth() const { + return max_intrinsic_width_; +} + +double Paragraph::GetMinIntrinsicWidth() const { + return min_intrinsic_width_; +} + double Paragraph::GetHeight() const { return paragraph_style_.font_size * paragraph_style_.line_height * paragraph_style_.max_lines; diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 513d1fb57fb..ca05810209e 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -53,6 +53,10 @@ class Paragraph { double GetIdeographicBaseline() const; + double GetMaxIntrinsicWidth() const; + + double GetMinIntrinsicWidth() const; + bool DidExceedMaxLines() const; private: @@ -73,6 +77,8 @@ class Paragraph { SkScalar y_ = 0.0f; // Height of the paragraph after Layout(). double width_ = 0.0f; int lines_ = 0; + double max_intrinsic_width_ = 0.0f; + double min_intrinsic_width_ = FLT_MAX; void SetText(std::vector text, StyledRuns runs); diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index e3901f02f0b..88071b13bd8 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -110,7 +110,9 @@ TEST_F(RenderTest, RainbowParagraph) { auto icu_text4 = icu::UnicodeString::fromUTF8(text4); std::u16string u16_text4(icu_text4.getBuffer(), icu_text4.getBuffer() + icu_text4.length()); - const char* text5 = "ContinueLastStyle"; + const char* text5 = + "Continue Last Style With lots of words to check if it overlaps properly " + "or not"; auto icu_text5 = icu::UnicodeString::fromUTF8(text5); std::u16string u16_text5(icu_text5.getBuffer(), icu_text5.getBuffer() + icu_text5.length()); @@ -284,6 +286,7 @@ TEST_F(RenderTest, LinebreakParagraph) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; + paragraph_style.max_lines = 1000; txt::ParagraphBuilder builder(paragraph_style); txt::TextStyle text_style; From 6baa479ed08e93fb4f0cf916ca6068575719fe1c Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Fri, 16 Jun 2017 16:32:50 -0700 Subject: [PATCH 293/364] Respect letter spacing and word spacing. Remove ParagraphConstraint. Change-Id: Ie833eab67b50be40b7ea38f9c82577cb46e0e1a7 --- engine/src/flutter/BUILD.gn | 2 - engine/src/flutter/examples/main.cc | 2 +- engine/src/flutter/src/paragraph.cc | 46 +++++++++++++++---- engine/src/flutter/src/paragraph.h | 9 ++-- .../src/flutter/src/paragraph_constraints.cc | 23 ---------- .../src/flutter/src/paragraph_constraints.h | 38 --------------- .../flutter/tests/txt/paragraph_unittests.cc | 27 ++++------- 7 files changed, 52 insertions(+), 95 deletions(-) delete mode 100644 engine/src/flutter/src/paragraph_constraints.cc delete mode 100644 engine/src/flutter/src/paragraph_constraints.h diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index d5e1d7596e9..b47c5a20c88 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -38,8 +38,6 @@ static_library("txt") { "src/paragraph.h", "src/paragraph_builder.cc", "src/paragraph_builder.h", - "src/paragraph_constraints.cc", - "src/paragraph_constraints.h", "src/paragraph_style.cc", "src/paragraph_style.h", "src/styled_runs.cc", diff --git a/engine/src/flutter/examples/main.cc b/engine/src/flutter/examples/main.cc index 3137207c38a..a4b52da6cb9 100644 --- a/engine/src/flutter/examples/main.cc +++ b/engine/src/flutter/examples/main.cc @@ -52,7 +52,7 @@ int runTest() { int width = 800; int height = 600; - paragraph->Layout(ParagraphConstraints(width)); + paragraph->Layout(width); SkAutoGraphics ag; SkBitmap bitmap; diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index e548f9d10be..26e8c3b96a2 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -128,12 +128,12 @@ void Paragraph::AddRunsToLineBreaker(const std::string& rootdir) { } } -void Paragraph::Layout(const ParagraphConstraints& constraints, +void Paragraph::Layout(double width, const std::string& rootdir, const double x_offset, const double y_offset) { - breaker_.setLineWidths(0.0f, 0, constraints.width()); - width_ = constraints.width(); + breaker_.setLineWidths(0.0f, 0, width); + width_ = width; AddRunsToLineBreaker(rootdir); size_t breaks_count = breaker_.computeBreaks(); const int* breaks = breaker_.getBreaks(); @@ -149,12 +149,14 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, // Reset member variables so Layout still works when called more than once max_intrinsic_width_ = 0.0f; - lines_ = 0; + lines_ = 1; minikin::Layout layout; SkScalar x = x_offset; y_ = y_offset; size_t break_index = 0; + double letter_spacing_offset = 0.0f; + double word_spacing_offset = 0.0f; for (size_t run_index = 0; run_index < runs_.size(); ++run_index) { auto run = runs_.GetRun(run_index); auto collection = @@ -163,8 +165,13 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, GetFontAndMinikinPaint(run.style, &font, &minikin_paint); GetPaint(run.style, &paint); + // Subtract inital offset to avoid big gap at start of run. + letter_spacing_offset -= run.style.letter_spacing; + size_t layout_start = run.start; - while (layout_start < run.end && !DidExceedMaxLines()) { + + while (layout_start < run.end && + GetLineCount() <= paragraph_style_.max_lines) { const size_t next_break = (break_index > breaks_count - 1) ? std::numeric_limits::max() : breaks[break_index]; @@ -187,11 +194,20 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, const size_t glyph_index = blob_start + blob_index; buffer.glyphs[blob_index] = layout.getGlyphId(glyph_index); const size_t pos_index = 2 * blob_index; - buffer.pos[pos_index] = layout.getX(glyph_index); + letter_spacing_offset += run.style.letter_spacing; + buffer.pos[pos_index] = layout.getX(glyph_index) + + letter_spacing_offset + word_spacing_offset; buffer.pos[pos_index + 1] = layout.getY(glyph_index); } blob_start += blob_length; - max_intrinsic_width_ += layout.getX(blob_start - 1); + + // Subtract letter offset to avoid big gap at end of run. + letter_spacing_offset -= run.style.letter_spacing; + + word_spacing_offset += run.style.word_spacing; + + max_intrinsic_width_ += + layout.getX(blob_start - 1) + letter_spacing_offset; } // TODO(abarth): We could keep the same SkTextBlobBuilder as long as the @@ -201,11 +217,15 @@ void Paragraph::Layout(const ParagraphConstraints& constraints, if (layout_end == next_break) { x = 0.0f; + letter_spacing_offset = 0.0f; + word_spacing_offset = 0.0f; // TODO(abarth): Use the line height, which is something like the max // font_size for runs in this line times the paragraph's line height. y_ += run.style.font_size * run.style.height; break_index += 1; lines_++; + if (lines_ > paragraph_style_.max_lines) + lines_--; } else { x += layout.getAdvance(); } @@ -220,10 +240,12 @@ const ParagraphStyle& Paragraph::GetParagraphStyle() const { } double Paragraph::GetAlphabeticBaseline() const { + // TODO(garyq): Implement. return FLT_MAX; } double Paragraph::GetIdeographicBaseline() const { + // TODO(garyq): Implement. return FLT_MAX; } @@ -232,6 +254,7 @@ double Paragraph::GetMaxIntrinsicWidth() const { } double Paragraph::GetMinIntrinsicWidth() const { + // TODO(garyq): Implement. return min_intrinsic_width_; } @@ -253,10 +276,13 @@ void Paragraph::Paint(SkCanvas* canvas, double x, double y) { } } +int Paragraph::GetLineCount() const { + // FTL_LOG(INFO) << "Lines: " << lines_; + return lines_; +} + bool Paragraph::DidExceedMaxLines() const { - if (y_ / (paragraph_style_.font_size * paragraph_style_.line_height) > - paragraph_style_.max_lines) - // if (lines_ > paragraph_style_.max_lines) + if (GetLineCount() > paragraph_style_.max_lines) return true; return false; } diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index ca05810209e..4ef74e3fcab 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -21,7 +21,6 @@ #include "lib/ftl/macros.h" #include "lib/txt/src/paint_record.h" -#include "lib/txt/src/paragraph_constraints.h" #include "lib/txt/src/paragraph_style.h" #include "lib/txt/src/styled_runs.h" #include "minikin/LineBreaker.h" @@ -38,7 +37,7 @@ class Paragraph { ~Paragraph(); - void Layout(const ParagraphConstraints& constraints, + void Layout(double width, const std::string& rootdir = "", const double x_offset = 0.0, const double y_offset = 0.0); @@ -57,6 +56,8 @@ class Paragraph { double GetMinIntrinsicWidth() const; + int GetLineCount() const; + bool DidExceedMaxLines() const; private: @@ -76,9 +77,9 @@ class Paragraph { ParagraphStyle paragraph_style_; SkScalar y_ = 0.0f; // Height of the paragraph after Layout(). double width_ = 0.0f; - int lines_ = 0; + int lines_ = 1; double max_intrinsic_width_ = 0.0f; - double min_intrinsic_width_ = FLT_MAX; + double min_intrinsic_width_ = 0; void SetText(std::vector text, StyledRuns runs); diff --git a/engine/src/flutter/src/paragraph_constraints.cc b/engine/src/flutter/src/paragraph_constraints.cc deleted file mode 100644 index 26a85e04637..00000000000 --- a/engine/src/flutter/src/paragraph_constraints.cc +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright 2017 Google, Inc. - * - * 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 "lib/txt/src/paragraph_constraints.h" - -namespace txt { - -ParagraphConstraints::ParagraphConstraints(double width) : width_(width) {} - -} // namespace txt diff --git a/engine/src/flutter/src/paragraph_constraints.h b/engine/src/flutter/src/paragraph_constraints.h deleted file mode 100644 index e6664515270..00000000000 --- a/engine/src/flutter/src/paragraph_constraints.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2017 Google, Inc. - * - * 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 LIB_TXT_SRC_PARAGRAPH_CONSTRAINTS_H_ -#define LIB_TXT_SRC_PARAGRAPH_CONSTRAINTS_H_ - -#include "lib/ftl/macros.h" - -namespace txt { - -class ParagraphConstraints { - public: - explicit ParagraphConstraints(double width); - - double width() const { return width_; } - - private: - double width_; - - FTL_DISALLOW_COPY_AND_ASSIGN(ParagraphConstraints); -}; - -} // namespace txt - -#endif // LIB_TXT_SRC_PARAGRAPH_CONSTRAINTS_H_ diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 88071b13bd8..64c38a98a07 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -43,8 +43,7 @@ TEST_F(RenderTest, SimpleParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, - txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); paragraph->Paint(GetCanvas(), 10.0, 15.0); @@ -77,8 +76,7 @@ TEST_F(RenderTest, SimpleRedParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, - txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); paragraph->Paint(GetCanvas(), 10.0, 15.0); @@ -98,7 +96,7 @@ TEST_F(RenderTest, RainbowParagraph) { auto icu_text1 = icu::UnicodeString::fromUTF8(text1); std::u16string u16_text1(icu_text1.getBuffer(), icu_text1.getBuffer() + icu_text1.length()); - const char* text2 = "BigGreenDefault "; + const char* text2 = "Big Green Default "; auto icu_text2 = icu::UnicodeString::fromUTF8(text2); std::u16string u16_text2(icu_text2.getBuffer(), icu_text2.getBuffer() + icu_text2.length()); @@ -129,8 +127,8 @@ TEST_F(RenderTest, RainbowParagraph) { txt::TextStyle text_style2; text_style2.font_size = 50; - // Letter spacing not yet implemented - text_style2.letter_spacing = 100; + text_style2.letter_spacing = 10; + text_style2.word_spacing = 30; text_style2.font_weight = txt::FontWeight::w600; text_style2.fake_bold = true; text_style2.color = SK_ColorGREEN; @@ -159,8 +157,7 @@ TEST_F(RenderTest, RainbowParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, - txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); paragraph->Paint(GetCanvas(), 10.0, 50.0); @@ -199,8 +196,7 @@ TEST_F(RenderTest, DefaultStyleParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, - txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); paragraph->Paint(GetCanvas(), 10.0, 15.0); @@ -236,8 +232,7 @@ TEST_F(RenderTest, BoldParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, - txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); paragraph->Paint(GetCanvas(), 10.0, 60.0); @@ -302,8 +297,7 @@ TEST_F(RenderTest, LinebreakParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, - txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); paragraph->Paint(GetCanvas(), 5.0, 30.0); @@ -338,8 +332,7 @@ TEST_F(RenderTest, ItalicsParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(txt::ParagraphConstraints{GetTestCanvasWidth()}, - txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); paragraph->Paint(GetCanvas(), 10.0, 35.0); From 23cc989a3598add72f9f2fe2ee43a434608554d6 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Mon, 19 Jun 2017 11:26:12 -0700 Subject: [PATCH 294/364] Add preliminary support for letter-spacing and word-spacing Change-Id: If3f64cf0c18ff0aa087091626532bcd983f6b54c --- engine/src/flutter/src/paragraph.cc | 20 +++++++++---------- .../flutter/tests/txt/paragraph_unittests.cc | 20 +++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 26e8c3b96a2..117e20c05a3 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -149,7 +149,7 @@ void Paragraph::Layout(double width, // Reset member variables so Layout still works when called more than once max_intrinsic_width_ = 0.0f; - lines_ = 1; + lines_ = 0; minikin::Layout layout; SkScalar x = x_offset; @@ -170,8 +170,7 @@ void Paragraph::Layout(double width, size_t layout_start = run.start; - while (layout_start < run.end && - GetLineCount() <= paragraph_style_.max_lines) { + while (layout_start < run.end && lines_ < paragraph_style_.max_lines) { const size_t next_break = (break_index > breaks_count - 1) ? std::numeric_limits::max() : breaks[break_index]; @@ -194,14 +193,15 @@ void Paragraph::Layout(double width, const size_t glyph_index = blob_start + blob_index; buffer.glyphs[blob_index] = layout.getGlyphId(glyph_index); const size_t pos_index = 2 * blob_index; - letter_spacing_offset += run.style.letter_spacing; buffer.pos[pos_index] = layout.getX(glyph_index) + letter_spacing_offset + word_spacing_offset; + letter_spacing_offset += run.style.letter_spacing; buffer.pos[pos_index + 1] = layout.getY(glyph_index); } blob_start += blob_length; - // Subtract letter offset to avoid big gap at end of run. + // Subtract letter offset to avoid big gap at end of run. This my be + // removed depending on the specificatins for letter spacing. letter_spacing_offset -= run.style.letter_spacing; word_spacing_offset += run.style.word_spacing; @@ -210,6 +210,10 @@ void Paragraph::Layout(double width, layout.getX(blob_start - 1) + letter_spacing_offset; } + // Subtract word offset to avoid big gap at end of run. This my be + // removed depending on the specificatins for word spacing. + word_spacing_offset -= run.style.word_spacing; + // TODO(abarth): We could keep the same SkTextBlobBuilder as long as the // color stayed the same. records_.push_back( @@ -224,8 +228,6 @@ void Paragraph::Layout(double width, y_ += run.style.font_size * run.style.height; break_index += 1; lines_++; - if (lines_ > paragraph_style_.max_lines) - lines_--; } else { x += layout.getAdvance(); } @@ -259,8 +261,7 @@ double Paragraph::GetMinIntrinsicWidth() const { } double Paragraph::GetHeight() const { - return paragraph_style_.font_size * paragraph_style_.line_height * - paragraph_style_.max_lines; + return y_; } void Paragraph::SetParagraphStyle(const ParagraphStyle& style) { @@ -277,7 +278,6 @@ void Paragraph::Paint(SkCanvas* canvas, double x, double y) { } int Paragraph::GetLineCount() const { - // FTL_LOG(INFO) << "Lines: " << lines_; return lines_; } diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 64c38a98a07..86988e8a2d5 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -92,25 +92,25 @@ TEST_F(RenderTest, SimpleRedParagraph) { } TEST_F(RenderTest, RainbowParagraph) { - const char* text1 = "RedRoboto "; + const char* text1 = "Red Roboto"; auto icu_text1 = icu::UnicodeString::fromUTF8(text1); std::u16string u16_text1(icu_text1.getBuffer(), icu_text1.getBuffer() + icu_text1.length()); - const char* text2 = "Big Green Default "; + const char* text2 = "Big Green Default"; auto icu_text2 = icu::UnicodeString::fromUTF8(text2); std::u16string u16_text2(icu_text2.getBuffer(), icu_text2.getBuffer() + icu_text2.length()); - const char* text3 = "DefcolorHomemadeApple "; + const char* text3 = "Defcolor Homemade Apple"; auto icu_text3 = icu::UnicodeString::fromUTF8(text3); std::u16string u16_text3(icu_text3.getBuffer(), icu_text3.getBuffer() + icu_text3.length()); - const char* text4 = "SmallBlueRoboto "; + const char* text4 = "Small Blue Roboto"; auto icu_text4 = icu::UnicodeString::fromUTF8(text4); std::u16string u16_text4(icu_text4.getBuffer(), icu_text4.getBuffer() + icu_text4.length()); const char* text5 = - "Continue Last Style With lots of words to check if it overlaps properly " - "or not"; + "Continue Last Style With lots of words to check if it overlaps " + "properly or not"; auto icu_text5 = icu::UnicodeString::fromUTF8(text5); std::u16string u16_text5(icu_text5.getBuffer(), icu_text5.getBuffer() + icu_text5.length()); @@ -281,13 +281,13 @@ TEST_F(RenderTest, LinebreakParagraph) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - paragraph_style.max_lines = 1000; + paragraph_style.max_lines = 14; txt::ParagraphBuilder builder(paragraph_style); txt::TextStyle text_style; text_style.font_size = 26; // Letter spacing not yet implemented - text_style.letter_spacing = 10; + text_style.letter_spacing = 0; text_style.color = SK_ColorBLACK; text_style.height = 1.15; builder.PushStyle(text_style); @@ -297,9 +297,9 @@ TEST_F(RenderTest, LinebreakParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth() - 100, txt::GetFontDir()); - paragraph->Paint(GetCanvas(), 5.0, 30.0); + paragraph->Paint(GetCanvas(), 0, 30.0); ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); for (size_t i = 0; i < u16_text.length(); i++) { From 197827c35cb160546e793442f336e320edac2fdd Mon Sep 17 00:00:00 2001 From: Ankur Mittal Date: Mon, 19 Jun 2017 15:39:58 -0700 Subject: [PATCH 295/364] Remove deps on gtest from static lib rule Change-Id: Iae0c4370ad0c7c3194209b7784797e81ee5f6825 --- engine/src/flutter/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index b47c5a20c88..11ff6440bd4 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -54,7 +54,6 @@ static_library("txt") { deps = [ "//lib/txt/libs/minikin", - "//third_party/gtest", "//third_party/skia", ] } From 3f5ae2f4a39d0acbe5e5c44d3267d31781403573 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Tue, 20 Jun 2017 16:22:44 -0700 Subject: [PATCH 296/364] Add support for underline, overline, and strikethrough. Change-Id: Id98ecb8409be69d9de44dc931ed6143163469c27 --- engine/src/flutter/src/paint_record.cc | 15 +++- engine/src/flutter/src/paint_record.h | 16 +++- engine/src/flutter/src/paragraph.cc | 85 ++++++++++++++++--- engine/src/flutter/src/paragraph.h | 15 +++- .../flutter/tests/txt/paragraph_unittests.cc | 9 +- 5 files changed, 116 insertions(+), 24 deletions(-) diff --git a/engine/src/flutter/src/paint_record.cc b/engine/src/flutter/src/paint_record.cc index 226b803d42f..8740ee8ea41 100644 --- a/engine/src/flutter/src/paint_record.cc +++ b/engine/src/flutter/src/paint_record.cc @@ -15,26 +15,33 @@ */ #include "lib/txt/src/paint_record.h" +#include "lib/ftl/logging.h" namespace txt { -PaintRecord::PaintRecord() = default; - PaintRecord::~PaintRecord() = default; -PaintRecord::PaintRecord(SkColor color, SkPoint offset, sk_sp text) - : color_(color), offset_(offset), text_(std::move(text)) {} +PaintRecord::PaintRecord(SkColor color, + SkPoint offset, + sk_sp text, + SkPaint::FontMetrics metrics) + : color_(color), + offset_(offset), + text_(std::move(text)), + metrics_(metrics) {} PaintRecord::PaintRecord(PaintRecord&& other) { color_ = other.color_; offset_ = other.offset_; text_ = std::move(other.text_); + metrics_ = other.metrics_; } PaintRecord& PaintRecord::operator=(PaintRecord&& other) { color_ = other.color_; offset_ = other.offset_; text_ = std::move(other.text_); + metrics_ = other.metrics_; return *this; } diff --git a/engine/src/flutter/src/paint_record.h b/engine/src/flutter/src/paint_record.h index 04d6f300d6b..f758b68729a 100644 --- a/engine/src/flutter/src/paint_record.h +++ b/engine/src/flutter/src/paint_record.h @@ -17,20 +17,23 @@ #ifndef LIB_TXT_SRC_PAINT_RECORD_H_ #define LIB_TXT_SRC_PAINT_RECORD_H_ +#include "lib/ftl/logging.h" #include "lib/ftl/macros.h" +#include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkTextBlob.h" namespace txt { class PaintRecord { public: - PaintRecord(); + PaintRecord() = delete; ~PaintRecord(); - PaintRecord(SkColor color, SkPoint offset, sk_sp text); - - PaintRecord(const PaintRecord& other) = delete; + PaintRecord(SkColor color, + SkPoint offset, + sk_sp text, + SkPaint::FontMetrics metrics); PaintRecord(PaintRecord&& other); @@ -42,10 +45,15 @@ class PaintRecord { SkTextBlob* text() const { return text_.get(); } + const SkPaint::FontMetrics& metrics() const { return metrics_; } + private: SkColor color_; SkPoint offset_; sk_sp text_; + SkPaint::FontMetrics metrics_; + + FTL_DISALLOW_COPY_AND_ASSIGN(PaintRecord); }; } // namespace txt diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 117e20c05a3..220e7c260a8 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -18,16 +18,15 @@ #include #include +#include #include #include #include -#include "minikin/LineBreaker.h" - #include "lib/ftl/logging.h" - #include "lib/txt/src/font_collection.h" #include "lib/txt/src/font_skia.h" +#include "minikin/LineBreaker.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkTextBlob.h" @@ -42,6 +41,7 @@ const sk_sp& GetTypefaceForGlyph(const minikin::Layout& layout, return font->GetSkTypeface(); } +// Return the number of glyphs until the typeface changes. size_t GetBlobLength(const minikin::Layout& layout, size_t blob_start) { const size_t glyph_count = layout.nGlyphs(); const sk_sp& typeface = GetTypefaceForGlyph(layout, blob_start); @@ -52,8 +52,8 @@ size_t GetBlobLength(const minikin::Layout& layout, size_t blob_start) { return glyph_count - blob_start; } -int GetWeight(const TextStyle& style) { - switch (style.font_weight) { +int GetWeight(const FontWeight weight) { + switch (weight) { case FontWeight::w100: return 1; case FontWeight::w200: @@ -75,6 +75,10 @@ int GetWeight(const TextStyle& style) { } } +int GetWeight(const TextStyle& style) { + return GetWeight(style.font_weight); +} + bool GetItalic(const TextStyle& style) { switch (style.font_style) { case FontStyle::normal: @@ -157,6 +161,8 @@ void Paragraph::Layout(double width, size_t break_index = 0; double letter_spacing_offset = 0.0f; double word_spacing_offset = 0.0f; + double max_line_spacing = 0.0f; + for (size_t run_index = 0; run_index < runs_.size(); ++run_index) { auto run = runs_.GetRun(run_index); auto collection = @@ -170,6 +176,7 @@ void Paragraph::Layout(double width, size_t layout_start = run.start; + // Layout until the end of the run or too many lines. while (layout_start < run.end && lines_ < paragraph_style_.max_lines) { const size_t next_break = (break_index > breaks_count - 1) ? std::numeric_limits::max() @@ -182,6 +189,7 @@ void Paragraph::Layout(double width, const size_t glyph_count = layout.nGlyphs(); size_t blob_start = 0; + // Each word/blob. while (blob_start < glyph_count) { const size_t blob_length = GetBlobLength(layout, blob_start); // TODO(abarth): Precompute when we can use allocRunPosH. @@ -189,6 +197,9 @@ void Paragraph::Layout(double width, auto buffer = builder.allocRunPos(paint, blob_length); + letter_spacing_offset += run.style.letter_spacing; + + // Each Glyph/Letter. for (size_t blob_index = 0; blob_index < blob_length; ++blob_index) { const size_t glyph_index = blob_start + blob_index; buffer.glyphs[blob_index] = layout.getGlyphId(glyph_index); @@ -201,8 +212,8 @@ void Paragraph::Layout(double width, blob_start += blob_length; // Subtract letter offset to avoid big gap at end of run. This my be - // removed depending on the specificatins for letter spacing. - letter_spacing_offset -= run.style.letter_spacing; + // removed depending on the specifications for letter spacing. + // letter_spacing_offset -= run.style.letter_spacing; word_spacing_offset += run.style.word_spacing; @@ -213,19 +224,29 @@ void Paragraph::Layout(double width, // Subtract word offset to avoid big gap at end of run. This my be // removed depending on the specificatins for word spacing. word_spacing_offset -= run.style.word_spacing; - // TODO(abarth): We could keep the same SkTextBlobBuilder as long as the // color stayed the same. - records_.push_back( - PaintRecord(run.style.color, SkPoint::Make(x, y_), builder.make())); + // TODO(garyq): Ensure that the typeface does not change throughout a + // run. + SkPaint::FontMetrics metrics; + paint.getFontMetrics(&metrics); + records_.push_back(PaintRecord{run.style.color, SkPoint::Make(x, y_), + builder.make(), metrics}); + decorations_.push_back( + std::make_tuple(run.style.decoration, run.style.decoration_color, + run.style.decoration_style, run.style.font_weight)); + if (max_line_spacing < -metrics.fAscent * run.style.height) + max_line_spacing = -metrics.fAscent * run.style.height; if (layout_end == next_break) { + y_ += max_line_spacing; + + max_line_spacing = 0.0f; x = 0.0f; letter_spacing_offset = 0.0f; word_spacing_offset = 0.0f; // TODO(abarth): Use the line height, which is something like the max // font_size for runs in this line times the paragraph's line height. - y_ += run.style.font_size * run.style.height; break_index += 1; lines_++; } else { @@ -269,11 +290,49 @@ void Paragraph::SetParagraphStyle(const ParagraphStyle& style) { } void Paragraph::Paint(SkCanvas* canvas, double x, double y) { - SkPaint paint; + int i = 0; for (const auto& record : records_) { + SkPaint paint; paint.setColor(record.color()); const SkPoint& offset = record.offset(); canvas->drawTextBlob(record.text(), x + offset.x(), y + offset.y(), paint); + PaintDecorations(canvas, x + offset.x(), y + offset.y(), decorations_[i], + record.metrics(), record.text()); + i++; + } +} + +void Paragraph::PaintDecorations( + SkCanvas* canvas, + double x, + double y, + std::tuple + decoration, + SkPaint::FontMetrics metrics, + SkTextBlob* blob) { + if (std::get<0>(decoration) != TextDecoration::kNone) { + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + paint.setColor(std::get<1>(decoration)); + paint.setAntiAlias(true); + + double width = blob->bounds().fRight + blob->bounds().fLeft; + + if (std::get<0>(decoration) & 0x1) { + paint.setStrokeWidth(metrics.fUnderlineThickness); + canvas->drawLine(x, y + metrics.fUnderlineThickness, x + width, + y + metrics.fUnderlineThickness, paint); + } + if (std::get<0>(decoration) & 0x2) { + paint.setStrokeWidth(metrics.fUnderlineThickness); + canvas->drawLine(x, y + metrics.fAscent, x + width, y + metrics.fAscent, + paint); + } + if (std::get<0>(decoration) & 0x4) { + paint.setStrokeWidth(metrics.fUnderlineThickness); + canvas->drawLine(x, y - metrics.fCapHeight / 2.5, x + width, + y - metrics.fCapHeight / 2.5, paint); + } } } @@ -282,7 +341,7 @@ int Paragraph::GetLineCount() const { } bool Paragraph::DidExceedMaxLines() const { - if (GetLineCount() > paragraph_style_.max_lines) + if (lines_ > paragraph_style_.max_lines) return true; return false; } diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 4ef74e3fcab..5a1e861afdc 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -17,6 +17,7 @@ #ifndef LIB_TXT_SRC_PARAGRAPH_H_ #define LIB_TXT_SRC_PARAGRAPH_H_ +#include #include #include "lib/ftl/macros.h" @@ -74,12 +75,15 @@ class Paragraph { StyledRuns runs_; minikin::LineBreaker breaker_; std::vector records_; + std::vector< + std::tuple> + decorations_; ParagraphStyle paragraph_style_; SkScalar y_ = 0.0f; // Height of the paragraph after Layout(). double width_ = 0.0f; int lines_ = 1; double max_intrinsic_width_ = 0.0f; - double min_intrinsic_width_ = 0; + double min_intrinsic_width_ = 0.0f; void SetText(std::vector text, StyledRuns runs); @@ -87,6 +91,15 @@ class Paragraph { void AddRunsToLineBreaker(const std::string& rootdir = ""); + void PaintDecorations( + SkCanvas* canvas, + double x, + double y, + std::tuple + decoration, + SkPaint::FontMetrics metrics, + SkTextBlob* blob); + FTL_DISALLOW_COPY_AND_ASSIGN(Paragraph); }; diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 86988e8a2d5..7f01eb45c7c 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -96,7 +96,7 @@ TEST_F(RenderTest, RainbowParagraph) { auto icu_text1 = icu::UnicodeString::fromUTF8(text1); std::u16string u16_text1(icu_text1.getBuffer(), icu_text1.getBuffer() + icu_text1.length()); - const char* text2 = "Big Green Default"; + const char* text2 = "big Greeen Default"; auto icu_text2 = icu::UnicodeString::fromUTF8(text2); std::u16string u16_text2(icu_text2.getBuffer(), icu_text2.getBuffer() + icu_text2.length()); @@ -116,6 +116,7 @@ TEST_F(RenderTest, RainbowParagraph) { icu_text5.getBuffer() + icu_text5.length()); txt::ParagraphStyle paragraph_style; + paragraph_style.max_lines = 2; txt::ParagraphBuilder builder(paragraph_style); txt::TextStyle text_style1; @@ -132,6 +133,8 @@ TEST_F(RenderTest, RainbowParagraph) { text_style2.font_weight = txt::FontWeight::w600; text_style2.fake_bold = true; text_style2.color = SK_ColorGREEN; + text_style2.decoration = txt::TextDecoration(0x1 | 0x2 | 0x4); + text_style2.decoration_color = SK_ColorBLACK; builder.PushStyle(text_style2); builder.AddText(u16_text2); @@ -165,6 +168,7 @@ TEST_F(RenderTest, RainbowParagraph) { for (size_t i = 0; i < u16_text1.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text1[i]); } + ASSERT_TRUE(Snapshot()); ASSERT_EQ(paragraph->runs_.runs_.size(), 4ull); ASSERT_EQ(paragraph->runs_.styles_.size(), 4ull); ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style1)); @@ -175,7 +179,6 @@ TEST_F(RenderTest, RainbowParagraph) { ASSERT_EQ(paragraph->records_[1].color(), text_style2.color); ASSERT_EQ(paragraph->records_[2].color(), text_style3.color); ASSERT_EQ(paragraph->records_[3].color(), text_style4.color); - ASSERT_TRUE(Snapshot()); } // Currently, this should render nothing without a supplied TextStyle. @@ -290,6 +293,8 @@ TEST_F(RenderTest, LinebreakParagraph) { text_style.letter_spacing = 0; text_style.color = SK_ColorBLACK; text_style.height = 1.15; + text_style.decoration = txt::TextDecoration(0x1); + text_style.decoration_color = SK_ColorBLACK; builder.PushStyle(text_style); builder.AddText(u16_text); From b4c8d2c134234afc0eeb2f5b4975ac83b456efbc Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Tue, 20 Jun 2017 18:28:09 -0700 Subject: [PATCH 297/364] Add support for Decoration Styles, remove usage of separate decoration records. Change-Id: I8fe929b0814b22e37e1517a7ddafb70a1c6b3d37 --- engine/src/flutter/src/paint_record.cc | 4 + engine/src/flutter/src/paint_record.h | 5 ++ engine/src/flutter/src/paragraph.cc | 103 ++++++++++++++++------- engine/src/flutter/src/paragraph.h | 17 ++-- engine/src/flutter/src/text_decoration.h | 10 +-- 5 files changed, 89 insertions(+), 50 deletions(-) diff --git a/engine/src/flutter/src/paint_record.cc b/engine/src/flutter/src/paint_record.cc index 8740ee8ea41..f8d13dbc259 100644 --- a/engine/src/flutter/src/paint_record.cc +++ b/engine/src/flutter/src/paint_record.cc @@ -22,16 +22,19 @@ namespace txt { PaintRecord::~PaintRecord() = default; PaintRecord::PaintRecord(SkColor color, + TextStyle style, SkPoint offset, sk_sp text, SkPaint::FontMetrics metrics) : color_(color), + style_(style), offset_(offset), text_(std::move(text)), metrics_(metrics) {} PaintRecord::PaintRecord(PaintRecord&& other) { color_ = other.color_; + style_ = other.style_; offset_ = other.offset_; text_ = std::move(other.text_); metrics_ = other.metrics_; @@ -39,6 +42,7 @@ PaintRecord::PaintRecord(PaintRecord&& other) { PaintRecord& PaintRecord::operator=(PaintRecord&& other) { color_ = other.color_; + style_ = other.style_; offset_ = other.offset_; text_ = std::move(other.text_); metrics_ = other.metrics_; diff --git a/engine/src/flutter/src/paint_record.h b/engine/src/flutter/src/paint_record.h index f758b68729a..d0c18fc05d0 100644 --- a/engine/src/flutter/src/paint_record.h +++ b/engine/src/flutter/src/paint_record.h @@ -19,6 +19,7 @@ #include "lib/ftl/logging.h" #include "lib/ftl/macros.h" +#include "lib/txt/src/text_style.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkTextBlob.h" @@ -31,6 +32,7 @@ class PaintRecord { ~PaintRecord(); PaintRecord(SkColor color, + TextStyle style, SkPoint offset, sk_sp text, SkPaint::FontMetrics metrics); @@ -47,8 +49,11 @@ class PaintRecord { const SkPaint::FontMetrics& metrics() const { return metrics_; } + const TextStyle& style() const { return style_; } + private: SkColor color_; + TextStyle style_; SkPoint offset_; sk_sp text_; SkPaint::FontMetrics metrics_; diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 220e7c260a8..48fcc8a56f2 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -31,6 +31,8 @@ #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkTextBlob.h" #include "third_party/skia/include/core/SkTypeface.h" +#include "third_party/skia/include/effects/SkDashPathEffect.h" +#include "third_party/skia/include/effects/SkDiscretePathEffect.h" namespace txt { namespace { @@ -230,11 +232,9 @@ void Paragraph::Layout(double width, // run. SkPaint::FontMetrics metrics; paint.getFontMetrics(&metrics); - records_.push_back(PaintRecord{run.style.color, SkPoint::Make(x, y_), - builder.make(), metrics}); - decorations_.push_back( - std::make_tuple(run.style.decoration, run.style.decoration_color, - run.style.decoration_style, run.style.font_weight)); + records_.push_back(PaintRecord{run.style.color, run.style, + SkPoint::Make(x, y_), builder.make(), + metrics}); if (max_line_spacing < -metrics.fAscent * run.style.height) max_line_spacing = -metrics.fAscent * run.style.height; @@ -290,48 +290,87 @@ void Paragraph::SetParagraphStyle(const ParagraphStyle& style) { } void Paragraph::Paint(SkCanvas* canvas, double x, double y) { - int i = 0; for (const auto& record : records_) { SkPaint paint; paint.setColor(record.color()); const SkPoint& offset = record.offset(); canvas->drawTextBlob(record.text(), x + offset.x(), y + offset.y(), paint); - PaintDecorations(canvas, x + offset.x(), y + offset.y(), decorations_[i], + PaintDecorations(canvas, x + offset.x(), y + offset.y(), record.style(), record.metrics(), record.text()); - i++; } } -void Paragraph::PaintDecorations( - SkCanvas* canvas, - double x, - double y, - std::tuple - decoration, - SkPaint::FontMetrics metrics, - SkTextBlob* blob) { - if (std::get<0>(decoration) != TextDecoration::kNone) { +void Paragraph::PaintDecorations(SkCanvas* canvas, + double x, + double y, + TextStyle style, + SkPaint::FontMetrics metrics, + SkTextBlob* blob) { + if (style.decoration != TextDecoration::kNone) { SkPaint paint; paint.setStyle(SkPaint::kStroke_Style); - paint.setColor(std::get<1>(decoration)); + paint.setColor(style.decoration_color); paint.setAntiAlias(true); + // This is set to 2 for the double line style + int decoration_count = 1; + + switch (style.decoration_style) { + case TextDecorationStyle::kSolid: + break; + case TextDecorationStyle::kDouble: { + decoration_count = 2; + break; + } + case TextDecorationStyle::kDotted: { + const SkScalar intervals[] = {3.0f, 5.0f, 3.0f, 5.0f}; + size_t count = sizeof(intervals) / sizeof(intervals[0]); + paint.setPathEffect(SkPathEffect::MakeCompose( + SkDashPathEffect::Make(intervals, count, 0.0f), + SkDiscretePathEffect::Make(0, 0))); + break; + } + case TextDecorationStyle::kDashed: { + const SkScalar intervals[] = {10.0f, 5.0f, 10.0f, 5.0f}; + size_t count = sizeof(intervals) / sizeof(intervals[0]); + paint.setPathEffect(SkPathEffect::MakeCompose( + SkDashPathEffect::Make(intervals, count, 0.0f), + SkDiscretePathEffect::Make(0, 0))); + break; + } + case TextDecorationStyle::kWavy: { + // TODO(garyq): Wave currently does a random wave instead of an ordered + // wave. + const SkScalar intervals[] = {1}; + size_t count = sizeof(intervals) / sizeof(intervals[0]); + paint.setPathEffect(SkPathEffect::MakeCompose( + SkDashPathEffect::Make(intervals, count, 0.0f), + SkDiscretePathEffect::Make(metrics.fAvgCharWidth / 10.0f, + metrics.fAvgCharWidth / 10.0f))); + break; + } + } + double width = blob->bounds().fRight + blob->bounds().fLeft; - if (std::get<0>(decoration) & 0x1) { - paint.setStrokeWidth(metrics.fUnderlineThickness); - canvas->drawLine(x, y + metrics.fUnderlineThickness, x + width, - y + metrics.fUnderlineThickness, paint); - } - if (std::get<0>(decoration) & 0x2) { - paint.setStrokeWidth(metrics.fUnderlineThickness); - canvas->drawLine(x, y + metrics.fAscent, x + width, y + metrics.fAscent, - paint); - } - if (std::get<0>(decoration) & 0x4) { - paint.setStrokeWidth(metrics.fUnderlineThickness); - canvas->drawLine(x, y - metrics.fCapHeight / 2.5, x + width, - y - metrics.fCapHeight / 2.5, paint); + for (int i = 0; i < decoration_count; i++) { + double y_offset = i * metrics.fUnderlineThickness * 3.0f; + if (style.decoration & 0x1) { + paint.setStrokeWidth(metrics.fUnderlineThickness); + canvas->drawLine(x, y + metrics.fUnderlineThickness + y_offset, + x + width, y + metrics.fUnderlineThickness + y_offset, + paint); + } + if (style.decoration & 0x2) { + paint.setStrokeWidth(metrics.fUnderlineThickness); + canvas->drawLine(x, y + metrics.fAscent + y_offset, x + width, + y + metrics.fAscent + y_offset, paint); + } + if (style.decoration & 0x4) { + paint.setStrokeWidth(metrics.fUnderlineThickness); + canvas->drawLine(x, y - metrics.fXHeight / 2 + y_offset, x + width, + y - metrics.fXHeight / 2 + y_offset, paint); + } } } } diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 5a1e861afdc..1d6ccd402d5 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -75,9 +75,6 @@ class Paragraph { StyledRuns runs_; minikin::LineBreaker breaker_; std::vector records_; - std::vector< - std::tuple> - decorations_; ParagraphStyle paragraph_style_; SkScalar y_ = 0.0f; // Height of the paragraph after Layout(). double width_ = 0.0f; @@ -91,14 +88,12 @@ class Paragraph { void AddRunsToLineBreaker(const std::string& rootdir = ""); - void PaintDecorations( - SkCanvas* canvas, - double x, - double y, - std::tuple - decoration, - SkPaint::FontMetrics metrics, - SkTextBlob* blob); + void PaintDecorations(SkCanvas* canvas, + double x, + double y, + TextStyle style, + SkPaint::FontMetrics metrics, + SkTextBlob* blob); FTL_DISALLOW_COPY_AND_ASSIGN(Paragraph); }; diff --git a/engine/src/flutter/src/text_decoration.h b/engine/src/flutter/src/text_decoration.h index 8e7b1654a49..055cf4b5790 100644 --- a/engine/src/flutter/src/text_decoration.h +++ b/engine/src/flutter/src/text_decoration.h @@ -19,6 +19,8 @@ namespace txt { +// Multiple decorations can be applied at once. Ex: Underline and overline is +// (0x1 | 0x2) enum TextDecoration { kNone = 0x0, kUnderline = 0x1, @@ -26,13 +28,7 @@ enum TextDecoration { kLineThrough = 0x4, }; -enum TextDecorationStyle { - kSolid, - kDouble, // "double" is reserved. - kDotted, - kDashed, - kWavy -}; +enum TextDecorationStyle { kSolid, kDouble, kDotted, kDashed, kWavy }; } // namespace txt From f1a7448f4422e75aad038cb902d62ffdfac0da26 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Wed, 21 Jun 2017 11:46:37 -0700 Subject: [PATCH 298/364] Properly implement line spacing. Change-Id: I2f7f7768fc9d6332873f27dce6e058b354b0330d --- engine/src/flutter/src/paint_record.cc | 17 ++++--- engine/src/flutter/src/paint_record.h | 12 +++-- engine/src/flutter/src/paragraph.cc | 51 ++++++++++++++----- engine/src/flutter/src/paragraph.h | 4 +- .../flutter/tests/txt/paragraph_unittests.cc | 18 +++---- 5 files changed, 69 insertions(+), 33 deletions(-) diff --git a/engine/src/flutter/src/paint_record.cc b/engine/src/flutter/src/paint_record.cc index f8d13dbc259..e360e55a43b 100644 --- a/engine/src/flutter/src/paint_record.cc +++ b/engine/src/flutter/src/paint_record.cc @@ -21,19 +21,21 @@ namespace txt { PaintRecord::~PaintRecord() = default; -PaintRecord::PaintRecord(SkColor color, - TextStyle style, +PaintRecord::PaintRecord(TextStyle style, SkPoint offset, sk_sp text, SkPaint::FontMetrics metrics) - : color_(color), - style_(style), + : style_(style), offset_(offset), text_(std::move(text)), metrics_(metrics) {} +PaintRecord::PaintRecord(TextStyle style, + sk_sp text, + SkPaint::FontMetrics metrics) + : style_(style), text_(std::move(text)), metrics_(metrics) {} + PaintRecord::PaintRecord(PaintRecord&& other) { - color_ = other.color_; style_ = other.style_; offset_ = other.offset_; text_ = std::move(other.text_); @@ -41,7 +43,6 @@ PaintRecord::PaintRecord(PaintRecord&& other) { } PaintRecord& PaintRecord::operator=(PaintRecord&& other) { - color_ = other.color_; style_ = other.style_; offset_ = other.offset_; text_ = std::move(other.text_); @@ -49,4 +50,8 @@ PaintRecord& PaintRecord::operator=(PaintRecord&& other) { return *this; } +void PaintRecord::SetOffset(SkPoint pt) { + offset_ = pt; +} + } // namespace txt diff --git a/engine/src/flutter/src/paint_record.h b/engine/src/flutter/src/paint_record.h index d0c18fc05d0..f9434ed163a 100644 --- a/engine/src/flutter/src/paint_record.h +++ b/engine/src/flutter/src/paint_record.h @@ -31,20 +31,23 @@ class PaintRecord { ~PaintRecord(); - PaintRecord(SkColor color, - TextStyle style, + PaintRecord(TextStyle style, SkPoint offset, sk_sp text, SkPaint::FontMetrics metrics); + PaintRecord(TextStyle style, + sk_sp text, + SkPaint::FontMetrics metrics); + PaintRecord(PaintRecord&& other); PaintRecord& operator=(PaintRecord&& other); - SkColor color() const { return color_; } - SkPoint offset() const { return offset_; } + void SetOffset(SkPoint pt); + SkTextBlob* text() const { return text_.get(); } const SkPaint::FontMetrics& metrics() const { return metrics_; } @@ -52,7 +55,6 @@ class PaintRecord { const TextStyle& style() const { return style_; } private: - SkColor color_; TextStyle style_; SkPoint offset_; sk_sp text_; diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 48fcc8a56f2..cb2d7d99e7b 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -138,8 +138,9 @@ void Paragraph::Layout(double width, const std::string& rootdir, const double x_offset, const double y_offset) { - breaker_.setLineWidths(0.0f, 0, width); width_ = width; + + breaker_.setLineWidths(0.0f, 0, width); AddRunsToLineBreaker(rootdir); size_t breaks_count = breaker_.computeBreaks(); const int* breaks = breaker_.getBreaks(); @@ -150,20 +151,31 @@ void Paragraph::Layout(double width, minikin::FontStyle font; minikin::MinikinPaint minikin_paint; + minikin::Layout layout; SkTextBlobBuilder builder; // Reset member variables so Layout still works when called more than once max_intrinsic_width_ = 0.0f; lines_ = 0; - - minikin::Layout layout; - SkScalar x = x_offset; y_ = y_offset; + + SkScalar x = x_offset; size_t break_index = 0; double letter_spacing_offset = 0.0f; double word_spacing_offset = 0.0f; double max_line_spacing = 0.0f; + double max_descent = 0.0f; + double prev_max_descent = 0.0f; + std::vector x_queue; + + auto flush = [this, &x_queue]() -> void { + for (size_t i = 0; i < x_queue.size(); ++i) { + records_[records_.size() - (x_queue.size() - i)].SetOffset( + SkPoint::Make(x_queue[i], y_)); + } + x_queue.clear(); + }; for (size_t run_index = 0; run_index < runs_.size(); ++run_index) { auto run = runs_.GetRun(run_index); @@ -206,10 +218,12 @@ void Paragraph::Layout(double width, const size_t glyph_index = blob_start + blob_index; buffer.glyphs[blob_index] = layout.getGlyphId(glyph_index); const size_t pos_index = 2 * blob_index; + buffer.pos[pos_index] = layout.getX(glyph_index) + letter_spacing_offset + word_spacing_offset; - letter_spacing_offset += run.style.letter_spacing; buffer.pos[pos_index + 1] = layout.getY(glyph_index); + + letter_spacing_offset += run.style.letter_spacing; } blob_start += blob_length; @@ -232,16 +246,27 @@ void Paragraph::Layout(double width, // run. SkPaint::FontMetrics metrics; paint.getFontMetrics(&metrics); - records_.push_back(PaintRecord{run.style.color, run.style, - SkPoint::Make(x, y_), builder.make(), - metrics}); - if (max_line_spacing < -metrics.fAscent * run.style.height) - max_line_spacing = -metrics.fAscent * run.style.height; + records_.push_back(PaintRecord{run.style, builder.make(), metrics}); + + // Must adjust each line to the largest text in the line, so cannot + // directly push the offset property of PaintRecord until line is + // finished. + x_queue.push_back(x); + + if (max_line_spacing < + (-metrics.fAscent + metrics.fLeading) * run.style.height) + max_line_spacing = + (-metrics.fAscent + metrics.fLeading) * run.style.height; + if (max_descent < metrics.fDescent * run.style.height) + max_descent = metrics.fDescent * run.style.height; if (layout_end == next_break) { - y_ += max_line_spacing; + y_ += max_line_spacing + prev_max_descent; + prev_max_descent = max_descent; + flush(); max_line_spacing = 0.0f; + max_descent = 0.0f; x = 0.0f; letter_spacing_offset = 0.0f; word_spacing_offset = 0.0f; @@ -256,6 +281,8 @@ void Paragraph::Layout(double width, layout_start = layout_end; } } + y_ += max_line_spacing; + flush(); } const ParagraphStyle& Paragraph::GetParagraphStyle() const { @@ -292,7 +319,7 @@ void Paragraph::SetParagraphStyle(const ParagraphStyle& style) { void Paragraph::Paint(SkCanvas* canvas, double x, double y) { for (const auto& record : records_) { SkPaint paint; - paint.setColor(record.color()); + paint.setColor(record.style().color); const SkPoint& offset = record.offset(); canvas->drawTextBlob(record.text(), x + offset.x(), y + offset.y(), paint); PaintDecorations(canvas, x + offset.x(), y + offset.y(), record.style(), diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 1d6ccd402d5..1b128481fde 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -76,7 +76,9 @@ class Paragraph { minikin::LineBreaker breaker_; std::vector records_; ParagraphStyle paragraph_style_; - SkScalar y_ = 0.0f; // Height of the paragraph after Layout(). + SkScalar y_ = 0.0f; + // TODO(garyq): Height of the paragraph after Layout(). + SkScalar height_ = 0.0f; double width_ = 0.0f; int lines_ = 1; double max_intrinsic_width_ = 0.0f; diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 7f01eb45c7c..941d6cd8c96 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -54,7 +54,7 @@ TEST_F(RenderTest, SimpleParagraph) { ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); - ASSERT_EQ(paragraph->records_[0].color(), text_style.color); + ASSERT_EQ(paragraph->records_[0].style().color, text_style.color); ASSERT_TRUE(Snapshot()); } @@ -87,7 +87,7 @@ TEST_F(RenderTest, SimpleRedParagraph) { ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); - ASSERT_EQ(paragraph->records_[0].color(), text_style.color); + ASSERT_EQ(paragraph->records_[0].style().color, text_style.color); ASSERT_TRUE(Snapshot()); } @@ -175,10 +175,10 @@ TEST_F(RenderTest, RainbowParagraph) { ASSERT_TRUE(paragraph->runs_.styles_[1].equals(text_style2)); ASSERT_TRUE(paragraph->runs_.styles_[2].equals(text_style3)); ASSERT_TRUE(paragraph->runs_.styles_[3].equals(text_style4)); - ASSERT_EQ(paragraph->records_[0].color(), text_style1.color); - ASSERT_EQ(paragraph->records_[1].color(), text_style2.color); - ASSERT_EQ(paragraph->records_[2].color(), text_style3.color); - ASSERT_EQ(paragraph->records_[3].color(), text_style4.color); + ASSERT_EQ(paragraph->records_[0].style().color, text_style1.color); + ASSERT_EQ(paragraph->records_[1].style().color, text_style2.color); + ASSERT_EQ(paragraph->records_[2].style().color, text_style3.color); + ASSERT_EQ(paragraph->records_[3].style().color, text_style4.color); } // Currently, this should render nothing without a supplied TextStyle. @@ -246,7 +246,7 @@ TEST_F(RenderTest, BoldParagraph) { ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); - ASSERT_EQ(paragraph->records_[0].color(), text_style.color); + ASSERT_EQ(paragraph->records_[0].style().color, text_style.color); ASSERT_TRUE(Snapshot()); } @@ -313,7 +313,7 @@ TEST_F(RenderTest, LinebreakParagraph) { ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); - ASSERT_EQ(paragraph->records_[0].color(), text_style.color); + ASSERT_EQ(paragraph->records_[0].style().color, text_style.color); ASSERT_TRUE(Snapshot()); } @@ -348,7 +348,7 @@ TEST_F(RenderTest, ItalicsParagraph) { ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); - ASSERT_EQ(paragraph->records_[0].color(), text_style.color); + ASSERT_EQ(paragraph->records_[0].style().color, text_style.color); ASSERT_TRUE(Snapshot()); } From b5d528f2793cc656919f47ae2793d8b88615dc30 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Wed, 21 Jun 2017 15:22:27 -0700 Subject: [PATCH 299/364] Implemented early version of text alignment/justification and baselines. Change-Id: Id36a20bb9c392f09813175677776d9367d8ccfc2 --- engine/src/flutter/src/paint_record.cc | 13 ++-- engine/src/flutter/src/paint_record.h | 9 ++- engine/src/flutter/src/paragraph.cc | 65 +++++++++++++++---- engine/src/flutter/src/paragraph.h | 4 +- .../flutter/tests/txt/paragraph_unittests.cc | 3 + 5 files changed, 73 insertions(+), 21 deletions(-) diff --git a/engine/src/flutter/src/paint_record.cc b/engine/src/flutter/src/paint_record.cc index e360e55a43b..07322ce05a2 100644 --- a/engine/src/flutter/src/paint_record.cc +++ b/engine/src/flutter/src/paint_record.cc @@ -24,22 +24,26 @@ PaintRecord::~PaintRecord() = default; PaintRecord::PaintRecord(TextStyle style, SkPoint offset, sk_sp text, - SkPaint::FontMetrics metrics) + SkPaint::FontMetrics metrics, + int line) : style_(style), offset_(offset), text_(std::move(text)), - metrics_(metrics) {} + metrics_(metrics), + line_(line) {} PaintRecord::PaintRecord(TextStyle style, sk_sp text, - SkPaint::FontMetrics metrics) - : style_(style), text_(std::move(text)), metrics_(metrics) {} + SkPaint::FontMetrics metrics, + int line) + : style_(style), text_(std::move(text)), metrics_(metrics), line_(line) {} PaintRecord::PaintRecord(PaintRecord&& other) { style_ = other.style_; offset_ = other.offset_; text_ = std::move(other.text_); metrics_ = other.metrics_; + line_ = other.line_; } PaintRecord& PaintRecord::operator=(PaintRecord&& other) { @@ -47,6 +51,7 @@ PaintRecord& PaintRecord::operator=(PaintRecord&& other) { offset_ = other.offset_; text_ = std::move(other.text_); metrics_ = other.metrics_; + line_ = other.line_; return *this; } diff --git a/engine/src/flutter/src/paint_record.h b/engine/src/flutter/src/paint_record.h index f9434ed163a..cc5b82807ab 100644 --- a/engine/src/flutter/src/paint_record.h +++ b/engine/src/flutter/src/paint_record.h @@ -34,11 +34,13 @@ class PaintRecord { PaintRecord(TextStyle style, SkPoint offset, sk_sp text, - SkPaint::FontMetrics metrics); + SkPaint::FontMetrics metrics, + int line); PaintRecord(TextStyle style, sk_sp text, - SkPaint::FontMetrics metrics); + SkPaint::FontMetrics metrics, + int line); PaintRecord(PaintRecord&& other); @@ -54,11 +56,14 @@ class PaintRecord { const TextStyle& style() const { return style_; } + double line() const { return line_; } + private: TextStyle style_; SkPoint offset_; sk_sp text_; SkPaint::FontMetrics metrics_; + int line_; FTL_DISALLOW_COPY_AND_ASSIGN(PaintRecord); }; diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index cb2d7d99e7b..474632c1b7b 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -158,21 +158,22 @@ void Paragraph::Layout(double width, // Reset member variables so Layout still works when called more than once max_intrinsic_width_ = 0.0f; lines_ = 0; - y_ = y_offset; SkScalar x = x_offset; + SkScalar y = y_offset; size_t break_index = 0; double letter_spacing_offset = 0.0f; double word_spacing_offset = 0.0f; double max_line_spacing = 0.0f; double max_descent = 0.0f; double prev_max_descent = 0.0f; + double line_width = 0.0f; std::vector x_queue; - auto flush = [this, &x_queue]() -> void { + auto flush = [this, &x_queue, &y]() -> void { for (size_t i = 0; i < x_queue.size(); ++i) { records_[records_.size() - (x_queue.size() - i)].SetOffset( - SkPoint::Make(x_queue[i], y_)); + SkPoint::Make(x_queue[i], y)); } x_queue.clear(); }; @@ -240,13 +241,18 @@ void Paragraph::Layout(double width, // Subtract word offset to avoid big gap at end of run. This my be // removed depending on the specificatins for word spacing. word_spacing_offset -= run.style.word_spacing; + // TODO(abarth): We could keep the same SkTextBlobBuilder as long as the // color stayed the same. // TODO(garyq): Ensure that the typeface does not change throughout a // run. SkPaint::FontMetrics metrics; paint.getFontMetrics(&metrics); - records_.push_back(PaintRecord{run.style, builder.make(), metrics}); + records_.push_back( + PaintRecord{run.style, builder.make(), metrics, lines_}); + line_width += + std::abs(records_[records_.size() - 1].text()->bounds().fRight + + records_[records_.size() - 1].text()->bounds().fLeft); // Must adjust each line to the largest text in the line, so cannot // directly push the offset property of PaintRecord until line is @@ -254,15 +260,25 @@ void Paragraph::Layout(double width, x_queue.push_back(x); if (max_line_spacing < - (-metrics.fAscent + metrics.fLeading) * run.style.height) - max_line_spacing = - (-metrics.fAscent + metrics.fLeading) * run.style.height; + (-metrics.fAscent + metrics.fLeading) * run.style.height) { + max_line_spacing = lines_ == 0 ? -metrics.fAscent * run.style.height + : (-metrics.fAscent + metrics.fLeading) * + run.style.height; + // Record the alphabetic_baseline_: + if (lines_ == 0) { + alphabetic_baseline_ = -metrics.fAscent * run.style.height; + // TODO(garyq): Properly implement ideographic_baseline_. + ideographic_baseline_ = + ((metrics.fDescent / 2) - metrics.fAscent) * run.style.height; + } + } if (max_descent < metrics.fDescent * run.style.height) max_descent = metrics.fDescent * run.style.height; if (layout_end == next_break) { - y_ += max_line_spacing + prev_max_descent; + y += max_line_spacing + prev_max_descent; prev_max_descent = max_descent; + line_widths_.push_back(line_width); flush(); max_line_spacing = 0.0f; @@ -270,6 +286,7 @@ void Paragraph::Layout(double width, x = 0.0f; letter_spacing_offset = 0.0f; word_spacing_offset = 0.0f; + line_width = 0.0f; // TODO(abarth): Use the line height, which is something like the max // font_size for runs in this line times the paragraph's line height. break_index += 1; @@ -281,8 +298,12 @@ void Paragraph::Layout(double width, layout_start = layout_end; } } - y_ += max_line_spacing; + y += max_line_spacing; flush(); + if (line_width != 0) + line_widths_.push_back(line_width); + + height_ = y + max_descent; } const ParagraphStyle& Paragraph::GetParagraphStyle() const { @@ -290,13 +311,12 @@ const ParagraphStyle& Paragraph::GetParagraphStyle() const { } double Paragraph::GetAlphabeticBaseline() const { - // TODO(garyq): Implement. - return FLT_MAX; + return alphabetic_baseline_; } double Paragraph::GetIdeographicBaseline() const { // TODO(garyq): Implement. - return FLT_MAX; + return ideographic_baseline_; } double Paragraph::GetMaxIntrinsicWidth() const { @@ -309,7 +329,7 @@ double Paragraph::GetMinIntrinsicWidth() const { } double Paragraph::GetHeight() const { - return y_; + return height_; } void Paragraph::SetParagraphStyle(const ParagraphStyle& style) { @@ -320,7 +340,24 @@ void Paragraph::Paint(SkCanvas* canvas, double x, double y) { for (const auto& record : records_) { SkPaint paint; paint.setColor(record.style().color); - const SkPoint& offset = record.offset(); + SkPoint offset = record.offset(); + // TODO(garyq): Fix alignment for paragraphs with multiple styles per line. + switch (paragraph_style_.text_align) { + case TextAlign::left: + break; + case TextAlign::right: { + offset.offset(width_ - line_widths_[record.line()], 0); + break; + } + case TextAlign::center: { + offset.offset((width_ - line_widths_[record.line()]) / 2, 0); + break; + } + case TextAlign::justify: { + // TODO(garyq): implement justify. + break; + } + } canvas->drawTextBlob(record.text(), x + offset.x(), y + offset.y(), paint); PaintDecorations(canvas, x + offset.x(), y + offset.y(), record.style(), record.metrics(), record.text()); diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 1b128481fde..a4e8529e51a 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -75,14 +75,16 @@ class Paragraph { StyledRuns runs_; minikin::LineBreaker breaker_; std::vector records_; + std::vector line_widths_; ParagraphStyle paragraph_style_; - SkScalar y_ = 0.0f; // TODO(garyq): Height of the paragraph after Layout(). SkScalar height_ = 0.0f; double width_ = 0.0f; int lines_ = 1; double max_intrinsic_width_ = 0.0f; double min_intrinsic_width_ = 0.0f; + double alphabetic_baseline_ = FLT_MAX; + double ideographic_baseline_ = FLT_MAX; void SetText(std::vector text, StyledRuns runs); diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 941d6cd8c96..463d18e5b00 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -18,6 +18,7 @@ #include "lib/txt/src/font_style.h" #include "lib/txt/src/font_weight.h" #include "lib/txt/src/paragraph.h" +#include "lib/txt/src/text_align.h" #include "lib/txt/tests/txt/utils.h" #include "paragraph_builder.h" #include "render_test.h" @@ -117,6 +118,7 @@ TEST_F(RenderTest, RainbowParagraph) { txt::ParagraphStyle paragraph_style; paragraph_style.max_lines = 2; + paragraph_style.text_align = TextAlign::left; txt::ParagraphBuilder builder(paragraph_style); txt::TextStyle text_style1; @@ -285,6 +287,7 @@ TEST_F(RenderTest, LinebreakParagraph) { txt::ParagraphStyle paragraph_style; paragraph_style.max_lines = 14; + paragraph_style.text_align = TextAlign::center; txt::ParagraphBuilder builder(paragraph_style); txt::TextStyle text_style; From f17cdae74ed79679f58807b33be15e287f248b6d Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Thu, 22 Jun 2017 10:22:52 -0700 Subject: [PATCH 300/364] Prevent multiple calls to layout without changing paragraph. Change-Id: I64e81606f095e3029161f5a01623df4c1ccbf5a9 --- engine/src/flutter/src/paragraph.cc | 23 +++++++++++++++++++---- engine/src/flutter/src/paragraph.h | 1 + 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 474632c1b7b..e8de72d3992 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -112,6 +112,9 @@ Paragraph::Paragraph() = default; Paragraph::~Paragraph() = default; void Paragraph::SetText(std::vector text, StyledRuns runs) { + needs_layout_ = true; + if (text.size() == 0) + return; text_ = std::move(text); runs_ = std::move(runs); @@ -138,6 +141,11 @@ void Paragraph::Layout(double width, const std::string& rootdir, const double x_offset, const double y_offset) { + // Do not allow calling layout multiple times without changing anything. + if (!needs_layout_) + return; + needs_layout_ = false; + width_ = width; breaker_.setLineWidths(0.0f, 0, width); @@ -261,15 +269,15 @@ void Paragraph::Layout(double width, if (max_line_spacing < (-metrics.fAscent + metrics.fLeading) * run.style.height) { - max_line_spacing = lines_ == 0 ? -metrics.fAscent * run.style.height + max_line_spacing = lines_ == 0 ? metrics.fCapHeight * run.style.height : (-metrics.fAscent + metrics.fLeading) * run.style.height; // Record the alphabetic_baseline_: if (lines_ == 0) { - alphabetic_baseline_ = -metrics.fAscent * run.style.height; + alphabetic_baseline_ = metrics.fCapHeight * run.style.height; // TODO(garyq): Properly implement ideographic_baseline_. ideographic_baseline_ = - ((metrics.fDescent / 2) - metrics.fAscent) * run.style.height; + (metrics.fDescent + metrics.fCapHeight) * run.style.height; } } if (max_descent < metrics.fDescent * run.style.height) @@ -333,12 +341,13 @@ double Paragraph::GetHeight() const { } void Paragraph::SetParagraphStyle(const ParagraphStyle& style) { + needs_layout_ = true; paragraph_style_ = style; } void Paragraph::Paint(SkCanvas* canvas, double x, double y) { + SkPaint paint; for (const auto& record : records_) { - SkPaint paint; paint.setColor(record.style().color); SkPoint offset = record.offset(); // TODO(garyq): Fix alignment for paragraphs with multiple styles per line. @@ -362,6 +371,12 @@ void Paragraph::Paint(SkCanvas* canvas, double x, double y) { PaintDecorations(canvas, x + offset.x(), y + offset.y(), record.style(), record.metrics(), record.text()); } + + paint.setStyle(SkPaint::kFill_Style); + paint.setAntiAlias(true); + paint.setStrokeWidth(4); + paint.setColor(0xffFE938C); + canvas->drawCircle(x, y, 3, paint); } void Paragraph::PaintDecorations(SkCanvas* canvas, diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index a4e8529e51a..93b28b6f02d 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -85,6 +85,7 @@ class Paragraph { double min_intrinsic_width_ = 0.0f; double alphabetic_baseline_ = FLT_MAX; double ideographic_baseline_ = FLT_MAX; + bool needs_layout_ = true; void SetText(std::vector text, StyledRuns runs); From 1d9ea69014dd02b80080ea6d1d645d1f4099b121 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Thu, 22 Jun 2017 15:16:05 -0700 Subject: [PATCH 301/364] Begin to move FontCollection to a multi-manager system. Change-Id: Ied69fa2d567f695990a754337bab79dc2f17c6ef --- engine/src/flutter/src/font_collection.cc | 104 ++++++++++-------- engine/src/flutter/src/font_collection.h | 8 +- .../tests/txt/font_collection_unittests.cc | 6 +- 3 files changed, 67 insertions(+), 51 deletions(-) diff --git a/engine/src/flutter/src/font_collection.cc b/engine/src/flutter/src/font_collection.cc index 05b5d6b66f6..29837694949 100644 --- a/engine/src/flutter/src/font_collection.cc +++ b/engine/src/flutter/src/font_collection.cc @@ -29,9 +29,15 @@ namespace txt { FontCollection& FontCollection::GetFontCollection(std::string dir) { + std::vector dirs = {dir}; + return GetFontCollection(std::move(dirs)); +} + +FontCollection& FontCollection::GetFontCollection( + std::vector dirs) { static FontCollection* collection = nullptr; static std::once_flag once; - std::call_once(once, [dir]() { collection = new FontCollection(dir); }); + std::call_once(once, [dirs]() { collection = new FontCollection(dirs); }); return *collection; } @@ -39,28 +45,33 @@ FontCollection& FontCollection::GetDefaultFontCollection() { return GetFontCollection(""); } -FontCollection::FontCollection(std::string dir) { +FontCollection::FontCollection(const std::vector& dirs) { #ifdef DIRECTORY_FONT_MANAGER_AVAILABLE - skia_font_manager_ = dir.length() != 0 - ? SkFontMgr_New_Custom_Directory(dir.c_str()) - : SkFontMgr::RefDefault(); -#else - skia_font_manager_ = SkFontMgr::RefDefault(); + for (std::string dir : dirs) { + if (dir.length() != 0) { + skia_font_managers_.push_back( + SkFontMgr_New_Custom_Directory(dir.c_str())); + } + } #endif + skia_font_managers_.push_back(SkFontMgr::RefDefault()); + + SkString str; + for (sk_sp mgr : skia_font_managers_) { + for (int i = 0; i < mgr->countFamilies(); i++) { + mgr->getFamilyName(i, &str); + family_names_.insert(std::string{str.writable_str()}); + } + } } FontCollection::~FontCollection() = default; std::set FontCollection::GetFamilyNames() { - std::set names; - SkString str; - for (int i = 0; i < skia_font_manager_->countFamilies(); i++) { - skia_font_manager_->getFamilyName(i, &str); - names.insert(std::string{str.writable_str()}); - } - return names; + return family_names_; } +// TODO(garyq): Rework this to use font fallback system. const std::string FontCollection::ProcessFamilyName(const std::string& family) { #ifdef DIRECTORY_FONT_MANAGER_AVAILABLE return family.length() == 0 ? DEFAULT_FAMILY_NAME : family; @@ -77,49 +88,52 @@ const std::string FontCollection::ProcessFamilyName(const std::string& family) { std::shared_ptr FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) { - FTL_DCHECK(skia_font_manager_ != nullptr); + FTL_DCHECK(skia_font_managers_.size() > 0); // Ask Skia to resolve a font style set for a font family name. // FIXME(chinmaygarde): The name "Coolvetica" is hardcoded because CoreText // crashes when passed a null string. This seems to be a bug in Skia as // SkFontMgr explicitly says passing in nullptr gives the default font. + for (sk_sp mgr : skia_font_managers_) { + FTL_DCHECK(mgr != nullptr); + auto font_style_set = mgr->matchFamily(ProcessFamilyName(family).c_str()); + FTL_DCHECK(font_style_set != nullptr); - auto font_style_set = - skia_font_manager_->matchFamily(ProcessFamilyName(family).c_str()); - FTL_DCHECK(font_style_set != nullptr); + std::vector minikin_fonts; - std::vector minikin_fonts; + // Add fonts to the Minikin font family. + for (int i = 0, style_count = font_style_set->count(); i < style_count; + ++i) { + // Create the skia typeface + auto skia_typeface = + sk_ref_sp(font_style_set->createTypeface(i)); + if (skia_typeface == nullptr) { + continue; + } - // Add fonts to the Minikin font family. - for (int i = 0, style_count = font_style_set->count(); i < style_count; ++i) { - // Create the skia typeface - auto skia_typeface = - sk_ref_sp(font_style_set->createTypeface(i)); - if (skia_typeface == nullptr) { - continue; + // Create the minikin font from the skia typeface. + minikin::Font minikin_font( + std::make_shared(skia_typeface), + minikin::FontStyle{skia_typeface->fontStyle().weight(), + skia_typeface->isItalic()}); + + minikin_fonts.emplace_back(std::move(minikin_font)); } - // Create the minikin font from the skia typeface. - minikin::Font minikin_font( - std::make_shared(skia_typeface), - minikin::FontStyle{skia_typeface->fontStyle().weight(), - skia_typeface->isItalic()}); + // Create a Minikin font family. + auto minikin_family = + std::make_shared(std::move(minikin_fonts)); - minikin_fonts.emplace_back(std::move(minikin_font)); + // Create a vector of font families for the Minkin font collection. For now, + // we only have one family in our collection. + std::vector> minikin_families = { + minikin_family, + }; + + // Return the font collection. + return std::make_shared(minikin_families); } - - // Create a Minikin font family. - auto minikin_family = - std::make_shared(std::move(minikin_fonts)); - - // Create a vector of font families for the Minkin font collection. For now, - // we only have one family in our collection. - std::vector> minikin_families = { - minikin_family, - }; - - // Return the font collection. - return std::make_shared(minikin_families); + return nullptr; } } // namespace txt diff --git a/engine/src/flutter/src/font_collection.h b/engine/src/flutter/src/font_collection.h index 836e22e8ff7..b8a0c8a6de2 100644 --- a/engine/src/flutter/src/font_collection.h +++ b/engine/src/flutter/src/font_collection.h @@ -39,6 +39,8 @@ class FontCollection { static FontCollection& GetFontCollection(std::string dir = ""); + static FontCollection& GetFontCollection(std::vector dirs); + std::shared_ptr GetMinikinFontCollectionForFamily( const std::string& family); @@ -46,7 +48,9 @@ class FontCollection { std::set GetFamilyNames(); private: - sk_sp skia_font_manager_; + std::vector> skia_font_managers_; + // Cache the names because GetFamilyNames() can be frequently called. + std::set family_names_; FRIEND_TEST(FontCollection, HasDefaultRegistrations); FRIEND_TEST(FontCollection, GetMinikinFontCollections); @@ -58,7 +62,7 @@ class FontCollection { return DEFAULT_FAMILY_NAME; }; - FontCollection(std::string dir = ""); + FontCollection(const std::vector& dirs); ~FontCollection(); diff --git a/engine/src/flutter/tests/txt/font_collection_unittests.cc b/engine/src/flutter/tests/txt/font_collection_unittests.cc index f501649a1c2..7f98cccb30f 100644 --- a/engine/src/flutter/tests/txt/font_collection_unittests.cc +++ b/engine/src/flutter/tests/txt/font_collection_unittests.cc @@ -67,7 +67,7 @@ TEST(FontCollection, GetFamilyNames) { txt::FontCollection::GetFontCollection(txt::GetFontDir()) .GetFamilyNames(); - ASSERT_EQ(names.size(), 19ull); + ASSERT_TRUE(names.size() >= 19ull); ASSERT_EQ(names.count("Roboto"), 1ull); ASSERT_EQ(names.count("Homemade Apple"), 1ull); @@ -92,9 +92,7 @@ TEST(FontCollection, GetFamilyNames) { ASSERT_EQ(names.count("Not a real font!"), 0ull); ASSERT_EQ(names.count(""), 0ull); - ASSERT_EQ(names.count("Helvetica"), 0ull); - ASSERT_EQ(names.count("TimesNewRoman"), 0ull); - ASSERT_EQ(names.count("Arial"), 0ull); + ASSERT_EQ(names.count("Another Fake Font"), 0ull); } } // namespace txt From 9935045848599ac9ea2df9be2c19521e1a50d15e Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Fri, 23 Jun 2017 12:54:46 -0700 Subject: [PATCH 302/364] Implement initial version of text justification, new tests, and fix bugs with right and center alignment. Change-Id: I3b6a547e1d81c966b82108c02d60aa7181cb0b87 --- engine/src/flutter/src/paint_record.h | 4 +- engine/src/flutter/src/paragraph.cc | 104 +++++++--- engine/src/flutter/src/paragraph.h | 12 +- engine/src/flutter/src/paragraph_style.h | 2 +- engine/src/flutter/src/styled_runs.h | 5 +- .../flutter/tests/txt/paragraph_unittests.cc | 178 +++++++++++++++++- engine/src/flutter/tests/txt/render_test.cc | 2 +- 7 files changed, 264 insertions(+), 43 deletions(-) diff --git a/engine/src/flutter/src/paint_record.h b/engine/src/flutter/src/paint_record.h index cc5b82807ab..c34fd9d1628 100644 --- a/engine/src/flutter/src/paint_record.h +++ b/engine/src/flutter/src/paint_record.h @@ -56,14 +56,14 @@ class PaintRecord { const TextStyle& style() const { return style_; } - double line() const { return line_; } + size_t line() const { return line_; } private: TextStyle style_; SkPoint offset_; sk_sp text_; SkPaint::FontMetrics metrics_; - int line_; + size_t line_; FTL_DISALLOW_COPY_AND_ASSIGN(PaintRecord); }; diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index e8de72d3992..549de3af7ba 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -24,6 +24,7 @@ #include #include "lib/ftl/logging.h" +#include "lib/txt/libs/minikin/LayoutUtils.h" #include "lib/txt/src/font_collection.h" #include "lib/txt/src/font_skia.h" #include "minikin/LineBreaker.h" @@ -96,7 +97,7 @@ void GetFontAndMinikinPaint(const TextStyle& style, *font = minikin::FontStyle(GetWeight(style), GetItalic(style)); paint->size = style.font_size; paint->letterSpacing = style.letter_spacing; - paint->wordSpacing = style.word_spacing; // Likely not working yet. + paint->wordSpacing = style.word_spacing; // TODO(abarth): word_spacing. } @@ -148,8 +149,9 @@ void Paragraph::Layout(double width, width_ = width; - breaker_.setLineWidths(0.0f, 0, width); + breaker_.setLineWidths(0.0f, 0, width_); AddRunsToLineBreaker(rootdir); + breaker_.setJustified(paragraph_style_.text_align == TextAlign::justify); size_t breaks_count = breaker_.computeBreaks(); const int* breaks = breaker_.getBreaks(); @@ -171,12 +173,12 @@ void Paragraph::Layout(double width, SkScalar y = y_offset; size_t break_index = 0; double letter_spacing_offset = 0.0f; - double word_spacing_offset = 0.0f; double max_line_spacing = 0.0f; double max_descent = 0.0f; double prev_max_descent = 0.0f; double line_width = 0.0f; std::vector x_queue; + size_t character_index = 0; auto flush = [this, &x_queue, &y]() -> void { for (size_t i = 0; i < x_queue.size(); ++i) { @@ -209,28 +211,44 @@ void Paragraph::Layout(double width, int bidiFlags = 0; layout.doLayout(text_.data(), layout_start, layout_end - layout_start, text_.size(), bidiFlags, font, minikin_paint, collection); - const size_t glyph_count = layout.nGlyphs(); size_t blob_start = 0; - // Each word/blob. + // Each blob. + std::vector buffers; + std::vector buffer_sizes; + int word_count = 0; while (blob_start < glyph_count) { const size_t blob_length = GetBlobLength(layout, blob_start); + buffer_sizes.push_back(blob_length); // TODO(abarth): Precompute when we can use allocRunPosH. paint.setTypeface(GetTypefaceForGlyph(layout, blob_start)); - auto buffer = builder.allocRunPos(paint, blob_length); + buffers.push_back(&builder.allocRunPos(paint, blob_length)); letter_spacing_offset += run.style.letter_spacing; // Each Glyph/Letter. + bool whitespace_ended = true; for (size_t blob_index = 0; blob_index < blob_length; ++blob_index) { const size_t glyph_index = blob_start + blob_index; - buffer.glyphs[blob_index] = layout.getGlyphId(glyph_index); + buffers.back()->glyphs[blob_index] = layout.getGlyphId(glyph_index); + // Check if the current Glyph is a whitespace and handle multiple + // whitespaces in a row. + if (minikin::isWordSpace(text_[character_index])) { + // Only increment word_count if it is the first in a series of + // whitespaces. + if (whitespace_ended) + ++word_count; + whitespace_ended = false; + } else { + whitespace_ended = true; + } + ++character_index; const size_t pos_index = 2 * blob_index; - buffer.pos[pos_index] = layout.getX(glyph_index) + - letter_spacing_offset + word_spacing_offset; - buffer.pos[pos_index + 1] = layout.getY(glyph_index); + buffers.back()->pos[pos_index] = + layout.getX(glyph_index) + letter_spacing_offset; + buffers.back()->pos[pos_index + 1] = layout.getY(glyph_index); letter_spacing_offset += run.style.letter_spacing; } @@ -240,22 +258,21 @@ void Paragraph::Layout(double width, // removed depending on the specifications for letter spacing. // letter_spacing_offset -= run.style.letter_spacing; - word_spacing_offset += run.style.word_spacing; - max_intrinsic_width_ += layout.getX(blob_start - 1) + letter_spacing_offset; } - // Subtract word offset to avoid big gap at end of run. This my be - // removed depending on the specificatins for word spacing. - word_spacing_offset -= run.style.word_spacing; - // TODO(abarth): We could keep the same SkTextBlobBuilder as long as the // color stayed the same. // TODO(garyq): Ensure that the typeface does not change throughout a // run. SkPaint::FontMetrics metrics; paint.getFontMetrics(&metrics); + // Apply additional word spacing if the text is justified. + if (paragraph_style_.text_align == TextAlign::justify && + buffer_sizes.size() > 0) { + JustifyLine(buffers, buffer_sizes, word_count, character_index); + } records_.push_back( PaintRecord{run.style, builder.make(), metrics, lines_}); line_width += @@ -293,7 +310,7 @@ void Paragraph::Layout(double width, max_descent = 0.0f; x = 0.0f; letter_spacing_offset = 0.0f; - word_spacing_offset = 0.0f; + word_count = 0; line_width = 0.0f; // TODO(abarth): Use the line height, which is something like the max // font_size for runs in this line times the paragraph's line height. @@ -314,6 +331,45 @@ void Paragraph::Layout(double width, height_ = y + max_descent; } +// Amends the buffers to incorporate justification. +void Paragraph::JustifyLine( + std::vector& buffers, + std::vector& buffer_sizes, + int word_count, + size_t character_index) { + // TODO(garyq): Add letter_spacing_offset back in. It is Temporarily + // removed. + double justify_spacing = + (width_ - breaker_.getWidths()[lines_]) / (word_count - 1); + word_count = 0; + // Set up index to properly access text_ because minikin::isWordSpace() + // takes uint_16 instead of GlyphIDs. + size_t line_character_index = character_index; + for (size_t i = 0; i < buffers.size(); ++i) + line_character_index -= buffer_sizes[i]; + bool whitespace_ended = true; + for (size_t i = 0; i < buffers.size(); ++i) { + for (size_t glyph_index = 0; glyph_index < buffer_sizes[i]; ++glyph_index) { + // Check if the current Glyph is a whitespace and handle multiple + // whitespaces in a row. + if (minikin::isWordSpace(text_[line_character_index])) { + // Only increment word_count and add justification spacing to + // whitespace if it is the first in a series of whitespaces. + if (whitespace_ended) { + ++word_count; + buffers[i]->pos[glyph_index * 2] += justify_spacing * word_count; + } + whitespace_ended = false; + } else { + // Add justification spacing for all non-whitespace glyphs. + buffers[i]->pos[glyph_index * 2] += justify_spacing * word_count; + whitespace_ended = true; + } + ++line_character_index; + } + } +} + const ParagraphStyle& Paragraph::GetParagraphStyle() const { return paragraph_style_; } @@ -346,8 +402,8 @@ void Paragraph::SetParagraphStyle(const ParagraphStyle& style) { } void Paragraph::Paint(SkCanvas* canvas, double x, double y) { - SkPaint paint; for (const auto& record : records_) { + SkPaint paint; paint.setColor(record.style().color); SkPoint offset = record.offset(); // TODO(garyq): Fix alignment for paragraphs with multiple styles per line. @@ -355,15 +411,15 @@ void Paragraph::Paint(SkCanvas* canvas, double x, double y) { case TextAlign::left: break; case TextAlign::right: { - offset.offset(width_ - line_widths_[record.line()], 0); + offset.offset(width_ - breaker_.getWidths()[record.line()], 0); break; } case TextAlign::center: { - offset.offset((width_ - line_widths_[record.line()]) / 2, 0); + offset.offset((width_ - breaker_.getWidths()[record.line()]) / 2, 0); break; } case TextAlign::justify: { - // TODO(garyq): implement justify. + // Justify is performed in the Layout(). break; } } @@ -371,12 +427,6 @@ void Paragraph::Paint(SkCanvas* canvas, double x, double y) { PaintDecorations(canvas, x + offset.x(), y + offset.y(), record.style(), record.metrics(), record.text()); } - - paint.setStyle(SkPaint::kFill_Style); - paint.setAntiAlias(true); - paint.setStrokeWidth(4); - paint.setColor(0xffFE938C); - canvas->drawCircle(x, y, 3, paint); } void Paragraph::PaintDecorations(SkCanvas* canvas, diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 93b28b6f02d..f71b16be11a 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -68,7 +68,10 @@ class Paragraph { FRIEND_TEST(RenderTest, RainbowParagraph); FRIEND_TEST(RenderTest, DefaultStyleParagraph); FRIEND_TEST(RenderTest, BoldParagraph); - FRIEND_TEST(RenderTest, LinebreakParagraph); + FRIEND_TEST(RenderTest, LeftAlignParagraph); + FRIEND_TEST(RenderTest, RightAlignParagraph); + FRIEND_TEST(RenderTest, CenterAlignParagraph); + FRIEND_TEST(RenderTest, JustifyAlignParagraph); FRIEND_TEST(RenderTest, ItalicsParagraph); std::vector text_; @@ -80,7 +83,7 @@ class Paragraph { // TODO(garyq): Height of the paragraph after Layout(). SkScalar height_ = 0.0f; double width_ = 0.0f; - int lines_ = 1; + size_t lines_ = 0; double max_intrinsic_width_ = 0.0f; double min_intrinsic_width_ = 0.0f; double alphabetic_baseline_ = FLT_MAX; @@ -93,6 +96,11 @@ class Paragraph { void AddRunsToLineBreaker(const std::string& rootdir = ""); + void JustifyLine(std::vector& buffers, + std::vector& buffer_sizes, + int word_count, + size_t character_index); + void PaintDecorations(SkCanvas* canvas, double x, double y, diff --git a/engine/src/flutter/src/paragraph_style.h b/engine/src/flutter/src/paragraph_style.h index e1730287a61..45f1dd745d6 100644 --- a/engine/src/flutter/src/paragraph_style.h +++ b/engine/src/flutter/src/paragraph_style.h @@ -32,7 +32,7 @@ class ParagraphStyle { FontStyle font_style = FontStyle::normal; std::string font_family = ""; double font_size = 14; - int max_lines = 1; + size_t max_lines = 1; double line_height = 1.0; std::string ellipsis; }; diff --git a/engine/src/flutter/src/styled_runs.h b/engine/src/flutter/src/styled_runs.h index 8b757658a44..4942b9cc20a 100644 --- a/engine/src/flutter/src/styled_runs.h +++ b/engine/src/flutter/src/styled_runs.h @@ -60,7 +60,10 @@ class StyledRuns { FRIEND_TEST(RenderTest, RainbowParagraph); FRIEND_TEST(RenderTest, DefaultStyleParagraph); FRIEND_TEST(RenderTest, BoldParagraph); - FRIEND_TEST(RenderTest, LinebreakParagraph); + FRIEND_TEST(RenderTest, LeftAlignParagraph); + FRIEND_TEST(RenderTest, RightAlignParagraph); + FRIEND_TEST(RenderTest, CenterAlignParagraph); + FRIEND_TEST(RenderTest, JustifyAlignParagraph); FRIEND_TEST(RenderTest, ItalicsParagraph); struct IndexedRun { diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 463d18e5b00..e18cc23a784 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -252,28 +252,132 @@ TEST_F(RenderTest, BoldParagraph) { ASSERT_TRUE(Snapshot()); } -TEST_F(RenderTest, LinebreakParagraph) { +TEST_F(RenderTest, LeftAlignParagraph) { const char* text = "This is a very long sentence to test if the text will properly wrap " "around and go to the next line. Sometimes, short sentence. Longer " - "sentences are okay too because they are nessecary. Very short." + "sentences are okay too because they are nessecary. Very short. " + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum. " + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum."; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + paragraph_style.max_lines = 14; + paragraph_style.text_align = TextAlign::left; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.font_size = 26; + text_style.letter_spacing = 1; + text_style.word_spacing = 5; + text_style.color = SK_ColorBLACK; + text_style.height = 1.15; + text_style.decoration = txt::TextDecoration(0x1); + text_style.decoration_color = SK_ColorBLACK; + builder.PushStyle(text_style); + + builder.AddText(u16_text); + + builder.Pop(); + + auto paragraph = builder.Build(); + paragraph->Layout(GetTestCanvasWidth() - 100, txt::GetFontDir()); + + paragraph->Paint(GetCanvas(), 0, 0); + ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); + for (size_t i = 0; i < u16_text.length(); i++) { + ASSERT_EQ(paragraph->text_[i], u16_text[i]); + } + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].style().color, text_style.color); + ASSERT_TRUE(Snapshot()); +} + +TEST_F(RenderTest, RightAlignParagraph) { + const char* text = "This is a very long sentence to test if the text will properly wrap " "around and go to the next line. Sometimes, short sentence. Longer " - "sentences are okay too because they are nessecary. Very short." + "sentences are okay too because they are nessecary. Very short. " "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " - "mollit anim id est laborum." + "mollit anim id est laborum. " "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " - "mollit anim id est laborum." + "mollit anim id est laborum."; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + paragraph_style.max_lines = 14; + paragraph_style.text_align = TextAlign::right; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.font_size = 26; + text_style.letter_spacing = 1; + text_style.word_spacing = 5; + text_style.color = SK_ColorBLACK; + text_style.height = 1.15; + text_style.decoration = txt::TextDecoration(0x1); + text_style.decoration_color = SK_ColorBLACK; + builder.PushStyle(text_style); + + builder.AddText(u16_text); + + builder.Pop(); + + auto paragraph = builder.Build(); + paragraph->Layout(GetTestCanvasWidth() - 100, txt::GetFontDir()); + + paragraph->Paint(GetCanvas(), 0, 0); + ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); + for (size_t i = 0; i < u16_text.length(); i++) { + ASSERT_EQ(paragraph->text_[i], u16_text[i]); + } + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].style().color, text_style.color); + ASSERT_TRUE(Snapshot()); +} + +TEST_F(RenderTest, CenterAlignParagraph) { + const char* text = + "This is a very long sentence to test if the text will properly wrap " + "around and go to the next line. Sometimes, short sentence. Longer " + "sentences are okay too because they are nessecary. Very short. " + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum. " "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " @@ -292,8 +396,8 @@ TEST_F(RenderTest, LinebreakParagraph) { txt::TextStyle text_style; text_style.font_size = 26; - // Letter spacing not yet implemented - text_style.letter_spacing = 0; + text_style.letter_spacing = 1; + text_style.word_spacing = 5; text_style.color = SK_ColorBLACK; text_style.height = 1.15; text_style.decoration = txt::TextDecoration(0x1); @@ -307,8 +411,64 @@ TEST_F(RenderTest, LinebreakParagraph) { auto paragraph = builder.Build(); paragraph->Layout(GetTestCanvasWidth() - 100, txt::GetFontDir()); - paragraph->Paint(GetCanvas(), 0, 30.0); + paragraph->Paint(GetCanvas(), 0, 0); + ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); + for (size_t i = 0; i < u16_text.length(); i++) { + ASSERT_EQ(paragraph->text_[i], u16_text[i]); + } + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].style().color, text_style.color); + ASSERT_TRUE(Snapshot()); +} +TEST_F(RenderTest, JustifyAlignParagraph) { + const char* text = + "This is a very long sentence to test if the text will properly wrap " + "around and go to the next line. Sometimes, short sentence. Longer " + "sentences are okay too because they are nessecary. Very short. " + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum. " + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum."; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + paragraph_style.max_lines = 14; + paragraph_style.text_align = TextAlign::justify; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.font_size = 26; + text_style.letter_spacing = 1; + text_style.word_spacing = 5; + text_style.color = SK_ColorBLACK; + text_style.height = 1.15; + text_style.decoration = txt::TextDecoration(0x1); + text_style.decoration_color = SK_ColorBLACK; + builder.PushStyle(text_style); + + builder.AddText(u16_text); + + builder.Pop(); + + auto paragraph = builder.Build(); + paragraph->Layout(GetTestCanvasWidth() - 100, txt::GetFontDir()); + + paragraph->Paint(GetCanvas(), 0, 0); ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); for (size_t i = 0; i < u16_text.length(); i++) { ASSERT_EQ(paragraph->text_[i], u16_text[i]); @@ -321,7 +481,7 @@ TEST_F(RenderTest, LinebreakParagraph) { } TEST_F(RenderTest, ItalicsParagraph) { - const char* text = "I am Italicized!"; + const char* text = "I am Italicized! "; auto icu_text = icu::UnicodeString::fromUTF8(text); std::u16string u16_text(icu_text.getBuffer(), icu_text.getBuffer() + icu_text.length()); diff --git a/engine/src/flutter/tests/txt/render_test.cc b/engine/src/flutter/tests/txt/render_test.cc index 68b45e98ac4..4b87a06bbb9 100644 --- a/engine/src/flutter/tests/txt/render_test.cc +++ b/engine/src/flutter/tests/txt/render_test.cc @@ -47,7 +47,7 @@ bool RenderTest::Snapshot() { } size_t RenderTest::GetTestCanvasWidth() const { - return 800; + return 1000; } size_t RenderTest::GetTestCanvasHeight() const { From adcdcc19a8d71acacc07e04ea2a14be580dd5684 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Mon, 26 Jun 2017 09:39:09 -0700 Subject: [PATCH 303/364] Reorganize text alignment code location and add unit tests. Change-Id: I3ccfb03230050c4c0f8ae4b7d0c73bf6f3b685ae --- engine/src/flutter/src/paragraph.cc | 53 +++--- engine/src/flutter/src/text_style.cc | 2 +- engine/src/flutter/src/text_style.h | 2 +- .../flutter/tests/txt/paragraph_unittests.cc | 175 ++++++++++++++++-- 4 files changed, 195 insertions(+), 37 deletions(-) diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 549de3af7ba..dff8b5f4497 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -180,10 +180,36 @@ void Paragraph::Layout(double width, std::vector x_queue; size_t character_index = 0; - auto flush = [this, &x_queue, &y]() -> void { + auto postprocess_line = [this, &x_queue, &y]() -> void { + size_t record_index = 0; for (size_t i = 0; i < x_queue.size(); ++i) { - records_[records_.size() - (x_queue.size() - i)].SetOffset( - SkPoint::Make(x_queue[i], y)); + record_index = records_.size() - (x_queue.size() - i); + records_[record_index].SetOffset(SkPoint::Make(x_queue[i], y)); + // TODO(garyq): Fix alignment for paragraphs with multiple styles per + // line. + switch (paragraph_style_.text_align) { + case TextAlign::left: + break; + case TextAlign::right: { + records_[record_index].SetOffset(SkPoint::Make( + records_[record_index].offset().x() + width_ - + breaker_.getWidths()[records_[record_index].line()], + records_[record_index].offset().y())); + break; + } + case TextAlign::center: { + records_[record_index].SetOffset(SkPoint::Make( + records_[record_index].offset().x() + + (width_ - + breaker_.getWidths()[records_[record_index].line()]) / + 2, + records_[record_index].offset().y())); + break; + } + case TextAlign::justify: { + break; + } + } } x_queue.clear(); }; @@ -304,7 +330,7 @@ void Paragraph::Layout(double width, y += max_line_spacing + prev_max_descent; prev_max_descent = max_descent; line_widths_.push_back(line_width); - flush(); + postprocess_line(); max_line_spacing = 0.0f; max_descent = 0.0f; @@ -324,7 +350,7 @@ void Paragraph::Layout(double width, } } y += max_line_spacing; - flush(); + postprocess_line(); if (line_width != 0) line_widths_.push_back(line_width); @@ -406,23 +432,6 @@ void Paragraph::Paint(SkCanvas* canvas, double x, double y) { SkPaint paint; paint.setColor(record.style().color); SkPoint offset = record.offset(); - // TODO(garyq): Fix alignment for paragraphs with multiple styles per line. - switch (paragraph_style_.text_align) { - case TextAlign::left: - break; - case TextAlign::right: { - offset.offset(width_ - breaker_.getWidths()[record.line()], 0); - break; - } - case TextAlign::center: { - offset.offset((width_ - breaker_.getWidths()[record.line()]) / 2, 0); - break; - } - case TextAlign::justify: { - // Justify is performed in the Layout(). - break; - } - } canvas->drawTextBlob(record.text(), x + offset.x(), y + offset.y(), paint); PaintDecorations(canvas, x + offset.x(), y + offset.y(), record.style(), record.metrics(), record.text()); diff --git a/engine/src/flutter/src/text_style.cc b/engine/src/flutter/src/text_style.cc index bacb9a55fea..692176c6873 100644 --- a/engine/src/flutter/src/text_style.cc +++ b/engine/src/flutter/src/text_style.cc @@ -21,7 +21,7 @@ namespace txt { -bool TextStyle::equals(TextStyle& other) { +bool TextStyle::equals(const TextStyle& other) const { if (color != other.color) return false; if (font_weight != other.font_weight) diff --git a/engine/src/flutter/src/text_style.h b/engine/src/flutter/src/text_style.h index 23c2043b0a0..7692c7a58c3 100644 --- a/engine/src/flutter/src/text_style.h +++ b/engine/src/flutter/src/text_style.h @@ -43,7 +43,7 @@ class TextStyle { double word_spacing = 0.0; double height = 1.0; - bool equals(TextStyle& other); + bool equals(const TextStyle& other) const; }; } // namespace txt diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index e18cc23a784..d93ea32e3ed 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -225,7 +225,6 @@ TEST_F(RenderTest, BoldParagraph) { txt::TextStyle text_style; text_style.font_size = 60; - // Letter spacing not yet implemented text_style.letter_spacing = 10; text_style.font_weight = txt::FontWeight::w700; text_style.fake_bold = true; @@ -285,8 +284,8 @@ TEST_F(RenderTest, LeftAlignParagraph) { text_style.letter_spacing = 1; text_style.word_spacing = 5; text_style.color = SK_ColorBLACK; - text_style.height = 1.15; - text_style.decoration = txt::TextDecoration(0x1); + text_style.height = 1; + text_style.decoration = txt::TextDecoration(0x0); text_style.decoration_color = SK_ColorBLACK; builder.PushStyle(text_style); @@ -305,7 +304,36 @@ TEST_F(RenderTest, LeftAlignParagraph) { ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); - ASSERT_EQ(paragraph->records_[0].style().color, text_style.color); + ASSERT_EQ(paragraph->records_.size(), paragraph_style.max_lines); + double expected_y = 18.484375; + + ASSERT_TRUE(paragraph->records_[0].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y); + expected_y += 30.46875; + ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().x(), 0); + + ASSERT_TRUE(paragraph->records_[1].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[1].offset().y(), expected_y); + expected_y += 30.46875; + ASSERT_DOUBLE_EQ(paragraph->records_[1].offset().x(), 0); + + ASSERT_TRUE(paragraph->records_[2].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y); + expected_y += 30.46875; + ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().x(), 0); + + ASSERT_TRUE(paragraph->records_[3].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[3].offset().y(), expected_y); + expected_y += 30.46875 * 10; + ASSERT_DOUBLE_EQ(paragraph->records_[3].offset().x(), 0); + + ASSERT_TRUE(paragraph->records_[13].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[13].offset().y(), expected_y); + ASSERT_DOUBLE_EQ(paragraph->records_[13].offset().x(), 0); + + ASSERT_EQ(paragraph_style.text_align, + paragraph->GetParagraphStyle().text_align); + ASSERT_TRUE(Snapshot()); } @@ -342,8 +370,8 @@ TEST_F(RenderTest, RightAlignParagraph) { text_style.letter_spacing = 1; text_style.word_spacing = 5; text_style.color = SK_ColorBLACK; - text_style.height = 1.15; - text_style.decoration = txt::TextDecoration(0x1); + text_style.height = 1; + text_style.decoration = txt::TextDecoration(0x0); text_style.decoration_color = SK_ColorBLACK; builder.PushStyle(text_style); @@ -362,7 +390,51 @@ TEST_F(RenderTest, RightAlignParagraph) { ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); - ASSERT_EQ(paragraph->records_[0].style().color, text_style.color); + ASSERT_EQ(paragraph->records_.size(), paragraph_style.max_lines); + double expected_y = 18.484375; + + ASSERT_TRUE(paragraph->records_[0].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y); + expected_y += 30.46875; + ASSERT_DOUBLE_EQ( + paragraph->records_[0].offset().x(), + paragraph->width_ - + paragraph->breaker_.getWidths()[paragraph->records_[0].line()]); + + ASSERT_TRUE(paragraph->records_[1].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[1].offset().y(), expected_y); + expected_y += 30.46875; + ASSERT_DOUBLE_EQ( + paragraph->records_[1].offset().x(), + paragraph->width_ - + paragraph->breaker_.getWidths()[paragraph->records_[1].line()]); + + ASSERT_TRUE(paragraph->records_[2].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y); + expected_y += 30.46875; + ASSERT_DOUBLE_EQ( + paragraph->records_[2].offset().x(), + paragraph->width_ - + paragraph->breaker_.getWidths()[paragraph->records_[2].line()]); + + ASSERT_TRUE(paragraph->records_[3].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[3].offset().y(), expected_y); + expected_y += 30.46875 * 10; + ASSERT_DOUBLE_EQ( + paragraph->records_[3].offset().x(), + paragraph->width_ - + paragraph->breaker_.getWidths()[paragraph->records_[3].line()]); + + ASSERT_TRUE(paragraph->records_[13].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[13].offset().y(), expected_y); + ASSERT_DOUBLE_EQ( + paragraph->records_[13].offset().x(), + paragraph->width_ - + paragraph->breaker_.getWidths()[paragraph->records_[13].line()]); + + ASSERT_EQ(paragraph_style.text_align, + paragraph->GetParagraphStyle().text_align); + ASSERT_TRUE(Snapshot()); } @@ -399,8 +471,8 @@ TEST_F(RenderTest, CenterAlignParagraph) { text_style.letter_spacing = 1; text_style.word_spacing = 5; text_style.color = SK_ColorBLACK; - text_style.height = 1.15; - text_style.decoration = txt::TextDecoration(0x1); + text_style.height = 1; + text_style.decoration = txt::TextDecoration(0x0); text_style.decoration_color = SK_ColorBLACK; builder.PushStyle(text_style); @@ -419,7 +491,55 @@ TEST_F(RenderTest, CenterAlignParagraph) { ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); - ASSERT_EQ(paragraph->records_[0].style().color, text_style.color); + ASSERT_EQ(paragraph->records_.size(), paragraph_style.max_lines); + double expected_y = 18.484375; + + ASSERT_TRUE(paragraph->records_[0].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y); + expected_y += 30.46875; + ASSERT_DOUBLE_EQ( + paragraph->records_[0].offset().x(), + (paragraph->width_ - + paragraph->breaker_.getWidths()[paragraph->records_[0].line()]) / + 2); + + ASSERT_TRUE(paragraph->records_[1].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[1].offset().y(), expected_y); + expected_y += 30.46875; + ASSERT_DOUBLE_EQ( + paragraph->records_[1].offset().x(), + (paragraph->width_ - + paragraph->breaker_.getWidths()[paragraph->records_[1].line()]) / + 2); + + ASSERT_TRUE(paragraph->records_[2].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y); + expected_y += 30.46875; + ASSERT_EQ(paragraph->records_[2].offset().x(), + (paragraph->width_ - + paragraph->breaker_.getWidths()[paragraph->records_[2].line()]) / + 2); + + ASSERT_TRUE(paragraph->records_[3].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[3].offset().y(), expected_y); + expected_y += 30.46875 * 10; + ASSERT_DOUBLE_EQ( + paragraph->records_[3].offset().x(), + (paragraph->width_ - + paragraph->breaker_.getWidths()[paragraph->records_[3].line()]) / + 2); + + ASSERT_TRUE(paragraph->records_[13].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[13].offset().y(), expected_y); + ASSERT_DOUBLE_EQ( + paragraph->records_[13].offset().x(), + (paragraph->width_ - + paragraph->breaker_.getWidths()[paragraph->records_[13].line()]) / + 2); + + ASSERT_EQ(paragraph_style.text_align, + paragraph->GetParagraphStyle().text_align); + ASSERT_TRUE(Snapshot()); } @@ -456,8 +576,8 @@ TEST_F(RenderTest, JustifyAlignParagraph) { text_style.letter_spacing = 1; text_style.word_spacing = 5; text_style.color = SK_ColorBLACK; - text_style.height = 1.15; - text_style.decoration = txt::TextDecoration(0x1); + text_style.height = 1; + text_style.decoration = txt::TextDecoration(0x0); text_style.decoration_color = SK_ColorBLACK; builder.PushStyle(text_style); @@ -476,7 +596,36 @@ TEST_F(RenderTest, JustifyAlignParagraph) { ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); - ASSERT_EQ(paragraph->records_[0].style().color, text_style.color); + ASSERT_EQ(paragraph->records_.size(), paragraph_style.max_lines); + double expected_y = 18.484375; + + ASSERT_TRUE(paragraph->records_[0].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().y(), expected_y); + expected_y += 30.46875; + ASSERT_DOUBLE_EQ(paragraph->records_[0].offset().x(), 0); + + ASSERT_TRUE(paragraph->records_[1].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[1].offset().y(), expected_y); + expected_y += 30.46875; + ASSERT_DOUBLE_EQ(paragraph->records_[1].offset().x(), 0); + + ASSERT_TRUE(paragraph->records_[2].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().y(), expected_y); + expected_y += 30.46875; + ASSERT_DOUBLE_EQ(paragraph->records_[2].offset().x(), 0); + + ASSERT_TRUE(paragraph->records_[3].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[3].offset().y(), expected_y); + expected_y += 30.46875 * 10; + ASSERT_DOUBLE_EQ(paragraph->records_[3].offset().x(), 0); + + ASSERT_TRUE(paragraph->records_[13].style().equals(text_style)); + ASSERT_DOUBLE_EQ(paragraph->records_[13].offset().y(), expected_y); + ASSERT_DOUBLE_EQ(paragraph->records_[13].offset().x(), 0); + + ASSERT_EQ(paragraph_style.text_align, + paragraph->GetParagraphStyle().text_align); + ASSERT_TRUE(Snapshot()); } From ea45f66608c633fd9777b3db850aada81f9598aa Mon Sep 17 00:00:00 2001 From: George Kulakowski Date: Wed, 28 Jun 2017 09:45:52 -0700 Subject: [PATCH 304/364] Add PATENTS file Change-Id: Ie25d2b4caa6a805ce76a288b41804700d7d37c5a --- engine/src/flutter/PATENTS | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 engine/src/flutter/PATENTS diff --git a/engine/src/flutter/PATENTS b/engine/src/flutter/PATENTS new file mode 100644 index 00000000000..2746e78d1be --- /dev/null +++ b/engine/src/flutter/PATENTS @@ -0,0 +1,22 @@ +Additional IP Rights Grant (Patents) + +"This implementation" means the copyrightable works distributed by +Google as part of the Fuchsia project. + +Google hereby grants to you a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable (except as stated in this +section) patent license to make, have made, use, offer to sell, sell, +import, transfer, and otherwise run, modify and propagate the contents +of this implementation of Fuchsia, where such license applies only to +those patent claims, both currently owned by Google and acquired in +the future, licensable by Google that are necessarily infringed by +this implementation. This grant does not include claims that would be +infringed only as a consequence of further modification of this +implementation. If you or your agent or exclusive licensee institute +or order or agree to the institution of patent litigation or any other +patent enforcement activity against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that this +implementation of Fuchsia constitutes direct or contributory patent +infringement, or inducement of patent infringement, then any patent +rights granted to you under this License for this implementation of +Fuchsia shall terminate as of the date such litigation is filed. From f716e8115c46def41ff7bfbd6420e119abfb2520 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Tue, 27 Jun 2017 17:14:01 -0700 Subject: [PATCH 305/364] Add benchmarking. Change-Id: I92b8d1d27d5d6b79a831853446e83086fa56a133 --- engine/src/flutter/benchmarks/BUILD.gn | 45 ++++ .../benchmarks/font_collection_benchmarks.cc | 49 +++++ .../benchmarks/paragraph_benchmarks.cc | 116 +++++++++++ .../paragraph_builder_benchmarks.cc | 194 ++++++++++++++++++ .../benchmarks/txt_run_all_benchmarks.cc | 41 ++++ engine/src/flutter/benchmarks/utils.cc | 43 ++++ engine/src/flutter/benchmarks/utils.h | 31 +++ engine/src/flutter/src/paragraph.cc | 3 +- engine/src/flutter/src/paragraph.h | 1 + engine/src/flutter/tests/txt/utils.cc | 8 +- engine/src/flutter/tests/txt/utils.h | 2 +- 11 files changed, 527 insertions(+), 6 deletions(-) create mode 100644 engine/src/flutter/benchmarks/BUILD.gn create mode 100644 engine/src/flutter/benchmarks/font_collection_benchmarks.cc create mode 100644 engine/src/flutter/benchmarks/paragraph_benchmarks.cc create mode 100644 engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc create mode 100644 engine/src/flutter/benchmarks/txt_run_all_benchmarks.cc create mode 100644 engine/src/flutter/benchmarks/utils.cc create mode 100644 engine/src/flutter/benchmarks/utils.h diff --git a/engine/src/flutter/benchmarks/BUILD.gn b/engine/src/flutter/benchmarks/BUILD.gn new file mode 100644 index 00000000000..7a3f14d7d73 --- /dev/null +++ b/engine/src/flutter/benchmarks/BUILD.gn @@ -0,0 +1,45 @@ +# Copyright 2017 Google, Inc. +# +# 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. + +executable("benchmarks") { + output_name = "txt_benchmarks" + + include_dirs = [ + "//lib/txt/src", + "//lib/txt/include", + "//third_party/icu/source", + ] + + sources = [ + "font_collection_benchmarks.cc", + "paragraph_benchmarks.cc", + "paragraph_builder_benchmarks.cc", + "txt_run_all_benchmarks.cc", + "utils.cc", + "utils.h", + ] + + deps = [ + "//dart/runtime:libdart_jit", # Logging + "//flutter/fml", + "//lib/txt/shims", + "//lib/txt", + "//build/secondary/testing/benchmark", + "//third_party/skia", + "//third_party/harfbuzz", + "//lib/txt/libs/minikin", + ] + + +} diff --git a/engine/src/flutter/benchmarks/font_collection_benchmarks.cc b/engine/src/flutter/benchmarks/font_collection_benchmarks.cc new file mode 100644 index 00000000000..10751e324fa --- /dev/null +++ b/engine/src/flutter/benchmarks/font_collection_benchmarks.cc @@ -0,0 +1,49 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 "third_party/benchmark/include/benchmark/benchmark_api.h" + +#include "lib/ftl/command_line.h" +#include "lib/ftl/logging.h" +#include "lib/txt/src/font_collection.h" +#include "utils.h" + +namespace txt { + +// Include this fake bench first because the first benchmark produces +// inconsistent times. +static void BM_FAKE_BENCHMARK(benchmark::State& state) { + while (state.KeepRunning()) { + continue; + } +} +BENCHMARK(BM_FAKE_BENCHMARK); + +static void BM_FontCollectionInit(benchmark::State& state) { + while (state.KeepRunning()) { + FontCollection::GetFontCollection(txt::GetFontDir()); + } +} +BENCHMARK(BM_FontCollectionInit); + +static void BM_FontCollectionGetMinikinFontCollectionForFamily(benchmark::State& state) { + while (state.KeepRunning()) { + FontCollection::GetFontCollection(txt::GetFontDir()).GetMinikinFontCollectionForFamily("Roboto"); + } +} +BENCHMARK(BM_FontCollectionGetMinikinFontCollectionForFamily); + +} // namespace txt diff --git a/engine/src/flutter/benchmarks/paragraph_benchmarks.cc b/engine/src/flutter/benchmarks/paragraph_benchmarks.cc new file mode 100644 index 00000000000..34d44ad5576 --- /dev/null +++ b/engine/src/flutter/benchmarks/paragraph_benchmarks.cc @@ -0,0 +1,116 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 "third_party/benchmark/include/benchmark/benchmark_api.h" + +#include "lib/ftl/command_line.h" +#include "lib/ftl/logging.h" +#include "lib/txt/src/font_style.h" +#include "lib/txt/src/font_weight.h" +#include "lib/txt/src/paragraph.h" +#include "lib/txt/src/paragraph_builder.h" +#include "lib/txt/src/text_align.h" +#include "third_party/icu/source/common/unicode/unistr.h" +#include "third_party/skia/include/core/SkColor.h" +#include "utils.h" + +namespace txt { + +static void BM_ParagraphShortLayout(benchmark::State& state) { + const char* text = "Hello World"; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + while (state.KeepRunning()) { + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; + + builder.PushStyle(text_style); + builder.AddText(u16_text); + builder.Pop(); + auto paragraph = builder.Build(); + paragraph->Layout(300, txt::GetFontDir(), true); + } +} +BENCHMARK(BM_ParagraphShortLayout); + +static void BM_ParagraphLongLayout(benchmark::State& state) { + const char* text = + "This is a very long sentence to test if the text will properly wrap " + "around and go to the next line. Sometimes, short sentence. Longer " + "sentences are okay too because they are necessary. Very short. " + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum. " + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum."; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; + + builder.PushStyle(text_style); + builder.AddText(u16_text); + builder.Pop(); + auto paragraph = builder.Build(); + while (state.KeepRunning()) { + paragraph->Layout(300, txt::GetFontDir(), true); + } +} +BENCHMARK(BM_ParagraphLongLayout); + +static void BM_ParagraphManyStylesLayout(benchmark::State& state) { + const char* text = "A short sentence. "; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + while (state.KeepRunning()) { + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; + + for (int i = 0; i < 100; ++i) { + builder.PushStyle(text_style); + builder.AddText(u16_text); + } + auto paragraph = builder.Build(); + paragraph->Layout(300, txt::GetFontDir(), true); + } +} +BENCHMARK(BM_ParagraphManyStylesLayout); + +} // namespace txt diff --git a/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc b/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc new file mode 100644 index 00000000000..88da483736c --- /dev/null +++ b/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc @@ -0,0 +1,194 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 "third_party/benchmark/include/benchmark/benchmark_api.h" + +#include "lib/ftl/logging.h" +#include "lib/txt/src/font_style.h" +#include "lib/txt/src/font_weight.h" +#include "lib/txt/src/paragraph.h" +#include "lib/txt/src/paragraph_builder.h" +#include "lib/txt/src/text_align.h" +#include "third_party/icu/source/common/unicode/unistr.h" +#include "third_party/skia/include/core/SkColor.h" + +namespace txt { + +static void BM_ParagraphBuilderConstruction(benchmark::State& state) { + txt::ParagraphStyle paragraph_style; + while (state.KeepRunning()) { + txt::ParagraphBuilder builder(paragraph_style); + } +} +BENCHMARK(BM_ParagraphBuilderConstruction); + +static void BM_ParagraphBuilderPushStyle(benchmark::State& state) { + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; + while (state.KeepRunning()) { + builder.PushStyle(text_style); + } +} +BENCHMARK(BM_ParagraphBuilderPushStyle); + +static void BM_ParagraphBuilderPushPop(benchmark::State& state) { + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; + while (state.KeepRunning()) { + builder.PushStyle(text_style); + builder.Pop(); + } +} +BENCHMARK(BM_ParagraphBuilderPushPop); + +static void BM_ParagraphBuilderAddTextString(benchmark::State& state) { + std::string text = "Hello World"; + + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + while (state.KeepRunning()) { + builder.AddText(text); + } +} +BENCHMARK(BM_ParagraphBuilderAddTextString); + +static void BM_ParagraphBuilderAddTextChar(benchmark::State& state) { + const char* text = "Hello World"; + + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + while (state.KeepRunning()) { + builder.AddText(text); + } +} +BENCHMARK(BM_ParagraphBuilderAddTextChar); + +static void BM_ParagraphBuilderAddTextU16stringShort(benchmark::State& state) { + const char* text = "H"; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + while (state.KeepRunning()) { + builder.AddText(u16_text); + } +} +BENCHMARK(BM_ParagraphBuilderAddTextU16stringShort); + +static void BM_ParagraphBuilderAddTextU16stringLong(benchmark::State& state) { + const char* text = + "This is a very long sentence to test if the text will properly wrap " + "around and go to the next line. Sometimes, short sentence. Longer " + "sentences are okay too because they are necessary. Very short. " + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum. " + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum."; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + while (state.KeepRunning()) { + builder.AddText(u16_text); + } +} +BENCHMARK(BM_ParagraphBuilderAddTextU16stringLong); + +static void BM_ParagraphBuilderShortParagraphConstruct( + benchmark::State& state) { + const char* text = "Hello World"; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; + + while (state.KeepRunning()) { + builder.PushStyle(text_style); + builder.AddText(u16_text); + builder.Pop(); + auto paragraph = builder.Build(); + } +} +BENCHMARK(BM_ParagraphBuilderShortParagraphConstruct); + +static void BM_ParagraphBuilderLongParagraphConstruct(benchmark::State& state) { + const char* text = + "This is a very long sentence to test if the text will properly wrap " + "around and go to the next line. Sometimes, short sentence. Longer " + "sentences are okay too because they are necessary. Very short. " + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum. " + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod " + "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " + "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " + "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " + "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " + "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " + "mollit anim id est laborum."; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + txt::ParagraphBuilder builder(paragraph_style); + + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; + + while (state.KeepRunning()) { + builder.PushStyle(text_style); + builder.AddText(u16_text); + builder.Pop(); + auto paragraph = builder.Build(); + } +} +BENCHMARK(BM_ParagraphBuilderLongParagraphConstruct); + +} // namespace txt diff --git a/engine/src/flutter/benchmarks/txt_run_all_benchmarks.cc b/engine/src/flutter/benchmarks/txt_run_all_benchmarks.cc new file mode 100644 index 00000000000..cc5bfc36457 --- /dev/null +++ b/engine/src/flutter/benchmarks/txt_run_all_benchmarks.cc @@ -0,0 +1,41 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 "third_party/benchmark/include/benchmark/benchmark_api.h" + +#include "flutter/fml/icu_util.h" +#include "lib/ftl/logging.h" +#include "utils.h" + +// We will use a custom main to allow custom font directories for consistency. +int main(int argc, char** argv) { + ::benchmark::Initialize(&argc, argv); + ftl::CommandLine cmd = ftl::CommandLineFromArgcArgv(argc, argv); + txt::SetCommandLine(cmd); + std::string dir = txt::GetCommandLineForProcess().GetOptionValueWithDefault( + "font-directory", ""); + txt::SetFontDir(dir); + if (txt::GetFontDir().length() <= 0) { + FTL_LOG(ERROR) << "Font directory must be specified with " + "--font-directoy=\"\" to run this test."; + return EXIT_FAILURE; + } + FTL_DCHECK(txt::GetFontDir().length() > 0); + + fml::icu::InitializeICU(); + + ::benchmark::RunSpecifiedBenchmarks(); +} \ No newline at end of file diff --git a/engine/src/flutter/benchmarks/utils.cc b/engine/src/flutter/benchmarks/utils.cc new file mode 100644 index 00000000000..6ec90c2a5cd --- /dev/null +++ b/engine/src/flutter/benchmarks/utils.cc @@ -0,0 +1,43 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 + +#include "lib/ftl/command_line.h" +#include "lib/txt/tests/txt/utils.h" + +namespace txt { + +static std::string gFontDir; +static ftl::CommandLine gCommandLine; + +const std::string GetFontDir() { + return gFontDir; +} + +void SetFontDir(const std::string& dir) { + gFontDir = dir; +} + +const ftl::CommandLine& GetCommandLineForProcess() { + return gCommandLine; +} + +void SetCommandLine(ftl::CommandLine cmd) { + gCommandLine = std::move(cmd); +} + +} // namespace txt diff --git a/engine/src/flutter/benchmarks/utils.h b/engine/src/flutter/benchmarks/utils.h new file mode 100644 index 00000000000..5b6db127180 --- /dev/null +++ b/engine/src/flutter/benchmarks/utils.h @@ -0,0 +1,31 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 + +#include "lib/ftl/command_line.h" + +namespace txt { + +const std::string GetFontDir(); + +void SetFontDir(const std::string& dir); + +const ftl::CommandLine& GetCommandLineForProcess(); + +void SetCommandLine(ftl::CommandLine cmd); + +} // namespace txt diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index dff8b5f4497..0dda95b66a6 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -140,10 +140,11 @@ void Paragraph::AddRunsToLineBreaker(const std::string& rootdir) { void Paragraph::Layout(double width, const std::string& rootdir, + bool force, const double x_offset, const double y_offset) { // Do not allow calling layout multiple times without changing anything. - if (!needs_layout_) + if (!needs_layout_ && !force) return; needs_layout_ = false; diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index f71b16be11a..b4b90a4ee91 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -40,6 +40,7 @@ class Paragraph { void Layout(double width, const std::string& rootdir = "", + bool force = false, const double x_offset = 0.0, const double y_offset = 0.0); diff --git a/engine/src/flutter/tests/txt/utils.cc b/engine/src/flutter/tests/txt/utils.cc index 3f853b8a926..6ec90c2a5cd 100644 --- a/engine/src/flutter/tests/txt/utils.cc +++ b/engine/src/flutter/tests/txt/utils.cc @@ -21,15 +21,15 @@ namespace txt { -static std::string gFontdir; +static std::string gFontDir; static ftl::CommandLine gCommandLine; const std::string GetFontDir() { - return gFontdir; + return gFontDir; } -void SetFontDir(std::string& dir) { - gFontdir = dir; +void SetFontDir(const std::string& dir) { + gFontDir = dir; } const ftl::CommandLine& GetCommandLineForProcess() { diff --git a/engine/src/flutter/tests/txt/utils.h b/engine/src/flutter/tests/txt/utils.h index ed42b820739..5b6db127180 100644 --- a/engine/src/flutter/tests/txt/utils.h +++ b/engine/src/flutter/tests/txt/utils.h @@ -22,7 +22,7 @@ namespace txt { const std::string GetFontDir(); -void SetFontDir(std::string& dir); +void SetFontDir(const std::string& dir); const ftl::CommandLine& GetCommandLineForProcess(); From 704aa0d2bf1f9b6d0bba9ef23349080f7720966c Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Wed, 28 Jun 2017 11:30:32 -0700 Subject: [PATCH 306/364] Only obtain new font if font has changed. Change-Id: I9a6316854e13ff5f01a34bbfca8750d223a90af8 --- .../benchmarks/font_collection_benchmarks.cc | 6 ++++-- engine/src/flutter/src/paragraph.cc | 14 ++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/benchmarks/font_collection_benchmarks.cc b/engine/src/flutter/benchmarks/font_collection_benchmarks.cc index 10751e324fa..99eb26eecfd 100644 --- a/engine/src/flutter/benchmarks/font_collection_benchmarks.cc +++ b/engine/src/flutter/benchmarks/font_collection_benchmarks.cc @@ -39,9 +39,11 @@ static void BM_FontCollectionInit(benchmark::State& state) { } BENCHMARK(BM_FontCollectionInit); -static void BM_FontCollectionGetMinikinFontCollectionForFamily(benchmark::State& state) { +static void BM_FontCollectionGetMinikinFontCollectionForFamily( + benchmark::State& state) { while (state.KeepRunning()) { - FontCollection::GetFontCollection(txt::GetFontDir()).GetMinikinFontCollectionForFamily("Roboto"); + FontCollection::GetFontCollection(txt::GetFontDir()) + .GetMinikinFontCollectionForFamily("Roboto"); } } BENCHMARK(BM_FontCollectionGetMinikinFontCollectionForFamily); diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 0dda95b66a6..fbdc53c6a99 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -214,12 +214,18 @@ void Paragraph::Layout(double width, } x_queue.clear(); }; - + std::shared_ptr collection = nullptr; + std::string prev_font_family = ""; for (size_t run_index = 0; run_index < runs_.size(); ++run_index) { auto run = runs_.GetRun(run_index); - auto collection = - FontCollection::GetFontCollection(rootdir) - .GetMinikinFontCollectionForFamily(run.style.font_family); + + // Only obtain new font family if the font has changed between runs. + if (run.style.font_family != prev_font_family || collection == nullptr) { + collection = + FontCollection::GetFontCollection(rootdir) + .GetMinikinFontCollectionForFamily(run.style.font_family); + } + prev_font_family = run.style.font_family; GetFontAndMinikinPaint(run.style, &font, &minikin_paint); GetPaint(run.style, &paint); From 7e02287cf9dc6f88513249f6928036a43dedd407 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Wed, 28 Jun 2017 18:16:37 -0700 Subject: [PATCH 307/364] Add additional benchmarks and initial bigO checks. Change-Id: I3d2d9186fb187d55319c10260bf7e0d579c65a6f --- engine/src/flutter/benchmarks/BUILD.gn | 2 +- .../benchmarks/paragraph_benchmarks.cc | 139 ++++++++++++++++-- .../paragraph_builder_benchmarks.cc | 14 +- .../benchmarks/styled_runs_benchmarks.cc | 39 +++++ 4 files changed, 170 insertions(+), 24 deletions(-) create mode 100644 engine/src/flutter/benchmarks/styled_runs_benchmarks.cc diff --git a/engine/src/flutter/benchmarks/BUILD.gn b/engine/src/flutter/benchmarks/BUILD.gn index 7a3f14d7d73..3b637cc4c34 100644 --- a/engine/src/flutter/benchmarks/BUILD.gn +++ b/engine/src/flutter/benchmarks/BUILD.gn @@ -25,6 +25,7 @@ executable("benchmarks") { "font_collection_benchmarks.cc", "paragraph_benchmarks.cc", "paragraph_builder_benchmarks.cc", + "styled_runs_benchmarks.cc", "txt_run_all_benchmarks.cc", "utils.cc", "utils.h", @@ -41,5 +42,4 @@ executable("benchmarks") { "//lib/txt/libs/minikin", ] - } diff --git a/engine/src/flutter/benchmarks/paragraph_benchmarks.cc b/engine/src/flutter/benchmarks/paragraph_benchmarks.cc index 34d44ad5576..7a694f6eb51 100644 --- a/engine/src/flutter/benchmarks/paragraph_benchmarks.cc +++ b/engine/src/flutter/benchmarks/paragraph_benchmarks.cc @@ -16,8 +16,12 @@ #include "third_party/benchmark/include/benchmark/benchmark_api.h" +#include #include "lib/ftl/command_line.h" #include "lib/ftl/logging.h" +#include "lib/txt/libs/minikin/LayoutUtils.h" +#include "lib/txt/src/font_collection.h" +#include "lib/txt/src/font_skia.h" #include "lib/txt/src/font_style.h" #include "lib/txt/src/font_weight.h" #include "lib/txt/src/paragraph.h" @@ -35,17 +39,18 @@ static void BM_ParagraphShortLayout(benchmark::State& state) { std::u16string u16_text(icu_text.getBuffer(), icu_text.getBuffer() + icu_text.length()); - while (state.KeepRunning()) { - txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphStyle paragraph_style; - txt::TextStyle text_style; - text_style.color = SK_ColorBLACK; + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; + while (state.KeepRunning()) { + txt::ParagraphBuilder builder(paragraph_style); builder.PushStyle(text_style); builder.AddText(u16_text); builder.Pop(); auto paragraph = builder.Build(); + paragraph->Layout(300, txt::GetFontDir(), true); } } @@ -75,16 +80,17 @@ static void BM_ParagraphLongLayout(benchmark::State& state) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); txt::TextStyle text_style; text_style.color = SK_ColorBLACK; - - builder.PushStyle(text_style); - builder.AddText(u16_text); - builder.Pop(); - auto paragraph = builder.Build(); while (state.KeepRunning()) { + txt::ParagraphBuilder builder(paragraph_style); + + builder.PushStyle(text_style); + builder.AddText(u16_text); + builder.Pop(); + auto paragraph = builder.Build(); + paragraph->Layout(300, txt::GetFontDir(), true); } } @@ -96,13 +102,12 @@ static void BM_ParagraphManyStylesLayout(benchmark::State& state) { std::u16string u16_text(icu_text.getBuffer(), icu_text.getBuffer() + icu_text.length()); + txt::ParagraphStyle paragraph_style; + + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; while (state.KeepRunning()) { - txt::ParagraphStyle paragraph_style; txt::ParagraphBuilder builder(paragraph_style); - - txt::TextStyle text_style; - text_style.color = SK_ColorBLACK; - for (int i = 0; i < 100; ++i) { builder.PushStyle(text_style); builder.AddText(u16_text); @@ -113,4 +118,106 @@ static void BM_ParagraphManyStylesLayout(benchmark::State& state) { } BENCHMARK(BM_ParagraphManyStylesLayout); +static void BM_ParagraphTextBigO(benchmark::State& state) { + std::string text(state.range(0), '-'); + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; + while (state.KeepRunning()) { + txt::ParagraphBuilder builder(paragraph_style); + + builder.PushStyle(text_style); + builder.AddText(u16_text); + builder.Pop(); + auto paragraph = builder.Build(); + + paragraph->Layout(300, txt::GetFontDir(), true); + } + state.SetComplexityN(state.range(0)); +} +BENCHMARK(BM_ParagraphTextBigO) + ->RangeMultiplier(20) + ->Range(1 << 4, 1 << 12) + ->Complexity(benchmark::oN); + +static void BM_ParagraphStylesBigO(benchmark::State& state) { + const char* text = "A short sentence. "; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; + while (state.KeepRunning()) { + txt::ParagraphBuilder builder(paragraph_style); + + for (int i = 0; i < state.range(0); ++i) { + builder.PushStyle(text_style); + builder.AddText(u16_text); + } + auto paragraph = builder.Build(); + paragraph->Layout(300, txt::GetFontDir(), true); + } + state.SetComplexityN(state.range(0)); +} +BENCHMARK(BM_ParagraphStylesBigO) + ->RangeMultiplier(20) + ->Range(1 << 2, 1 << 8) + ->Complexity(benchmark::oN); + +// ----------------------------------------------------------------------------- +// +// The following benchmarks break down the layout function and attempts to time +// each of the components to more finely attribute latency. +// +// ----------------------------------------------------------------------------- + +static void BM_ParagraphMinikinDoLayout(benchmark::State& state) { + std::vector text; + for (uint16_t i = 0; i < 100; ++i) { + text.push_back(i); + } + minikin::FontStyle font; + txt::TextStyle text_style; + text_style.font_family = "Roboto"; + minikin::MinikinPaint paint; + + font = minikin::FontStyle(4, false); + paint.size = text_style.font_size; + paint.letterSpacing = text_style.letter_spacing; + paint.wordSpacing = text_style.word_spacing; + + auto collection = + FontCollection::GetFontCollection(txt::GetFontDir()) + .GetMinikinFontCollectionForFamily(text_style.font_family); + + while (state.KeepRunning()) { + minikin::Layout layout; + layout.doLayout(text.data(), 0, 50, text.size(), 0, font, paint, + collection); + } +} +BENCHMARK(BM_ParagraphMinikinDoLayout); + +static void BM_ParagraphSkTextBlobAlloc(benchmark::State& state) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); + paint.setTextSize(14); + paint.setFakeBoldText(false); + + while (state.KeepRunning()) { + SkTextBlobBuilder builder; + builder.allocRunPos(paint, 100); + } +} +BENCHMARK(BM_ParagraphSkTextBlobAlloc); + } // namespace txt diff --git a/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc b/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc index 88da483736c..e91ba4416d4 100644 --- a/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc +++ b/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc @@ -37,11 +37,11 @@ BENCHMARK(BM_ParagraphBuilderConstruction); static void BM_ParagraphBuilderPushStyle(benchmark::State& state) { txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); txt::TextStyle text_style; text_style.color = SK_ColorBLACK; while (state.KeepRunning()) { + txt::ParagraphBuilder builder(paragraph_style); builder.PushStyle(text_style); } } @@ -64,9 +64,9 @@ static void BM_ParagraphBuilderAddTextString(benchmark::State& state) { std::string text = "Hello World"; txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); while (state.KeepRunning()) { + txt::ParagraphBuilder builder(paragraph_style); builder.AddText(text); } } @@ -76,9 +76,9 @@ static void BM_ParagraphBuilderAddTextChar(benchmark::State& state) { const char* text = "Hello World"; txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); while (state.KeepRunning()) { + txt::ParagraphBuilder builder(paragraph_style); builder.AddText(text); } } @@ -91,9 +91,9 @@ static void BM_ParagraphBuilderAddTextU16stringShort(benchmark::State& state) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); while (state.KeepRunning()) { + txt::ParagraphBuilder builder(paragraph_style); builder.AddText(u16_text); } } @@ -123,9 +123,9 @@ static void BM_ParagraphBuilderAddTextU16stringLong(benchmark::State& state) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); while (state.KeepRunning()) { + txt::ParagraphBuilder builder(paragraph_style); builder.AddText(u16_text); } } @@ -139,12 +139,12 @@ static void BM_ParagraphBuilderShortParagraphConstruct( icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); txt::TextStyle text_style; text_style.color = SK_ColorBLACK; while (state.KeepRunning()) { + txt::ParagraphBuilder builder(paragraph_style); builder.PushStyle(text_style); builder.AddText(u16_text); builder.Pop(); @@ -177,12 +177,12 @@ static void BM_ParagraphBuilderLongParagraphConstruct(benchmark::State& state) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); txt::TextStyle text_style; text_style.color = SK_ColorBLACK; while (state.KeepRunning()) { + txt::ParagraphBuilder builder(paragraph_style); builder.PushStyle(text_style); builder.AddText(u16_text); builder.Pop(); diff --git a/engine/src/flutter/benchmarks/styled_runs_benchmarks.cc b/engine/src/flutter/benchmarks/styled_runs_benchmarks.cc new file mode 100644 index 00000000000..b0531c2da09 --- /dev/null +++ b/engine/src/flutter/benchmarks/styled_runs_benchmarks.cc @@ -0,0 +1,39 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 "third_party/benchmark/include/benchmark/benchmark_api.h" + +#include "lib/ftl/command_line.h" +#include "lib/ftl/logging.h" +#include "lib/txt/src/styled_runs.h" +#include "lib/txt/src/text_style.h" +#include "utils.h" + +namespace txt { + +static void BM_StyledRunsGetRun(benchmark::State& state) { + StyledRuns runs; + TextStyle style; + runs.AddStyle(style); + runs.StartRun(0, 0); + runs.EndRunIfNeeded(11); + while (state.KeepRunning()) { + runs.GetRun(0); + } +} +BENCHMARK(BM_StyledRunsGetRun); + +} // namespace txt From 4ddb034139767b18487620b3eb1923c2142eb539 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Thu, 29 Jun 2017 15:04:54 -0700 Subject: [PATCH 308/364] Major efficiency improvements, new benches, and API change to allow changing font collections. Change-Id: Id33cdcd161d659310d28dd36f415dc01da2e03a7 --- engine/src/flutter/benchmarks/BUILD.gn | 1 + .../benchmarks/font_collection_benchmarks.cc | 23 +++++++-- .../benchmarks/paint_record_benchmarks.cc | 46 +++++++++++++++++ .../benchmarks/paragraph_benchmarks.cc | 27 ++++++---- .../paragraph_builder_benchmarks.cc | 21 ++++---- engine/src/flutter/src/font_collection.cc | 12 +++++ engine/src/flutter/src/font_collection.h | 16 ++++-- engine/src/flutter/src/paragraph.cc | 39 ++++++++------- engine/src/flutter/src/paragraph.h | 14 +++--- engine/src/flutter/src/paragraph_builder.cc | 17 +++++++ engine/src/flutter/src/paragraph_builder.h | 6 +++ .../flutter/tests/txt/paragraph_unittests.cc | 50 +++++++++++-------- engine/src/flutter/tests/txt/utils.cc | 2 +- 13 files changed, 202 insertions(+), 72 deletions(-) create mode 100644 engine/src/flutter/benchmarks/paint_record_benchmarks.cc diff --git a/engine/src/flutter/benchmarks/BUILD.gn b/engine/src/flutter/benchmarks/BUILD.gn index 3b637cc4c34..184d2a5a0bb 100644 --- a/engine/src/flutter/benchmarks/BUILD.gn +++ b/engine/src/flutter/benchmarks/BUILD.gn @@ -23,6 +23,7 @@ executable("benchmarks") { sources = [ "font_collection_benchmarks.cc", + "paint_record_benchmarks.cc", "paragraph_benchmarks.cc", "paragraph_builder_benchmarks.cc", "styled_runs_benchmarks.cc", diff --git a/engine/src/flutter/benchmarks/font_collection_benchmarks.cc b/engine/src/flutter/benchmarks/font_collection_benchmarks.cc index 99eb26eecfd..74737a8f702 100644 --- a/engine/src/flutter/benchmarks/font_collection_benchmarks.cc +++ b/engine/src/flutter/benchmarks/font_collection_benchmarks.cc @@ -19,6 +19,8 @@ #include "lib/ftl/command_line.h" #include "lib/ftl/logging.h" #include "lib/txt/src/font_collection.h" +#include "third_party/skia/include/ports/SkFontMgr.h" +#include "third_party/skia/include/ports/SkFontMgr_directory.h" #include "utils.h" namespace txt { @@ -32,18 +34,33 @@ static void BM_FAKE_BENCHMARK(benchmark::State& state) { } BENCHMARK(BM_FAKE_BENCHMARK); +static void BM_FontCollectionCustomInit(benchmark::State& state) { + while (state.KeepRunning()) { + benchmark::DoNotOptimize( + FontCollection::GetFontCollection(txt::GetFontDir())); + } +} +BENCHMARK(BM_FontCollectionCustomInit); + static void BM_FontCollectionInit(benchmark::State& state) { while (state.KeepRunning()) { - FontCollection::GetFontCollection(txt::GetFontDir()); + benchmark::DoNotOptimize(FontCollection::GetFontCollection()); } } BENCHMARK(BM_FontCollectionInit); +static void BM_FontCollectionSkFontMgr(benchmark::State& state) { + while (state.KeepRunning()) { + auto mgr = SkFontMgr_New_Custom_Directory(txt::GetFontDir().c_str()); + } +} +BENCHMARK(BM_FontCollectionSkFontMgr); + static void BM_FontCollectionGetMinikinFontCollectionForFamily( benchmark::State& state) { + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - FontCollection::GetFontCollection(txt::GetFontDir()) - .GetMinikinFontCollectionForFamily("Roboto"); + font_collection.GetMinikinFontCollectionForFamily("Roboto"); } } BENCHMARK(BM_FontCollectionGetMinikinFontCollectionForFamily); diff --git a/engine/src/flutter/benchmarks/paint_record_benchmarks.cc b/engine/src/flutter/benchmarks/paint_record_benchmarks.cc new file mode 100644 index 00000000000..f5f7143d726 --- /dev/null +++ b/engine/src/flutter/benchmarks/paint_record_benchmarks.cc @@ -0,0 +1,46 @@ +/* + * Copyright 2017 Google, Inc. + * + * 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 "third_party/benchmark/include/benchmark/benchmark_api.h" + +#include "lib/ftl/command_line.h" +#include "lib/ftl/logging.h" +#include "lib/txt/src/paint_record.h" +#include "lib/txt/src/text_style.h" +#include "utils.h" + +namespace txt { + +static void BM_PaintRecordInit(benchmark::State& state) { + TextStyle style; + + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); + paint.setTextSize(14); + paint.setFakeBoldText(false); + + SkTextBlobBuilder builder; + builder.allocRunPos(paint, 100); + auto text_blob = builder.make(); + + while (state.KeepRunning()) { + PaintRecord PaintRecord(style, text_blob, SkPaint::FontMetrics(), 0); + } +} +BENCHMARK(BM_PaintRecordInit); + +} // namespace txt diff --git a/engine/src/flutter/benchmarks/paragraph_benchmarks.cc b/engine/src/flutter/benchmarks/paragraph_benchmarks.cc index 7a694f6eb51..455b75e047e 100644 --- a/engine/src/flutter/benchmarks/paragraph_benchmarks.cc +++ b/engine/src/flutter/benchmarks/paragraph_benchmarks.cc @@ -43,15 +43,16 @@ static void BM_ParagraphShortLayout(benchmark::State& state) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.PushStyle(text_style); builder.AddText(u16_text); builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(300, txt::GetFontDir(), true); + paragraph->Layout(300, true); } } BENCHMARK(BM_ParagraphShortLayout); @@ -83,15 +84,16 @@ static void BM_ParagraphLongLayout(benchmark::State& state) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.PushStyle(text_style); builder.AddText(u16_text); builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(300, txt::GetFontDir(), true); + paragraph->Layout(300, true); } } BENCHMARK(BM_ParagraphLongLayout); @@ -106,14 +108,15 @@ static void BM_ParagraphManyStylesLayout(benchmark::State& state) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); - for (int i = 0; i < 100; ++i) { + txt::ParagraphBuilder builder(paragraph_style, &font_collection); + for (int i = 0; i < 1000; ++i) { builder.PushStyle(text_style); builder.AddText(u16_text); } auto paragraph = builder.Build(); - paragraph->Layout(300, txt::GetFontDir(), true); + paragraph->Layout(300, true); } } BENCHMARK(BM_ParagraphManyStylesLayout); @@ -128,15 +131,16 @@ static void BM_ParagraphTextBigO(benchmark::State& state) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.PushStyle(text_style); builder.AddText(u16_text); builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(300, txt::GetFontDir(), true); + paragraph->Layout(300, true); } state.SetComplexityN(state.range(0)); } @@ -155,15 +159,16 @@ static void BM_ParagraphStylesBigO(benchmark::State& state) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); for (int i = 0; i < state.range(0); ++i) { builder.PushStyle(text_style); builder.AddText(u16_text); } auto paragraph = builder.Build(); - paragraph->Layout(300, txt::GetFontDir(), true); + paragraph->Layout(300, true); } state.SetComplexityN(state.range(0)); } diff --git a/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc b/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc index e91ba4416d4..c589dfd9aef 100644 --- a/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc +++ b/engine/src/flutter/benchmarks/paragraph_builder_benchmarks.cc @@ -17,6 +17,7 @@ #include "third_party/benchmark/include/benchmark/benchmark_api.h" #include "lib/ftl/logging.h" +#include "lib/txt/src/font_collection.h" #include "lib/txt/src/font_style.h" #include "lib/txt/src/font_weight.h" #include "lib/txt/src/paragraph.h" @@ -24,6 +25,7 @@ #include "lib/txt/src/text_align.h" #include "third_party/icu/source/common/unicode/unistr.h" #include "third_party/skia/include/core/SkColor.h" +#include "utils.h" namespace txt { @@ -40,8 +42,9 @@ static void BM_ParagraphBuilderPushStyle(benchmark::State& state) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.PushStyle(text_style); } } @@ -76,9 +79,9 @@ static void BM_ParagraphBuilderAddTextChar(benchmark::State& state) { const char* text = "Hello World"; txt::ParagraphStyle paragraph_style; - + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.AddText(text); } } @@ -91,9 +94,9 @@ static void BM_ParagraphBuilderAddTextU16stringShort(benchmark::State& state) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.AddText(u16_text); } } @@ -142,9 +145,9 @@ static void BM_ParagraphBuilderShortParagraphConstruct( txt::TextStyle text_style; text_style.color = SK_ColorBLACK; - + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.PushStyle(text_style); builder.AddText(u16_text); builder.Pop(); @@ -180,9 +183,9 @@ static void BM_ParagraphBuilderLongParagraphConstruct(benchmark::State& state) { txt::TextStyle text_style; text_style.color = SK_ColorBLACK; - + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); while (state.KeepRunning()) { - txt::ParagraphBuilder builder(paragraph_style); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); builder.PushStyle(text_style); builder.AddText(u16_text); builder.Pop(); diff --git a/engine/src/flutter/src/font_collection.cc b/engine/src/flutter/src/font_collection.cc index 29837694949..009382d3f25 100644 --- a/engine/src/flutter/src/font_collection.cc +++ b/engine/src/flutter/src/font_collection.cc @@ -28,11 +28,13 @@ namespace txt { +// Will be deprecated when full compatibility with Flutter Engine is complete. FontCollection& FontCollection::GetFontCollection(std::string dir) { std::vector dirs = {dir}; return GetFontCollection(std::move(dirs)); } +// Will be deprecated when full compatibility with Flutter Engine is complete. FontCollection& FontCollection::GetFontCollection( std::vector dirs) { static FontCollection* collection = nullptr; @@ -41,10 +43,20 @@ FontCollection& FontCollection::GetFontCollection( return *collection; } +// Will be deprecated when full compatibility with Flutter Engine is complete. FontCollection& FontCollection::GetDefaultFontCollection() { return GetFontCollection(""); } +FontCollection::FontCollection() { + FontCollection(""); +} + +FontCollection::FontCollection(std::string dir) { + std::vector dirs = {dir}; + FontCollection(std::move(dirs)); +} + FontCollection::FontCollection(const std::vector& dirs) { #ifdef DIRECTORY_FONT_MANAGER_AVAILABLE for (std::string dir : dirs) { diff --git a/engine/src/flutter/src/font_collection.h b/engine/src/flutter/src/font_collection.h index b8a0c8a6de2..0a05bda86d2 100644 --- a/engine/src/flutter/src/font_collection.h +++ b/engine/src/flutter/src/font_collection.h @@ -35,15 +35,26 @@ namespace txt { class FontCollection { public: + // Will be deprecated when full compatibility with Flutter Engine is complete. static FontCollection& GetDefaultFontCollection(); + // Will be deprecated when full compatibility with Flutter Engine is complete. static FontCollection& GetFontCollection(std::string dir = ""); + // Will be deprecated when full compatibility with Flutter Engine is complete. static FontCollection& GetFontCollection(std::vector dirs); std::shared_ptr GetMinikinFontCollectionForFamily( const std::string& family); + FontCollection(const std::vector& dirs); + + FontCollection(std::string dir); + + FontCollection(); + + ~FontCollection(); + // Provides a set of all available family names. std::set GetFamilyNames(); @@ -62,12 +73,7 @@ class FontCollection { return DEFAULT_FAMILY_NAME; }; - FontCollection(const std::vector& dirs); - - ~FontCollection(); - // TODO(chinmaygarde): Caches go here. - FTL_DISALLOW_COPY_AND_ASSIGN(FontCollection); }; } // namespace txt diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index fbdc53c6a99..c6ee6be9794 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -125,24 +125,25 @@ void Paragraph::SetText(std::vector text, StyledRuns runs) { breaker_.setText(); } -void Paragraph::AddRunsToLineBreaker(const std::string& rootdir) { +void Paragraph::AddRunsToLineBreaker( + std::shared_ptr& collection, + std::string& prev_font_family) { minikin::FontStyle font; minikin::MinikinPaint paint; for (size_t i = 0; i < runs_.size(); ++i) { auto run = runs_.GetRun(i); - auto collection = - FontCollection::GetFontCollection(rootdir) - .GetMinikinFontCollectionForFamily(run.style.font_family); + // Only obtain new font family if the font has changed between runs. + if (run.style.font_family != prev_font_family || collection == nullptr) { + collection = font_collection_->GetMinikinFontCollectionForFamily( + run.style.font_family); + } + prev_font_family = run.style.font_family; GetFontAndMinikinPaint(run.style, &font, &paint); breaker_.addStyleRun(&paint, collection, font, run.start, run.end, false); } } -void Paragraph::Layout(double width, - const std::string& rootdir, - bool force, - const double x_offset, - const double y_offset) { +void Paragraph::Layout(double width, bool force) { // Do not allow calling layout multiple times without changing anything. if (!needs_layout_ && !force) return; @@ -150,8 +151,11 @@ void Paragraph::Layout(double width, width_ = width; + std::shared_ptr collection = nullptr; + std::string prev_font_family = ""; + breaker_.setLineWidths(0.0f, 0, width_); - AddRunsToLineBreaker(rootdir); + AddRunsToLineBreaker(collection, prev_font_family); breaker_.setJustified(paragraph_style_.text_align == TextAlign::justify); size_t breaks_count = breaker_.computeBreaks(); const int* breaks = breaker_.getBreaks(); @@ -170,8 +174,8 @@ void Paragraph::Layout(double width, max_intrinsic_width_ = 0.0f; lines_ = 0; - SkScalar x = x_offset; - SkScalar y = y_offset; + SkScalar x = 0.0f; + SkScalar y = 0.0f; size_t break_index = 0; double letter_spacing_offset = 0.0f; double max_line_spacing = 0.0f; @@ -214,16 +218,13 @@ void Paragraph::Layout(double width, } x_queue.clear(); }; - std::shared_ptr collection = nullptr; - std::string prev_font_family = ""; for (size_t run_index = 0; run_index < runs_.size(); ++run_index) { auto run = runs_.GetRun(run_index); // Only obtain new font family if the font has changed between runs. if (run.style.font_family != prev_font_family || collection == nullptr) { - collection = - FontCollection::GetFontCollection(rootdir) - .GetMinikinFontCollectionForFamily(run.style.font_family); + collection = font_collection_->GetMinikinFontCollectionForFamily( + run.style.font_family); } prev_font_family = run.style.font_family; GetFontAndMinikinPaint(run.style, &font, &minikin_paint); @@ -434,6 +435,10 @@ void Paragraph::SetParagraphStyle(const ParagraphStyle& style) { paragraph_style_ = style; } +void Paragraph::SetFontCollection(FontCollection* font_collection) { + font_collection_ = font_collection; +} + void Paragraph::Paint(SkCanvas* canvas, double x, double y) { for (const auto& record : records_) { SkPaint paint; diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index b4b90a4ee91..64739c8b95f 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -21,6 +21,7 @@ #include #include "lib/ftl/macros.h" +#include "lib/txt/src/font_collection.h" #include "lib/txt/src/paint_record.h" #include "lib/txt/src/paragraph_style.h" #include "lib/txt/src/styled_runs.h" @@ -38,11 +39,7 @@ class Paragraph { ~Paragraph(); - void Layout(double width, - const std::string& rootdir = "", - bool force = false, - const double x_offset = 0.0, - const double y_offset = 0.0); + void Layout(double width, bool force = false); void Paint(SkCanvas* canvas, double x, double y); @@ -81,6 +78,7 @@ class Paragraph { std::vector records_; std::vector line_widths_; ParagraphStyle paragraph_style_; + FontCollection* font_collection_; // TODO(garyq): Height of the paragraph after Layout(). SkScalar height_ = 0.0f; double width_ = 0.0f; @@ -95,7 +93,11 @@ class Paragraph { void SetParagraphStyle(const ParagraphStyle& style); - void AddRunsToLineBreaker(const std::string& rootdir = ""); + void SetFontCollection(FontCollection* font_collection); + + void AddRunsToLineBreaker( + std::shared_ptr& collection, + std::string& prev_font_family); void JustifyLine(std::vector& buffers, std::vector& buffer_sizes, diff --git a/engine/src/flutter/src/paragraph_builder.cc b/engine/src/flutter/src/paragraph_builder.cc index 3d980eae3a3..d3076774585 100644 --- a/engine/src/flutter/src/paragraph_builder.cc +++ b/engine/src/flutter/src/paragraph_builder.cc @@ -21,6 +21,10 @@ namespace txt { +ParagraphBuilder::ParagraphBuilder(ParagraphStyle style, + FontCollection* font_collection) + : paragraph_style_(style), font_collection_(font_collection) {} + ParagraphBuilder::ParagraphBuilder(ParagraphStyle style) : paragraph_style_(style) {} @@ -30,6 +34,10 @@ void ParagraphBuilder::SetParagraphStyle(const ParagraphStyle& style) { paragraph_style_ = style; } +void ParagraphBuilder::SetFontCollection(FontCollection* font_collection) { + font_collection_ = font_collection; +} + ParagraphBuilder::~ParagraphBuilder() = default; void ParagraphBuilder::PushStyle(const TextStyle& style) { @@ -71,10 +79,19 @@ void ParagraphBuilder::AddText(const char* text) { } std::unique_ptr ParagraphBuilder::Build() { + if (font_collection_ == nullptr) { + // Will be deprecated when full compatibility with Flutter Engine is + // complete. + FTL_LOG(WARNING) << "No font collection provided. Falling back to default " + "fonts."; + font_collection_ = &FontCollection::GetFontCollection(""); + } + runs_.EndRunIfNeeded(text_.size()); std::unique_ptr paragraph = std::make_unique(); paragraph->SetText(std::move(text_), std::move(runs_)); paragraph->SetParagraphStyle(paragraph_style_); + paragraph->SetFontCollection(font_collection_); return paragraph; } diff --git a/engine/src/flutter/src/paragraph_builder.h b/engine/src/flutter/src/paragraph_builder.h index 5df84ca72aa..07d92e69d62 100644 --- a/engine/src/flutter/src/paragraph_builder.h +++ b/engine/src/flutter/src/paragraph_builder.h @@ -21,6 +21,7 @@ #include #include "lib/ftl/macros.h" +#include "lib/txt/src/font_collection.h" #include "lib/txt/src/paragraph.h" #include "lib/txt/src/paragraph_style.h" #include "lib/txt/src/styled_runs.h" @@ -32,6 +33,8 @@ class ParagraphBuilder { public: explicit ParagraphBuilder(ParagraphStyle style); + ParagraphBuilder(ParagraphStyle style, FontCollection* font_collection); + ParagraphBuilder(); ~ParagraphBuilder(); @@ -48,6 +51,8 @@ class ParagraphBuilder { void SetParagraphStyle(const ParagraphStyle& style); + void SetFontCollection(FontCollection* font_collection); + std::unique_ptr Build(); private: @@ -55,6 +60,7 @@ class ParagraphBuilder { std::vector style_stack_; StyledRuns runs_; ParagraphStyle paragraph_style_; + FontCollection* font_collection_ = nullptr; FTL_DISALLOW_COPY_AND_ASSIGN(ParagraphBuilder); }; diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index d93ea32e3ed..187ccfa3029 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -34,7 +34,8 @@ TEST_F(RenderTest, SimpleParagraph) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.color = SK_ColorBLACK; @@ -44,7 +45,7 @@ TEST_F(RenderTest, SimpleParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth()); paragraph->Paint(GetCanvas(), 10.0, 15.0); @@ -66,7 +67,8 @@ TEST_F(RenderTest, SimpleRedParagraph) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.color = SK_ColorRED; @@ -77,7 +79,7 @@ TEST_F(RenderTest, SimpleRedParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth()); paragraph->Paint(GetCanvas(), 10.0, 15.0); @@ -119,7 +121,8 @@ TEST_F(RenderTest, RainbowParagraph) { txt::ParagraphStyle paragraph_style; paragraph_style.max_lines = 2; paragraph_style.text_align = TextAlign::left; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style1; text_style1.color = SK_ColorRED; @@ -162,7 +165,7 @@ TEST_F(RenderTest, RainbowParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth()); paragraph->Paint(GetCanvas(), 10.0, 50.0); @@ -191,7 +194,8 @@ TEST_F(RenderTest, DefaultStyleParagraph) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.color = SK_ColorRED; @@ -201,7 +205,7 @@ TEST_F(RenderTest, DefaultStyleParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth()); paragraph->Paint(GetCanvas(), 10.0, 15.0); @@ -221,7 +225,8 @@ TEST_F(RenderTest, BoldParagraph) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.font_size = 60; @@ -236,7 +241,7 @@ TEST_F(RenderTest, BoldParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth()); paragraph->Paint(GetCanvas(), 10.0, 60.0); @@ -277,7 +282,8 @@ TEST_F(RenderTest, LeftAlignParagraph) { txt::ParagraphStyle paragraph_style; paragraph_style.max_lines = 14; paragraph_style.text_align = TextAlign::left; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.font_size = 26; @@ -294,7 +300,7 @@ TEST_F(RenderTest, LeftAlignParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth() - 100, txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth() - 100); paragraph->Paint(GetCanvas(), 0, 0); ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); @@ -363,7 +369,8 @@ TEST_F(RenderTest, RightAlignParagraph) { txt::ParagraphStyle paragraph_style; paragraph_style.max_lines = 14; paragraph_style.text_align = TextAlign::right; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.font_size = 26; @@ -380,7 +387,7 @@ TEST_F(RenderTest, RightAlignParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth() - 100, txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth() - 100); paragraph->Paint(GetCanvas(), 0, 0); ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); @@ -464,7 +471,8 @@ TEST_F(RenderTest, CenterAlignParagraph) { txt::ParagraphStyle paragraph_style; paragraph_style.max_lines = 14; paragraph_style.text_align = TextAlign::center; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.font_size = 26; @@ -481,7 +489,7 @@ TEST_F(RenderTest, CenterAlignParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth() - 100, txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth() - 100); paragraph->Paint(GetCanvas(), 0, 0); ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); @@ -569,7 +577,8 @@ TEST_F(RenderTest, JustifyAlignParagraph) { txt::ParagraphStyle paragraph_style; paragraph_style.max_lines = 14; paragraph_style.text_align = TextAlign::justify; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.font_size = 26; @@ -586,7 +595,7 @@ TEST_F(RenderTest, JustifyAlignParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth() - 100, txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth() - 100); paragraph->Paint(GetCanvas(), 0, 0); ASSERT_EQ(paragraph->text_.size(), std::string{text}.length()); @@ -636,7 +645,8 @@ TEST_F(RenderTest, ItalicsParagraph) { icu_text.getBuffer() + icu_text.length()); txt::ParagraphStyle paragraph_style; - txt::ParagraphBuilder builder(paragraph_style); + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); txt::TextStyle text_style; text_style.color = SK_ColorRED; @@ -649,7 +659,7 @@ TEST_F(RenderTest, ItalicsParagraph) { builder.Pop(); auto paragraph = builder.Build(); - paragraph->Layout(GetTestCanvasWidth(), txt::GetFontDir()); + paragraph->Layout(GetTestCanvasWidth()); paragraph->Paint(GetCanvas(), 10.0, 35.0); diff --git a/engine/src/flutter/tests/txt/utils.cc b/engine/src/flutter/tests/txt/utils.cc index 6ec90c2a5cd..0bee521a3fd 100644 --- a/engine/src/flutter/tests/txt/utils.cc +++ b/engine/src/flutter/tests/txt/utils.cc @@ -40,4 +40,4 @@ void SetCommandLine(ftl::CommandLine cmd) { gCommandLine = std::move(cmd); } -} // namespace txt +} // namespace txt \ No newline at end of file From d6a6221fc832c7e292f0a4ab663c67c7a634aa9c Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Thu, 29 Jun 2017 16:14:35 -0700 Subject: [PATCH 309/364] Switch to hashmap caching of font collections to be resillient to alternating fonts and slight performance improvement. Change-Id: Ide3a311819c41e23e88e6dca06f0ce7669f6842c --- engine/src/flutter/src/paragraph.cc | 30 +++++++++++++---------------- engine/src/flutter/src/paragraph.h | 4 ++-- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index c6ee6be9794..d4a7c7d13ec 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -126,20 +126,21 @@ void Paragraph::SetText(std::vector text, StyledRuns runs) { } void Paragraph::AddRunsToLineBreaker( - std::shared_ptr& collection, - std::string& prev_font_family) { + std::unordered_map>& + collection_map) { minikin::FontStyle font; minikin::MinikinPaint paint; for (size_t i = 0; i < runs_.size(); ++i) { auto run = runs_.GetRun(i); // Only obtain new font family if the font has changed between runs. - if (run.style.font_family != prev_font_family || collection == nullptr) { - collection = font_collection_->GetMinikinFontCollectionForFamily( - run.style.font_family); + if (collection_map.count(run.style.font_family) == 0) { + collection_map[run.style.font_family] = + font_collection_->GetMinikinFontCollectionForFamily( + run.style.font_family); } - prev_font_family = run.style.font_family; GetFontAndMinikinPaint(run.style, &font, &paint); - breaker_.addStyleRun(&paint, collection, font, run.start, run.end, false); + breaker_.addStyleRun(&paint, collection_map.at(run.style.font_family), font, + run.start, run.end, false); } } @@ -151,11 +152,11 @@ void Paragraph::Layout(double width, bool force) { width_ = width; - std::shared_ptr collection = nullptr; - std::string prev_font_family = ""; + std::unordered_map> + collection_map; breaker_.setLineWidths(0.0f, 0, width_); - AddRunsToLineBreaker(collection, prev_font_family); + AddRunsToLineBreaker(collection_map); breaker_.setJustified(paragraph_style_.text_align == TextAlign::justify); size_t breaks_count = breaker_.computeBreaks(); const int* breaks = breaker_.getBreaks(); @@ -221,12 +222,6 @@ void Paragraph::Layout(double width, bool force) { for (size_t run_index = 0; run_index < runs_.size(); ++run_index) { auto run = runs_.GetRun(run_index); - // Only obtain new font family if the font has changed between runs. - if (run.style.font_family != prev_font_family || collection == nullptr) { - collection = font_collection_->GetMinikinFontCollectionForFamily( - run.style.font_family); - } - prev_font_family = run.style.font_family; GetFontAndMinikinPaint(run.style, &font, &minikin_paint); GetPaint(run.style, &paint); @@ -244,7 +239,8 @@ void Paragraph::Layout(double width, bool force) { int bidiFlags = 0; layout.doLayout(text_.data(), layout_start, layout_end - layout_start, - text_.size(), bidiFlags, font, minikin_paint, collection); + text_.size(), bidiFlags, font, minikin_paint, + collection_map.at(run.style.font_family)); const size_t glyph_count = layout.nGlyphs(); size_t blob_start = 0; // Each blob. diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 64739c8b95f..97e30dae511 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -96,8 +96,8 @@ class Paragraph { void SetFontCollection(FontCollection* font_collection); void AddRunsToLineBreaker( - std::shared_ptr& collection, - std::string& prev_font_family); + std::unordered_map>& + collection_map); void JustifyLine(std::vector& buffers, std::vector& buffer_sizes, From 4c93f0e97663b8b996432a7219fb93d8f8b627e7 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Thu, 29 Jun 2017 17:58:42 -0700 Subject: [PATCH 310/364] Remove trailing spaces of blobs to fix decoration positioning, justify, and centering. Change-Id: Ide66103f95be8c090ab5ddc9888cd4defc5cde51 --- engine/src/flutter/src/paragraph.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index d4a7c7d13ec..764291ef485 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -253,13 +253,22 @@ void Paragraph::Layout(double width, bool force) { // TODO(abarth): Precompute when we can use allocRunPosH. paint.setTypeface(GetTypefaceForGlyph(layout, blob_start)); - buffers.push_back(&builder.allocRunPos(paint, blob_length)); + // Check if we should remove trailing whitespace of blobs. + size_t trailing_length = 0; + while (minikin::isWordSpace( + text_[character_index + blob_length - trailing_length - 1])) { + ++trailing_length; + } + + buffers.push_back( + &builder.allocRunPos(paint, blob_length - trailing_length)); letter_spacing_offset += run.style.letter_spacing; // Each Glyph/Letter. bool whitespace_ended = true; - for (size_t blob_index = 0; blob_index < blob_length; ++blob_index) { + for (size_t blob_index = 0; blob_index < blob_length - trailing_length; + ++blob_index) { const size_t glyph_index = blob_start + blob_index; buffers.back()->glyphs[blob_index] = layout.getGlyphId(glyph_index); // Check if the current Glyph is a whitespace and handle multiple @@ -283,6 +292,7 @@ void Paragraph::Layout(double width, bool force) { letter_spacing_offset += run.style.letter_spacing; } blob_start += blob_length; + character_index += trailing_length; // Subtract letter offset to avoid big gap at end of run. This my be // removed depending on the specifications for letter spacing. From 11580cea63f8a3f71e88b4cbe53d995c23488ece Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Fri, 30 Jun 2017 12:05:11 -0700 Subject: [PATCH 311/364] Move font caches to FontCollection and multiple eviction schemes. ~x200 speed improvement. Change-Id: I1e2f940ddb36f9ac51cc95c42c2f121140ff3f6f --- .../benchmarks/paragraph_benchmarks.cc | 4 +- engine/src/flutter/src/font_collection.cc | 128 ++++++++++++------ engine/src/flutter/src/font_collection.h | 30 +++- engine/src/flutter/src/paragraph.cc | 17 ++- 4 files changed, 123 insertions(+), 56 deletions(-) diff --git a/engine/src/flutter/benchmarks/paragraph_benchmarks.cc b/engine/src/flutter/benchmarks/paragraph_benchmarks.cc index 455b75e047e..7bbfaacba50 100644 --- a/engine/src/flutter/benchmarks/paragraph_benchmarks.cc +++ b/engine/src/flutter/benchmarks/paragraph_benchmarks.cc @@ -146,7 +146,7 @@ static void BM_ParagraphTextBigO(benchmark::State& state) { } BENCHMARK(BM_ParagraphTextBigO) ->RangeMultiplier(20) - ->Range(1 << 4, 1 << 12) + ->Range(1 << 6, 1 << 14) ->Complexity(benchmark::oN); static void BM_ParagraphStylesBigO(benchmark::State& state) { @@ -174,7 +174,7 @@ static void BM_ParagraphStylesBigO(benchmark::State& state) { } BENCHMARK(BM_ParagraphStylesBigO) ->RangeMultiplier(20) - ->Range(1 << 2, 1 << 8) + ->Range(1 << 4, 1 << 12) ->Complexity(benchmark::oN); // ----------------------------------------------------------------------------- diff --git a/engine/src/flutter/src/font_collection.cc b/engine/src/flutter/src/font_collection.cc index 009382d3f25..eb0a793a420 100644 --- a/engine/src/flutter/src/font_collection.cc +++ b/engine/src/flutter/src/font_collection.cc @@ -16,9 +16,13 @@ #include "lib/txt/src/font_collection.h" +#include +#include #include #include #include +#include +#include #include "lib/ftl/logging.h" #include "lib/txt/src/font_skia.h" @@ -52,12 +56,17 @@ FontCollection::FontCollection() { FontCollection(""); } -FontCollection::FontCollection(std::string dir) { - std::vector dirs = {dir}; - FontCollection(std::move(dirs)); +FontCollection::FontCollection(CacheMethod cache_method) { + FontCollection("", cache_method); } -FontCollection::FontCollection(const std::vector& dirs) { +FontCollection::FontCollection(std::string dir, CacheMethod cache_method) { + std::vector dirs = {dir}; + FontCollection(std::move(dirs), cache_method); +} + +FontCollection::FontCollection(const std::vector& dirs, + CacheMethod cache_method) { #ifdef DIRECTORY_FONT_MANAGER_AVAILABLE for (std::string dir : dirs) { if (dir.length() != 0) { @@ -75,6 +84,8 @@ FontCollection::FontCollection(const std::vector& dirs) { family_names_.insert(std::string{str.writable_str()}); } } + + cache_method_ = cache_method; } FontCollection::~FontCollection() = default; @@ -83,6 +94,18 @@ std::set FontCollection::GetFamilyNames() { return family_names_; } +bool FontCollection::HasFamily(const std::string family) const { + return family_names_.count(family) == 1; +} + +void FontCollection::FlushCache() { + minikin_font_collection_map_.clear(); +} + +void FontCollection::SetCacheCapacity(const size_t cap) { + cache_capacity_ = cap; +} + // TODO(garyq): Rework this to use font fallback system. const std::string FontCollection::ProcessFamilyName(const std::string& family) { #ifdef DIRECTORY_FONT_MANAGER_AVAILABLE @@ -101,51 +124,70 @@ const std::string FontCollection::ProcessFamilyName(const std::string& family) { std::shared_ptr FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) { FTL_DCHECK(skia_font_managers_.size() > 0); + std::string processed_family_name = ProcessFamilyName(family); + // Only obtain new font family if the font has changed between runs. + if (cache_method_ == CacheMethod::kNone || + minikin_font_collection_map_.count(processed_family_name) == 0) { + // Ask Skia to resolve a font style set for a font family name. + // FIXME(chinmaygarde): CoreText crashes when passed a null string. This + // seems to be a bug in Skia as SkFontMgr explicitly says passing in + // nullptr gives the default font. + for (sk_sp mgr : skia_font_managers_) { + FTL_DCHECK(mgr != nullptr); + auto font_style_set = mgr->matchFamily(processed_family_name.c_str()); + if (font_style_set != nullptr) { + std::vector minikin_fonts; - // Ask Skia to resolve a font style set for a font family name. - // FIXME(chinmaygarde): The name "Coolvetica" is hardcoded because CoreText - // crashes when passed a null string. This seems to be a bug in Skia as - // SkFontMgr explicitly says passing in nullptr gives the default font. - for (sk_sp mgr : skia_font_managers_) { - FTL_DCHECK(mgr != nullptr); - auto font_style_set = mgr->matchFamily(ProcessFamilyName(family).c_str()); - FTL_DCHECK(font_style_set != nullptr); + // Add fonts to the Minikin font family. + for (int i = 0, style_count = font_style_set->count(); i < style_count; + ++i) { + // Create the skia typeface + auto skia_typeface = + sk_ref_sp(font_style_set->createTypeface(i)); + if (skia_typeface == nullptr) { + continue; + } - std::vector minikin_fonts; + // Create the minikin font from the skia typeface. + minikin::Font minikin_font( + std::make_shared(skia_typeface), + minikin::FontStyle{skia_typeface->fontStyle().weight(), + skia_typeface->isItalic()}); - // Add fonts to the Minikin font family. - for (int i = 0, style_count = font_style_set->count(); i < style_count; - ++i) { - // Create the skia typeface - auto skia_typeface = - sk_ref_sp(font_style_set->createTypeface(i)); - if (skia_typeface == nullptr) { - continue; + minikin_fonts.emplace_back(std::move(minikin_font)); + } + + // Create a Minikin font family. + auto minikin_family = + std::make_shared(std::move(minikin_fonts)); + + // Create a vector of font families for the Minkin font collection. For + // now, we only have one family in our collection. + std::vector> minikin_families = { + minikin_family, + }; + + // Assign the font collection. + minikin_font_collection_map_[processed_family_name] = + std::make_shared(minikin_families); + return minikin_font_collection_map_[processed_family_name]; } - - // Create the minikin font from the skia typeface. - minikin::Font minikin_font( - std::make_shared(skia_typeface), - minikin::FontStyle{skia_typeface->fontStyle().weight(), - skia_typeface->isItalic()}); - - minikin_fonts.emplace_back(std::move(minikin_font)); } - - // Create a Minikin font family. - auto minikin_family = - std::make_shared(std::move(minikin_fonts)); - - // Create a vector of font families for the Minkin font collection. For now, - // we only have one family in our collection. - std::vector> minikin_families = { - minikin_family, - }; - - // Return the font collection. - return std::make_shared(minikin_families); + // Uh oh! Font family not found in any of the font managers! + minikin_font_collection_map_[processed_family_name] = nullptr; } - return nullptr; + + // Maintain LRU and evict old fonts no longer used. + if (cache_method_ == CacheMethod::kLRU) { + lru_tracker_.remove(processed_family_name); + lru_tracker_.push_front(processed_family_name); + if (lru_tracker_.size() > cache_capacity_) { + std::string family_to_evict = lru_tracker_.back(); + lru_tracker_.pop_back(); + minikin_font_collection_map_.erase(family_to_evict); + } + } + return minikin_font_collection_map_[processed_family_name]; } } // namespace txt diff --git a/engine/src/flutter/src/font_collection.h b/engine/src/flutter/src/font_collection.h index 0a05bda86d2..efc1dab7323 100644 --- a/engine/src/flutter/src/font_collection.h +++ b/engine/src/flutter/src/font_collection.h @@ -19,9 +19,11 @@ #define DEFAULT_FAMILY_NAME "Roboto" +#include #include #include #include +#include #include #include "lib/ftl/macros.h" @@ -35,6 +37,11 @@ namespace txt { class FontCollection { public: + enum CacheMethod { + kNone, + kLRU, // Least Recently Used. + kUnlimited, + }; // Will be deprecated when full compatibility with Flutter Engine is complete. static FontCollection& GetDefaultFontCollection(); @@ -47,9 +54,13 @@ class FontCollection { std::shared_ptr GetMinikinFontCollectionForFamily( const std::string& family); - FontCollection(const std::vector& dirs); + FontCollection(const std::vector& dirs, + CacheMethod cache_method = CacheMethod::kUnlimited); - FontCollection(std::string dir); + FontCollection(std::string dir, + CacheMethod cache_method = CacheMethod::kUnlimited); + + FontCollection(CacheMethod cache_method); FontCollection(); @@ -58,10 +69,25 @@ class FontCollection { // Provides a set of all available family names. std::set GetFamilyNames(); + bool HasFamily(const std::string family) const; + + void FlushCache(); + + void SetCacheCapacity(const size_t cap); + private: std::vector> skia_font_managers_; // Cache the names because GetFamilyNames() can be frequently called. std::set family_names_; + CacheMethod cache_method_ = CacheMethod::kUnlimited; + std::list lru_tracker_; + size_t cache_capacity_ = 20; + + // Cache minikin font collections to prevent slow disk reads. + // TODO(garyq): Implement optional low-memory optimized system to prevent + // fonts building up in memory. + std::unordered_map> + minikin_font_collection_map_; FRIEND_TEST(FontCollection, HasDefaultRegistrations); FRIEND_TEST(FontCollection, GetMinikinFontCollections); diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 764291ef485..848bda5d549 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -132,15 +132,11 @@ void Paragraph::AddRunsToLineBreaker( minikin::MinikinPaint paint; for (size_t i = 0; i < runs_.size(); ++i) { auto run = runs_.GetRun(i); - // Only obtain new font family if the font has changed between runs. - if (collection_map.count(run.style.font_family) == 0) { - collection_map[run.style.font_family] = - font_collection_->GetMinikinFontCollectionForFamily( - run.style.font_family); - } GetFontAndMinikinPaint(run.style, &font, &paint); - breaker_.addStyleRun(&paint, collection_map.at(run.style.font_family), font, - run.start, run.end, false); + breaker_.addStyleRun(&paint, + font_collection_->GetMinikinFontCollectionForFamily( + run.style.font_family), + font, run.start, run.end, false); } } @@ -240,7 +236,8 @@ void Paragraph::Layout(double width, bool force) { int bidiFlags = 0; layout.doLayout(text_.data(), layout_start, layout_end - layout_start, text_.size(), bidiFlags, font, minikin_paint, - collection_map.at(run.style.font_family)); + font_collection_->GetMinikinFontCollectionForFamily( + run.style.font_family)); const size_t glyph_count = layout.nGlyphs(); size_t blob_start = 0; // Each blob. @@ -445,6 +442,8 @@ void Paragraph::SetFontCollection(FontCollection* font_collection) { font_collection_ = font_collection; } +// The x,y coordinates will be the very top left corner of the rendered +// paragraph. void Paragraph::Paint(SkCanvas* canvas, double x, double y) { for (const auto& record : records_) { SkPaint paint; From 45dd415ba561a3ca587db51812c0bfdc6d7351bb Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Fri, 30 Jun 2017 13:39:24 -0700 Subject: [PATCH 312/364] Add low memory setting on FontCollection. Only remove trailing whitespace at end of line, and do not justify last line. Change-Id: Iee32003624862b3c7f5f2d0e999ef72719302551 --- engine/src/flutter/src/font_collection.cc | 32 ++++++++++++++----- engine/src/flutter/src/font_collection.h | 9 +++++- engine/src/flutter/src/paragraph.cc | 8 +++-- .../flutter/tests/txt/paragraph_unittests.cc | 4 +-- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/engine/src/flutter/src/font_collection.cc b/engine/src/flutter/src/font_collection.cc index eb0a793a420..ca8132e7c62 100644 --- a/engine/src/flutter/src/font_collection.cc +++ b/engine/src/flutter/src/font_collection.cc @@ -100,13 +100,31 @@ bool FontCollection::HasFamily(const std::string family) const { void FontCollection::FlushCache() { minikin_font_collection_map_.clear(); + lru_tracker_.clear(); } void FontCollection::SetCacheCapacity(const size_t cap) { cache_capacity_ = cap; } -// TODO(garyq): Rework this to use font fallback system. +void FontCollection::SetLowMemoryMode(bool mode, size_t cap) { + cache_capacity_ = cap; + if (mode) { + cache_method_ = CacheMethod::kLRU; + TrimCache(); + } else { + cache_method_ = CacheMethod::kUnlimited; + } +} + +void FontCollection::TrimCache() { + while (minikin_font_collection_map_.size() > cache_capacity_) { + std::string family_to_evict = lru_tracker_.back(); + lru_tracker_.pop_back(); + minikin_font_collection_map_.erase(family_to_evict); + } +} + const std::string FontCollection::ProcessFamilyName(const std::string& family) { #ifdef DIRECTORY_FONT_MANAGER_AVAILABLE return family.length() == 0 ? DEFAULT_FAMILY_NAME : family; @@ -178,15 +196,13 @@ FontCollection::GetMinikinFontCollectionForFamily(const std::string& family) { } // Maintain LRU and evict old fonts no longer used. + + lru_tracker_.remove(processed_family_name); + lru_tracker_.push_front(processed_family_name); if (cache_method_ == CacheMethod::kLRU) { - lru_tracker_.remove(processed_family_name); - lru_tracker_.push_front(processed_family_name); - if (lru_tracker_.size() > cache_capacity_) { - std::string family_to_evict = lru_tracker_.back(); - lru_tracker_.pop_back(); - minikin_font_collection_map_.erase(family_to_evict); - } + TrimCache(); } + return minikin_font_collection_map_[processed_family_name]; } diff --git a/engine/src/flutter/src/font_collection.h b/engine/src/flutter/src/font_collection.h index efc1dab7323..b5ba03ea92f 100644 --- a/engine/src/flutter/src/font_collection.h +++ b/engine/src/flutter/src/font_collection.h @@ -18,6 +18,7 @@ #define LIB_TXT_SRC_FONT_COLLECTION_H_ #define DEFAULT_FAMILY_NAME "Roboto" +#define DEFAULT_CACHE_CAPACITY 20 #include #include @@ -75,13 +76,17 @@ class FontCollection { void SetCacheCapacity(const size_t cap); + // Call this to limit memory usage by cached fonts. SetLowMemoryMode() will + // enable default LRU policy and flush fonts beyond capacity. + void SetLowMemoryMode(bool mode = true, size_t cap = DEFAULT_CACHE_CAPACITY); + private: std::vector> skia_font_managers_; // Cache the names because GetFamilyNames() can be frequently called. std::set family_names_; CacheMethod cache_method_ = CacheMethod::kUnlimited; std::list lru_tracker_; - size_t cache_capacity_ = 20; + size_t cache_capacity_ = DEFAULT_CACHE_CAPACITY; // Cache minikin font collections to prevent slow disk reads. // TODO(garyq): Implement optional low-memory optimized system to prevent @@ -95,6 +100,8 @@ class FontCollection { const std::string ProcessFamilyName(const std::string& family); + void TrimCache(); + static const std::string GetDefaultFamilyName() { return DEFAULT_FAMILY_NAME; }; diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 848bda5d549..9a575537b0e 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -252,8 +252,10 @@ void Paragraph::Layout(double width, bool force) { // Check if we should remove trailing whitespace of blobs. size_t trailing_length = 0; - while (minikin::isWordSpace( - text_[character_index + blob_length - trailing_length - 1])) { + while ( + minikin::isWordSpace( + text_[character_index + blob_length - trailing_length - 1]) && + layout_end == next_break) { ++trailing_length; } @@ -307,7 +309,7 @@ void Paragraph::Layout(double width, bool force) { paint.getFontMetrics(&metrics); // Apply additional word spacing if the text is justified. if (paragraph_style_.text_align == TextAlign::justify && - buffer_sizes.size() > 0) { + buffer_sizes.size() > 0 && character_index != text_.size()) { JustifyLine(buffers, buffer_sizes, word_count, character_index); } records_.push_back( diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 187ccfa3029..0c8b7e59242 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -567,9 +567,7 @@ TEST_F(RenderTest, JustifyAlignParagraph) { "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim " "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea " "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate " - "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " - "occaecat cupidatat non proident, sunt in culpa qui officia deserunt " - "mollit anim id est laborum."; + "velit esse cillum dolore eu fugiat."; auto icu_text = icu::UnicodeString::fromUTF8(text); std::u16string u16_text(icu_text.getBuffer(), icu_text.getBuffer() + icu_text.length()); From 42179e540389af77008319745f1fe933d9ed8384 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Wed, 5 Jul 2017 12:16:45 -0700 Subject: [PATCH 313/364] Switch to fuchsia/third_party/benchmark Change-Id: I40a9dadc1e910d4eb31085a71a372e2144d2d03d --- engine/src/flutter/benchmarks/BUILD.gn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/benchmarks/BUILD.gn b/engine/src/flutter/benchmarks/BUILD.gn index 184d2a5a0bb..7c5c6c17b09 100644 --- a/engine/src/flutter/benchmarks/BUILD.gn +++ b/engine/src/flutter/benchmarks/BUILD.gn @@ -14,6 +14,7 @@ executable("benchmarks") { output_name = "txt_benchmarks" + testonly = true include_dirs = [ "//lib/txt/src", @@ -37,7 +38,7 @@ executable("benchmarks") { "//flutter/fml", "//lib/txt/shims", "//lib/txt", - "//build/secondary/testing/benchmark", + "//third_party/benchmark", "//third_party/skia", "//third_party/harfbuzz", "//lib/txt/libs/minikin", From b6c6f1780ec7fcc335db12127cb713e760827010 Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Wed, 5 Jul 2017 16:07:55 -0700 Subject: [PATCH 314/364] Implement wavy text decoration. Change-Id: Ie28dc4e833a24a9661e72f32f54a3e7489f81417 --- engine/src/flutter/src/paragraph.cc | 82 +++++++++++++------ engine/src/flutter/src/paragraph.h | 19 +++++ engine/src/flutter/src/styled_runs.h | 1 + engine/src/flutter/src/text_style.cc | 8 ++ engine/src/flutter/src/text_style.h | 1 + .../flutter/tests/txt/paragraph_unittests.cc | 78 ++++++++++++++++++ 6 files changed, 166 insertions(+), 23 deletions(-) diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 9a575537b0e..8f4221e6188 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -351,8 +351,7 @@ void Paragraph::Layout(double width, bool force) { letter_spacing_offset = 0.0f; word_count = 0; line_width = 0.0f; - // TODO(abarth): Use the line height, which is something like the max - // font_size for runs in this line times the paragraph's line height. + character_index = layout_end; break_index += 1; lines_++; } else { @@ -472,9 +471,17 @@ void Paragraph::PaintDecorations(SkCanvas* canvas, // This is set to 2 for the double line style int decoration_count = 1; + std::vector wave_coords; + + double width = blob->bounds().fRight + blob->bounds().fLeft; + + paint.setStrokeWidth(metrics.fUnderlineThickness * + style.decoration_thickness); + switch (style.decoration_style) { - case TextDecorationStyle::kSolid: + case TextDecorationStyle::kSolid: { break; + } case TextDecorationStyle::kDouble: { decoration_count = 2; break; @@ -496,42 +503,71 @@ void Paragraph::PaintDecorations(SkCanvas* canvas, break; } case TextDecorationStyle::kWavy: { - // TODO(garyq): Wave currently does a random wave instead of an ordered - // wave. - const SkScalar intervals[] = {1}; - size_t count = sizeof(intervals) / sizeof(intervals[0]); - paint.setPathEffect(SkPathEffect::MakeCompose( - SkDashPathEffect::Make(intervals, count, 0.0f), - SkDiscretePathEffect::Make(metrics.fAvgCharWidth / 10.0f, - metrics.fAvgCharWidth / 10.0f))); + int wave_count = 0; + double x_start = 0; + double y_top = -metrics.fUnderlineThickness; + double y_bottom = metrics.fUnderlineThickness; + while (x_start + metrics.fUnderlineThickness * 2 < x + width) { + wave_coords.push_back( + WaveCoordinates(x_start, wave_count % 2 == 0 ? y_bottom : y_top, + x_start + metrics.fUnderlineThickness * 2, + wave_count % 2 == 0 ? y_top : y_bottom)); + x_start += metrics.fUnderlineThickness * 2; + ++wave_count; + } break; } } - double width = blob->bounds().fRight + blob->bounds().fLeft; - + // Use a for loop for "kDouble" decoration style for (int i = 0; i < decoration_count; i++) { double y_offset = i * metrics.fUnderlineThickness * 3.0f; + // Underline if (style.decoration & 0x1) { - paint.setStrokeWidth(metrics.fUnderlineThickness); - canvas->drawLine(x, y + metrics.fUnderlineThickness + y_offset, - x + width, y + metrics.fUnderlineThickness + y_offset, - paint); + if (style.decoration_style != TextDecorationStyle::kWavy) + canvas->drawLine(x, y + metrics.fUnderlineThickness + y_offset, + x + width, + y + metrics.fUnderlineThickness + y_offset, paint); + else + PaintWavyDecoration(canvas, wave_coords, paint, x, y, + metrics.fUnderlineThickness, width); } + // Overline if (style.decoration & 0x2) { - paint.setStrokeWidth(metrics.fUnderlineThickness); - canvas->drawLine(x, y + metrics.fAscent + y_offset, x + width, - y + metrics.fAscent + y_offset, paint); + if (style.decoration_style != TextDecorationStyle::kWavy) + canvas->drawLine(x, y + metrics.fAscent + y_offset, x + width, + y + metrics.fAscent + y_offset, paint); + else + PaintWavyDecoration(canvas, wave_coords, paint, x, y, metrics.fAscent, + width); } + // Strikethrough if (style.decoration & 0x4) { - paint.setStrokeWidth(metrics.fUnderlineThickness); - canvas->drawLine(x, y - metrics.fXHeight / 2 + y_offset, x + width, - y - metrics.fXHeight / 2 + y_offset, paint); + if (style.decoration_style != TextDecorationStyle::kWavy) + canvas->drawLine(x, y - metrics.fXHeight / 2 + y_offset, x + width, + y - metrics.fXHeight / 2 + y_offset, paint); + else + PaintWavyDecoration(canvas, wave_coords, paint, x, y, + -metrics.fXHeight / 2, width); } } } } +void Paragraph::PaintWavyDecoration(SkCanvas* canvas, + std::vector wave_coords, + SkPaint paint, + double x, + double y, + double y_offset, + double width) { + for (size_t i = 0; i < wave_coords.size(); ++i) { + WaveCoordinates coords = wave_coords[i]; + canvas->drawLine(x + coords.x_start, y + y_offset + coords.y_start, + x + coords.x_end, y + y_offset + coords.y_end, paint); + } +} + int Paragraph::GetLineCount() const { return lines_; } diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 97e30dae511..85b45811eb2 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -70,6 +70,7 @@ class Paragraph { FRIEND_TEST(RenderTest, RightAlignParagraph); FRIEND_TEST(RenderTest, CenterAlignParagraph); FRIEND_TEST(RenderTest, JustifyAlignParagraph); + FRIEND_TEST(RenderTest, DecorationsParagraph); FRIEND_TEST(RenderTest, ItalicsParagraph); std::vector text_; @@ -89,6 +90,16 @@ class Paragraph { double ideographic_baseline_ = FLT_MAX; bool needs_layout_ = true; + struct WaveCoordinates { + double x_start; + double y_start; + double x_end; + double y_end; + + WaveCoordinates(double x_s, double y_s, double x_e, double y_e) + : x_start(x_s), y_start(y_s), x_end(x_e), y_end(y_e) {} + }; + void SetText(std::vector text, StyledRuns runs); void SetParagraphStyle(const ParagraphStyle& style); @@ -111,6 +122,14 @@ class Paragraph { SkPaint::FontMetrics metrics, SkTextBlob* blob); + void PaintWavyDecoration(SkCanvas* canvas, + std::vector wave_coords, + SkPaint paint, + double x, + double y, + double y_offset, + double width); + FTL_DISALLOW_COPY_AND_ASSIGN(Paragraph); }; diff --git a/engine/src/flutter/src/styled_runs.h b/engine/src/flutter/src/styled_runs.h index 4942b9cc20a..eedd9e7a89e 100644 --- a/engine/src/flutter/src/styled_runs.h +++ b/engine/src/flutter/src/styled_runs.h @@ -64,6 +64,7 @@ class StyledRuns { FRIEND_TEST(RenderTest, RightAlignParagraph); FRIEND_TEST(RenderTest, CenterAlignParagraph); FRIEND_TEST(RenderTest, JustifyAlignParagraph); + FRIEND_TEST(RenderTest, DecorationsParagraph); FRIEND_TEST(RenderTest, ItalicsParagraph); struct IndexedRun { diff --git a/engine/src/flutter/src/text_style.cc b/engine/src/flutter/src/text_style.cc index 692176c6873..7965318cd6f 100644 --- a/engine/src/flutter/src/text_style.cc +++ b/engine/src/flutter/src/text_style.cc @@ -24,6 +24,14 @@ namespace txt { bool TextStyle::equals(const TextStyle& other) const { if (color != other.color) return false; + if (decoration != other.decoration) + return false; + if (decoration_color != other.decoration_color) + return false; + if (decoration_style != other.decoration_style) + return false; + if (decoration_thickness != other.decoration_thickness) + return false; if (font_weight != other.font_weight) return false; if (font_style != other.font_style) diff --git a/engine/src/flutter/src/text_style.h b/engine/src/flutter/src/text_style.h index 7692c7a58c3..8ed552dd803 100644 --- a/engine/src/flutter/src/text_style.h +++ b/engine/src/flutter/src/text_style.h @@ -33,6 +33,7 @@ class TextStyle { TextDecoration decoration = TextDecoration::kNone; SkColor decoration_color = SK_ColorWHITE; TextDecorationStyle decoration_style = TextDecorationStyle::kSolid; + double decoration_thickness = 1.0; FontWeight font_weight = FontWeight::w400; FontStyle font_style = FontStyle::normal; bool fake_bold = false; diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 0c8b7e59242..7509e2e05d5 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -636,6 +636,84 @@ TEST_F(RenderTest, JustifyAlignParagraph) { ASSERT_TRUE(Snapshot()); } +TEST_F(RenderTest, DecorationsParagraph) { + txt::ParagraphStyle paragraph_style; + paragraph_style.max_lines = 14; + paragraph_style.text_align = TextAlign::left; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); + + txt::TextStyle text_style; + text_style.font_size = 26; + text_style.letter_spacing = 0; + text_style.word_spacing = 5; + text_style.color = SK_ColorBLACK; + text_style.height = 2; + text_style.decoration = txt::TextDecoration(0x1 | 0x2 | 0x4); + text_style.decoration_style = txt::TextDecorationStyle::kSolid; + text_style.decoration_color = SK_ColorBLACK; + builder.PushStyle(text_style); + builder.AddText("This text should be"); + + text_style.decoration_style = txt::TextDecorationStyle::kDouble; + text_style.decoration_color = SK_ColorBLUE; + builder.PushStyle(text_style); + builder.AddText(" decorated even when"); + + text_style.decoration_style = txt::TextDecorationStyle::kDotted; + text_style.decoration_color = SK_ColorBLACK; + builder.PushStyle(text_style); + builder.AddText(" wrapped around to"); + + text_style.decoration_style = txt::TextDecorationStyle::kDashed; + text_style.decoration_color = SK_ColorBLACK; + builder.PushStyle(text_style); + builder.AddText(" the next line."); + + text_style.decoration_style = txt::TextDecorationStyle::kWavy; + text_style.decoration_color = SK_ColorRED; + builder.PushStyle(text_style); + + builder.AddText(" Otherwise, bad things happen."); + + builder.Pop(); + + auto paragraph = builder.Build(); + paragraph->Layout(GetTestCanvasWidth() - 100); + + paragraph->Paint(GetCanvas(), 0, 0); + + ASSERT_EQ(paragraph->runs_.size(), 5ull); + ASSERT_EQ(paragraph->records_.size(), 6ull); + + for (size_t i = 0; i < 6; ++i) { + ASSERT_EQ(paragraph->records_[i].style().decoration, + txt::TextDecoration(0x1 | 0x2 | 0x4)); + } + + ASSERT_EQ(paragraph->records_[0].style().decoration_style, + txt::TextDecorationStyle::kSolid); + ASSERT_EQ(paragraph->records_[1].style().decoration_style, + txt::TextDecorationStyle::kDouble); + ASSERT_EQ(paragraph->records_[2].style().decoration_style, + txt::TextDecorationStyle::kDotted); + ASSERT_EQ(paragraph->records_[3].style().decoration_style, + txt::TextDecorationStyle::kDashed); + ASSERT_EQ(paragraph->records_[4].style().decoration_style, + txt::TextDecorationStyle::kDashed); + ASSERT_EQ(paragraph->records_[5].style().decoration_style, + txt::TextDecorationStyle::kWavy); + + ASSERT_EQ(paragraph->records_[0].style().decoration_color, SK_ColorBLACK); + ASSERT_EQ(paragraph->records_[1].style().decoration_color, SK_ColorBLUE); + ASSERT_EQ(paragraph->records_[2].style().decoration_color, SK_ColorBLACK); + ASSERT_EQ(paragraph->records_[3].style().decoration_color, SK_ColorBLACK); + ASSERT_EQ(paragraph->records_[4].style().decoration_color, SK_ColorBLACK); + ASSERT_EQ(paragraph->records_[5].style().decoration_color, SK_ColorRED); + + ASSERT_TRUE(Snapshot()); +} + TEST_F(RenderTest, ItalicsParagraph) { const char* text = "I am Italicized! "; auto icu_text = icu::UnicodeString::fromUTF8(text); From 4ed0e488daed26d0c5fedf6cdff4f2d64aa05cfc Mon Sep 17 00:00:00 2001 From: Gary Qian Date: Thu, 6 Jul 2017 11:36:00 -0700 Subject: [PATCH 315/364] Add chinese tests, underline fix, cleanup, move fonts to third_party/fonts. Change-Id: I1b246534cd364c9e7e3fec3f6bcbe202932fee44 --- engine/src/flutter/src/font_collection.h | 4 - engine/src/flutter/src/paragraph.cc | 12 +- engine/src/flutter/src/paragraph.h | 1 + engine/src/flutter/src/styled_runs.h | 1 + .../flutter/tests/txt/paragraph_unittests.cc | 44 +++ engine/src/flutter/third_party/fonts/Bold.ttf | Bin 0 -> 884 bytes engine/src/flutter/third_party/fonts/Bold.ttx | 254 +++++++++++++++ .../flutter/third_party/fonts/BoldItalic.ttf | Bin 0 -> 956 bytes .../flutter/third_party/fonts/BoldItalic.ttx | 254 +++++++++++++++ .../third_party/fonts/ColorEmojiFont.ttf | Bin 0 -> 996 bytes .../third_party/fonts/ColorEmojiFont.ttx | 238 ++++++++++++++ .../fonts/ColorTextMixedEmojiFont.ttf | Bin 0 -> 860 bytes .../fonts/ColorTextMixedEmojiFont.ttx | 212 ++++++++++++ .../src/flutter/third_party/fonts/Emoji.ttf | Bin 0 -> 912 bytes .../src/flutter/third_party/fonts/Emoji.ttx | 238 ++++++++++++++ .../fonts/HomemadeApple-LICENSE.txt | 202 ++++++++++++ .../third_party/fonts/HomemadeApple.ttf | Bin 0 -> 110080 bytes .../src/flutter/third_party/fonts/Italic.ttf | Bin 0 -> 908 bytes .../src/flutter/third_party/fonts/Italic.ttx | 254 +++++++++++++++ engine/src/flutter/third_party/fonts/Ja.ttf | Bin 0 -> 1300 bytes engine/src/flutter/third_party/fonts/Ja.ttx | 306 ++++++++++++++++++ .../third_party/fonts/Katibeh-LICENSE.txt | 92 ++++++ .../third_party/fonts/Katibeh-Regular.ttf | Bin 0 -> 188360 bytes engine/src/flutter/third_party/fonts/Ko.ttf | Bin 0 -> 824 bytes engine/src/flutter/third_party/fonts/Ko.ttx | 224 +++++++++++++ .../flutter/third_party/fonts/MultiAxis.ttf | Bin 0 -> 844 bytes .../flutter/third_party/fonts/MultiAxis.ttx | 223 +++++++++++++ .../third_party/fonts/NoCmapFormat14.ttf | Bin 0 -> 844 bytes .../third_party/fonts/NoCmapFormat14.ttx | 207 ++++++++++++ .../flutter/third_party/fonts/NoGlyphFont.ttf | Bin 0 -> 712 bytes .../flutter/third_party/fonts/NoGlyphFont.ttx | 199 ++++++++++++ .../src/flutter/third_party/fonts/Regular.ttf | Bin 0 -> 984 bytes .../src/flutter/third_party/fonts/Regular.ttx | 263 +++++++++++++++ .../third_party/fonts/Roboto-Black.ttf | Bin 0 -> 171480 bytes .../third_party/fonts/Roboto-BlackItalic.ttf | Bin 0 -> 177552 bytes .../flutter/third_party/fonts/Roboto-Bold.ttf | Bin 0 -> 170760 bytes .../third_party/fonts/Roboto-BoldItalic.ttf | Bin 0 -> 174952 bytes .../third_party/fonts/Roboto-Italic.ttf | Bin 0 -> 173932 bytes .../third_party/fonts/Roboto-Light.ttf | Bin 0 -> 170420 bytes .../third_party/fonts/Roboto-LightItalic.ttf | Bin 0 -> 176616 bytes .../third_party/fonts/Roboto-Medium.ttf | Bin 0 -> 172064 bytes .../third_party/fonts/Roboto-MediumItalic.ttf | Bin 0 -> 176864 bytes .../third_party/fonts/Roboto-Regular.ttf | Bin 0 -> 171676 bytes .../flutter/third_party/fonts/Roboto-Thin.ttf | Bin 0 -> 171904 bytes .../third_party/fonts/Roboto-ThinItalic.ttf | Bin 0 -> 176300 bytes .../fonts/SourceHanSerif-LICENSE.txt | 92 ++++++ .../third_party/fonts/TextEmojiFont.ttf | Bin 0 -> 908 bytes .../third_party/fonts/TextEmojiFont.ttx | 239 ++++++++++++++ .../third_party/fonts/UnicodeBMPOnly.ttf | Bin 0 -> 696 bytes .../third_party/fonts/UnicodeBMPOnly.ttx | 177 ++++++++++ .../third_party/fonts/UnicodeBMPOnly2.ttf | Bin 0 -> 696 bytes .../third_party/fonts/UnicodeBMPOnly2.ttx | 177 ++++++++++ .../flutter/third_party/fonts/UnicodeUCS4.ttf | Bin 0 -> 744 bytes .../flutter/third_party/fonts/UnicodeUCS4.ttx | 181 +++++++++++ .../fonts/VariationSelectorTest-Regular.ttf | Bin 0 -> 1008 bytes .../fonts/VariationSelectorTest-Regular.ttx | 229 +++++++++++++ .../src/flutter/third_party/fonts/ZhHans.ttf | Bin 0 -> 1176 bytes .../src/flutter/third_party/fonts/ZhHans.ttx | 282 ++++++++++++++++ .../src/flutter/third_party/fonts/ZhHant.ttf | Bin 0 -> 984 bytes .../src/flutter/third_party/fonts/ZhHant.ttx | 240 ++++++++++++++ .../src/flutter/third_party/fonts/emoji.xml | 31 ++ .../src/flutter/third_party/fonts/itemize.xml | 39 +++ 62 files changed, 4903 insertions(+), 12 deletions(-) create mode 100644 engine/src/flutter/third_party/fonts/Bold.ttf create mode 100644 engine/src/flutter/third_party/fonts/Bold.ttx create mode 100644 engine/src/flutter/third_party/fonts/BoldItalic.ttf create mode 100644 engine/src/flutter/third_party/fonts/BoldItalic.ttx create mode 100644 engine/src/flutter/third_party/fonts/ColorEmojiFont.ttf create mode 100644 engine/src/flutter/third_party/fonts/ColorEmojiFont.ttx create mode 100644 engine/src/flutter/third_party/fonts/ColorTextMixedEmojiFont.ttf create mode 100644 engine/src/flutter/third_party/fonts/ColorTextMixedEmojiFont.ttx create mode 100644 engine/src/flutter/third_party/fonts/Emoji.ttf create mode 100644 engine/src/flutter/third_party/fonts/Emoji.ttx create mode 100644 engine/src/flutter/third_party/fonts/HomemadeApple-LICENSE.txt create mode 100644 engine/src/flutter/third_party/fonts/HomemadeApple.ttf create mode 100644 engine/src/flutter/third_party/fonts/Italic.ttf create mode 100644 engine/src/flutter/third_party/fonts/Italic.ttx create mode 100644 engine/src/flutter/third_party/fonts/Ja.ttf create mode 100644 engine/src/flutter/third_party/fonts/Ja.ttx create mode 100644 engine/src/flutter/third_party/fonts/Katibeh-LICENSE.txt create mode 100644 engine/src/flutter/third_party/fonts/Katibeh-Regular.ttf create mode 100644 engine/src/flutter/third_party/fonts/Ko.ttf create mode 100644 engine/src/flutter/third_party/fonts/Ko.ttx create mode 100644 engine/src/flutter/third_party/fonts/MultiAxis.ttf create mode 100644 engine/src/flutter/third_party/fonts/MultiAxis.ttx create mode 100644 engine/src/flutter/third_party/fonts/NoCmapFormat14.ttf create mode 100644 engine/src/flutter/third_party/fonts/NoCmapFormat14.ttx create mode 100644 engine/src/flutter/third_party/fonts/NoGlyphFont.ttf create mode 100644 engine/src/flutter/third_party/fonts/NoGlyphFont.ttx create mode 100644 engine/src/flutter/third_party/fonts/Regular.ttf create mode 100644 engine/src/flutter/third_party/fonts/Regular.ttx create mode 100644 engine/src/flutter/third_party/fonts/Roboto-Black.ttf create mode 100644 engine/src/flutter/third_party/fonts/Roboto-BlackItalic.ttf create mode 100644 engine/src/flutter/third_party/fonts/Roboto-Bold.ttf create mode 100644 engine/src/flutter/third_party/fonts/Roboto-BoldItalic.ttf create mode 100644 engine/src/flutter/third_party/fonts/Roboto-Italic.ttf create mode 100644 engine/src/flutter/third_party/fonts/Roboto-Light.ttf create mode 100644 engine/src/flutter/third_party/fonts/Roboto-LightItalic.ttf create mode 100644 engine/src/flutter/third_party/fonts/Roboto-Medium.ttf create mode 100644 engine/src/flutter/third_party/fonts/Roboto-MediumItalic.ttf create mode 100644 engine/src/flutter/third_party/fonts/Roboto-Regular.ttf create mode 100644 engine/src/flutter/third_party/fonts/Roboto-Thin.ttf create mode 100644 engine/src/flutter/third_party/fonts/Roboto-ThinItalic.ttf create mode 100644 engine/src/flutter/third_party/fonts/SourceHanSerif-LICENSE.txt create mode 100644 engine/src/flutter/third_party/fonts/TextEmojiFont.ttf create mode 100644 engine/src/flutter/third_party/fonts/TextEmojiFont.ttx create mode 100644 engine/src/flutter/third_party/fonts/UnicodeBMPOnly.ttf create mode 100644 engine/src/flutter/third_party/fonts/UnicodeBMPOnly.ttx create mode 100644 engine/src/flutter/third_party/fonts/UnicodeBMPOnly2.ttf create mode 100644 engine/src/flutter/third_party/fonts/UnicodeBMPOnly2.ttx create mode 100644 engine/src/flutter/third_party/fonts/UnicodeUCS4.ttf create mode 100644 engine/src/flutter/third_party/fonts/UnicodeUCS4.ttx create mode 100644 engine/src/flutter/third_party/fonts/VariationSelectorTest-Regular.ttf create mode 100644 engine/src/flutter/third_party/fonts/VariationSelectorTest-Regular.ttx create mode 100644 engine/src/flutter/third_party/fonts/ZhHans.ttf create mode 100644 engine/src/flutter/third_party/fonts/ZhHans.ttx create mode 100644 engine/src/flutter/third_party/fonts/ZhHant.ttf create mode 100644 engine/src/flutter/third_party/fonts/ZhHant.ttx create mode 100644 engine/src/flutter/third_party/fonts/emoji.xml create mode 100644 engine/src/flutter/third_party/fonts/itemize.xml diff --git a/engine/src/flutter/src/font_collection.h b/engine/src/flutter/src/font_collection.h index b5ba03ea92f..865af8b3807 100644 --- a/engine/src/flutter/src/font_collection.h +++ b/engine/src/flutter/src/font_collection.h @@ -89,8 +89,6 @@ class FontCollection { size_t cache_capacity_ = DEFAULT_CACHE_CAPACITY; // Cache minikin font collections to prevent slow disk reads. - // TODO(garyq): Implement optional low-memory optimized system to prevent - // fonts building up in memory. std::unordered_map> minikin_font_collection_map_; @@ -105,8 +103,6 @@ class FontCollection { static const std::string GetDefaultFamilyName() { return DEFAULT_FAMILY_NAME; }; - - // TODO(chinmaygarde): Caches go here. }; } // namespace txt diff --git a/engine/src/flutter/src/paragraph.cc b/engine/src/flutter/src/paragraph.cc index 8f4221e6188..3b07c4ee70a 100644 --- a/engine/src/flutter/src/paragraph.cc +++ b/engine/src/flutter/src/paragraph.cc @@ -98,7 +98,6 @@ void GetFontAndMinikinPaint(const TextStyle& style, paint->size = style.font_size; paint->letterSpacing = style.letter_spacing; paint->wordSpacing = style.word_spacing; - // TODO(abarth): word_spacing. } void GetPaint(const TextStyle& style, SkPaint* paint) { @@ -187,8 +186,6 @@ void Paragraph::Layout(double width, bool force) { for (size_t i = 0; i < x_queue.size(); ++i) { record_index = records_.size() - (x_queue.size() - i); records_[record_index].SetOffset(SkPoint::Make(x_queue[i], y)); - // TODO(garyq): Fix alignment for paragraphs with multiple styles per - // line. switch (paragraph_style_.text_align) { case TextAlign::left: break; @@ -303,8 +300,6 @@ void Paragraph::Layout(double width, bool force) { // TODO(abarth): We could keep the same SkTextBlobBuilder as long as the // color stayed the same. - // TODO(garyq): Ensure that the typeface does not change throughout a - // run. SkPaint::FontMetrics metrics; paint.getFontMetrics(&metrics); // Apply additional word spacing if the text is justified. @@ -471,6 +466,7 @@ void Paragraph::PaintDecorations(SkCanvas* canvas, // This is set to 2 for the double line style int decoration_count = 1; + // Filled when drawing wavy decorations. std::vector wave_coords; double width = blob->bounds().fRight + blob->bounds().fLeft; @@ -525,9 +521,9 @@ void Paragraph::PaintDecorations(SkCanvas* canvas, // Underline if (style.decoration & 0x1) { if (style.decoration_style != TextDecorationStyle::kWavy) - canvas->drawLine(x, y + metrics.fUnderlineThickness + y_offset, - x + width, - y + metrics.fUnderlineThickness + y_offset, paint); + canvas->drawLine(x, y + metrics.fUnderlinePosition + y_offset, + x + width, y + metrics.fUnderlinePosition + y_offset, + paint); else PaintWavyDecoration(canvas, wave_coords, paint, x, y, metrics.fUnderlineThickness, width); diff --git a/engine/src/flutter/src/paragraph.h b/engine/src/flutter/src/paragraph.h index 85b45811eb2..04ed7e7a60b 100644 --- a/engine/src/flutter/src/paragraph.h +++ b/engine/src/flutter/src/paragraph.h @@ -72,6 +72,7 @@ class Paragraph { FRIEND_TEST(RenderTest, JustifyAlignParagraph); FRIEND_TEST(RenderTest, DecorationsParagraph); FRIEND_TEST(RenderTest, ItalicsParagraph); + FRIEND_TEST(RenderTest, ChineseParagraph); std::vector text_; StyledRuns runs_; diff --git a/engine/src/flutter/src/styled_runs.h b/engine/src/flutter/src/styled_runs.h index eedd9e7a89e..d61ea1c57f6 100644 --- a/engine/src/flutter/src/styled_runs.h +++ b/engine/src/flutter/src/styled_runs.h @@ -66,6 +66,7 @@ class StyledRuns { FRIEND_TEST(RenderTest, JustifyAlignParagraph); FRIEND_TEST(RenderTest, DecorationsParagraph); FRIEND_TEST(RenderTest, ItalicsParagraph); + FRIEND_TEST(RenderTest, ChineseParagraph); struct IndexedRun { size_t style_index = 0; diff --git a/engine/src/flutter/tests/txt/paragraph_unittests.cc b/engine/src/flutter/tests/txt/paragraph_unittests.cc index 7509e2e05d5..5cb2a75bc64 100644 --- a/engine/src/flutter/tests/txt/paragraph_unittests.cc +++ b/engine/src/flutter/tests/txt/paragraph_unittests.cc @@ -750,4 +750,48 @@ TEST_F(RenderTest, ItalicsParagraph) { ASSERT_TRUE(Snapshot()); } +TEST_F(RenderTest, ChineseParagraph) { + const char* text = + "左線読設重説切後碁給能上目秘使約。満毎冠行来昼本可必図将発確年。今属場育" + "図情闘陰野高備込制詩西校客。審対江置講今固残必託地集済決維駆年策。立得庭" + "際輝求佐抗蒼提夜合逃表。注統天言件自謙雅載報紙喪。作画稿愛器灯女書利変探" + "訃第金線朝開化建。子戦年帝励害表月幕株漠新期刊人秘。図的海力生禁挙保天戦" + "聞条年所在口。"; + auto icu_text = icu::UnicodeString::fromUTF8(text); + std::u16string u16_text(icu_text.getBuffer(), + icu_text.getBuffer() + icu_text.length()); + + txt::ParagraphStyle paragraph_style; + paragraph_style.max_lines = 14; + auto font_collection = FontCollection::GetFontCollection(txt::GetFontDir()); + txt::ParagraphBuilder builder(paragraph_style, &font_collection); + + txt::TextStyle text_style; + text_style.color = SK_ColorBLACK; + text_style.font_size = 35; + text_style.letter_spacing = 2; + text_style.font_family = "Source Han Serif CN"; + text_style.decoration = txt::TextDecoration(0x1 | 0x2 | 0x4); + text_style.decoration_style = txt::TextDecorationStyle::kSolid; + text_style.decoration_color = SK_ColorBLACK; + builder.PushStyle(text_style); + + builder.AddText(u16_text); + + builder.Pop(); + + auto paragraph = builder.Build(); + paragraph->Layout(GetTestCanvasWidth() - 100); + + paragraph->Paint(GetCanvas(), 0, 0); + + ASSERT_EQ(paragraph->runs_.runs_.size(), 1ull); + ASSERT_EQ(paragraph->runs_.styles_.size(), 1ull); + ASSERT_TRUE(paragraph->runs_.styles_[0].equals(text_style)); + ASSERT_EQ(paragraph->records_[0].style().color, text_style.color); + ASSERT_EQ(paragraph->records_.size(), 7ull); + + ASSERT_TRUE(Snapshot()); +} + } // namespace txt diff --git a/engine/src/flutter/third_party/fonts/Bold.ttf b/engine/src/flutter/third_party/fonts/Bold.ttf new file mode 100644 index 0000000000000000000000000000000000000000..44ef33cf89e6ea8e913879981a1ce110d0122d22 GIT binary patch literal 884 zcmc&yF-u!f7(Msis8MT62OY#AsSc$W#0=t~Ra6udTB?z{Sbdn6MoIDlc~HBFQz@>J z)k4QYC(*$*kRcuFQs`W$KR|J5^LoCU_eAsu^gizU&N<)rKF)XVg96ZnJs2cju8gF& z7k4HB^_1%7R?#W9T{maRkI3iV7T)L3Mg;YTuY@4ZrIOoATj^jwc> z)Fpd@lUZlcB(v za-u;z!zjB + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + BoldFont Test + + + Bold + + + BoldFont Test + + + BoldFontTest-Bold + + + BoldFont Test + + + Bold + + + BoldFont Test + + + BoldFontTest-Bold + + + + + + + + + + + + + + + + diff --git a/engine/src/flutter/third_party/fonts/BoldItalic.ttf b/engine/src/flutter/third_party/fonts/BoldItalic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..10c7b02b955c0f67c51f83820715a3a1a3274798 GIT binary patch literal 956 zcmc&zze^lJ7=1Id>Zu_X{-_e!BN9UJ2)RN;l!y^Q4ibopHX4_^)jQd{J-7uGEJ8>j zA^jDxu&@-Y1PeQnSR{y+X>0`j0}N>rH*eH^V{zXu$_4*l#CZ zBy*{yAwWE%I-kxv#fIP4ugN#bM;E=-1vC&r{NeH?>pB_r@#``1HfLX!g0&?NiO)HE zviV>|9f}j?uakFqe%iq)cF1+SEAOln@x67IJVtI8oV@!F|F9qQql7QOK zacHlcTWe>>@7o4{L8wbAIPEO|F#F6wx89@C1Q{WoQI{d>iYv^DGGEVc; zkE%K1iZ#K`j5GSW{V_;qiZ28@vcMjQWArBxM*^-AVMr~GUN{V%`i3Ymw{a^M2-a7X{+K#vfuUyTQzzk9`jQWRx_hdF%V&i z4$Mc`s?i&n5sdg=W;}4bTzbqe1oos`s*!F6bu95;!U%kL$Y2}+9HJc3yh9%aavPIy aQ6j3BRZpv)te#8MJ*lGC+13BR-SH2aTAE1! literal 0 HcmV?d00001 diff --git a/engine/src/flutter/third_party/fonts/BoldItalic.ttx b/engine/src/flutter/third_party/fonts/BoldItalic.ttx new file mode 100644 index 00000000000..5de79fcb7f1 --- /dev/null +++ b/engine/src/flutter/third_party/fonts/BoldItalic.ttx @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + BoldItalicFont Test + + + BoldItalic + + + BoldItalicFont Test + + + BoldItalicFontTest-BoldItalic + + + BoldItalicFont Test + + + BoldItalic + + + BoldItalicFont Test + + + BoldItalicFontTest-BoldItalic + + + + + + + + + + + + + + + + diff --git a/engine/src/flutter/third_party/fonts/ColorEmojiFont.ttf b/engine/src/flutter/third_party/fonts/ColorEmojiFont.ttf new file mode 100644 index 0000000000000000000000000000000000000000..eee1c379f0314d1b2ce632a71bc62b6b19d6d82f GIT binary patch literal 996 zcmaJ=J!lj`6#iy*bGamHgqT8&un=8Eje$e_!3aV~nt+lsq6mpD@w~gRdwbknFj`p# z8*Sto%ODmZ-GPOLMFMFAiM5?Y1g$&^i@1JoW+RCK-|@}+=DqLDdpo-a1)v*G;lR6b zb2wL8E?xoDDMs(lMnSc8@%aq*FNm&U`1m12552@?pi~GRxEpI{$d`!=B?jCjy+;0p zI9`ex3wjdMtX1teWByW)e zoK?x2-t0g5`Q+lg-jSbB&L-p7=x=@y|LM)QC*o7=55cH~nSa8E}G7_}xp_Pl!422Lb;y@e&+Z?4wzM zgY+vY*vi{)!6V>}SO_0HYGL?SazeO&%))SKLKyCo6NXD;!titCgyF;Fgy9@ahBN#Z zIYF*|)D0}(BHyy{cA4*}Z1r6Et;n-;AZtmoX9r}FewEbq{mpCE_NA5Xj(7$~_;aA# zE@pk4Pq}8NyD4{f#4}WsM&mH9jYaWXc|5K(ys1LHkuMbI!=Sc1BZ;9jgHgl?i5kWb r(a)ibarz1x@Gyk}>STHPBIc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ColorEmojiFont Test + + + Regular + + + ColorEmojiFont Test + + + ColorEmojiFontTest-Regular + + + ColorEmojiFont Test + + + Regular + + + ColorEmojiFont Test + + + ColorEmojiFontTest-Regular + + + + + + + + + + + + + + + + diff --git a/engine/src/flutter/third_party/fonts/ColorTextMixedEmojiFont.ttf b/engine/src/flutter/third_party/fonts/ColorTextMixedEmojiFont.ttf new file mode 100644 index 0000000000000000000000000000000000000000..57ee330b79f66be79c74b7f18e323a178620df58 GIT binary patch literal 860 zcmb7CF>4e-6#iy*lUq$N)pd#siWo5{SI8BKh#}X+D4r+UoVw&TcNcbVkGl=77Gfia zSlHbk5NyOQBBEs^jS#H-0TyZOVxdLW@6C>K2nxPs_I=-b-+S|BXQ2Qb#6vjnuUtD* z=^Sal2GmJL@2ti_|7_%6B!5PJz8&3LgU)mE&*Y~%VbF43ecd5`$#t&7fcso;5r5%2 z-igypU&UMMACr4gvKrtJ4wFlb7YA7%TT`3l9=YEO;_$=!*-LpI`PUx9D{^w zOmoh=L<>_R3Bb{HeuW8m`iZ_tzFc^93l()*1QYTqOy>M;*OzZx#s&De@A#Zyn=@}S zX*6n2za#dG$v9WjW~A9PzZK;4oMvC3n2-IL0%4Y3;lvNqir~9FZ;5qf6Es4(uYWR8 zd04X=CHG^oMv2T!3U@3%iDP^mDE9!fRn#oj-1&jU?pS=1il>W7lnfeSmacTOu(cE? z>)l$?OZ`STOzUBLBMJt8k%(f>O0b9o5!V0>gvgL$1zq|OEi55sW}Uo7-($`;{H8GHW(n}CW{ literal 0 HcmV?d00001 diff --git a/engine/src/flutter/third_party/fonts/ColorTextMixedEmojiFont.ttx b/engine/src/flutter/third_party/fonts/ColorTextMixedEmojiFont.ttx new file mode 100644 index 00000000000..461210bfd88 --- /dev/null +++ b/engine/src/flutter/third_party/fonts/ColorTextMixedEmojiFont.ttx @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ColorTextMixedEmojiFont Test + + + Regular + + + ColorTextMixedEmojiFont Test + + + ColorTextMixedEmojiFontTest-Regular + + + ColorTextMixedEmojiFont Test + + + Regular + + + ColorTextMixedEmojiFont Test + + + ColorTextMixedEmojiFontTest-Regular + + + + + + + + + + + + + + + + diff --git a/engine/src/flutter/third_party/fonts/Emoji.ttf b/engine/src/flutter/third_party/fonts/Emoji.ttf new file mode 100644 index 0000000000000000000000000000000000000000..a3413b3e08f96ab5b2a0b5cffd1cc249026ffd40 GIT binary patch literal 912 zcmcIiJ#W)c6g}_RO#(rbfk+G$G9Lq~D3lBciGWzzr3j=D1WN%^Tqji=Ta7Eqf|w9O zAh87@M#O*^xy-#ho*k9VGJC;)r$2oAif*G|{l zr^54qIzjf%QsgH`8%JI-e#!V@*nO}JH_rhr`Md4Fzvpbc+aP{VKiekZzR{nENA%6F!p+W6uce2zR3JD#-k+er}+oe0f#;C zAX@3uqwmjePd0u+Ia_4#tv2{#_QzkTZER)e0<*{2%FnSm!=f5s(M%c_5-7uz4H8~s zAEt1h=t6ZM1RUK|FED|MeyVRWUa-5mg}OQ^1rxGZ6P;tbzHs9TE@3v$9gi9|sdBdk=V1!sO!%o8tl-6{5Dcu$9}Gd=?cFlxrx>23SI*xDi*tJR@*sCEbj7%AJ%17 z78;imRMs&rLsXU+-@Zzj=hgTYj$s;Sm@iDe|E@$bzk=mrwlcT1r)r26i`^Z3iTY}C zBXI3@^og3>L#&|-AFKbV+^(DXtJ1NrF(1l*{jdE7riqAK literal 0 HcmV?d00001 diff --git a/engine/src/flutter/third_party/fonts/Emoji.ttx b/engine/src/flutter/third_party/fonts/Emoji.ttx new file mode 100644 index 00000000000..3318c594ae1 --- /dev/null +++ b/engine/src/flutter/third_party/fonts/Emoji.ttx @@ -0,0 +1,238 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + EmojiFont Test + + + Regular + + + EmojiFont Test + + + EmojiFontTest-Regular + + + EmojiFont Test + + + Regular + + + EmojiFont Test + + + EmojiFontTest-Regular + + + + + + + + + + + + + + + + diff --git a/engine/src/flutter/third_party/fonts/HomemadeApple-LICENSE.txt b/engine/src/flutter/third_party/fonts/HomemadeApple-LICENSE.txt new file mode 100644 index 00000000000..d6456956733 --- /dev/null +++ b/engine/src/flutter/third_party/fonts/HomemadeApple-LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. diff --git a/engine/src/flutter/third_party/fonts/HomemadeApple.ttf b/engine/src/flutter/third_party/fonts/HomemadeApple.ttf new file mode 100644 index 0000000000000000000000000000000000000000..75d4fbcb8b50189a2b6c68c6b4aa32750075ddb1 GIT binary patch literal 110080 zcmdSC37Dj3S?~Ss`@YuR)m7b9-90@$OZQYILo(UJ5*0`U5?KQY3CI$51VlvHMhuF8 z$dM!>vM9@_2oVuMLO_s3MDzecg394TL_ME)P|4KyyWi@>py-8OdR^a{sr9XQdEV!_ zpL_Y=|NCi0RTL#so~P)_Bkp_Ip`(v}#^sMv6!luRKH^c2zw)|!tv}##ief%OQM8Xg z>gi7%DkZ-t?$7h0J^H$99{=+5KKqY~;vD9fE3dioDc32r;wtJ}-^B09HIMtDM?dV9 zH|;8lf1RSf=H_d!zVfPX-0S?S`R!{wXV~=>ND$0KYAA5KddPF zs~`8oM_u{Am;B|cx!z4|`}pIpeCBn!Zv8o*@5TPZCtUgXs}KI+gWs;GZ`h!XS6=tT zr#$ty-|#norKrF1QkvJj?#WkQcdhl(7jXP5*xy#;BtOYPigvkvnztceAI-Oo#ckR@EOxb)Vrf5g$L-qv z7C)vvW%1+Ms}>K@Zd|-yJGCgZ&SFLV!_#lmpQ~)@4^=jmPbiy4uH@=ddH#Y@s24B3 ztUhP)m+A`@UCycglCq&@%7e6DTHK+{Ip)R6rRr}gx$;W39Z(8QSt#mHDECvJ%rR#y zu2L^s{H|IoZdYHrc(m4D{59t_wZ|;ptaTTk(;m0@ruMMKjas3Y>Tf9zQopkJl=>%1 zNBzFV7u9=l>}zSm%NBpHK9_TSO1W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me!KWHdX|^osgveTUH)8dgY_S+FTjoP@2&sG`keKDTYrvq$XR*I!_pP3qE!O#TgKXkSkszSr`Fsg z-w<1gm0~;F)Q-DW&+1zP7@|hj*qUIyXVwb53k!z-8nNOAL;DyfdYn@|!71;MQ`seU z+P6-Vg*$^~z6xajHKv<%4RCk$4c(3&>45K&jQ19oqK1fwngZE(` z=$jb^-^OJ84(qMfcfy78UDkKAqWpF1`>gM`-e&y`>u;jr^8?o3w*HRwgRCz9o%KW3 z4_klF`cdm0@TtGc`U&eFSnsypW4+hB(;mY^{>(3{(bBJvi`vOwDp+nS^t~$@BBC2fA9A8b=$dT zzv=7);e&Ucz4w7TFlrCqdG^jby!&pu{p($|J`hC|A%S?3Ym5$;HK*=-kS59cW_Axx{R1+`?7a7WZ-@8$?Lh$O#2OUb*V9jP zrS#GZKs=^8Uo7id+wXs)%1^RDJ{6tf9dcs880=sSuo)v@o-6ileQlg;?<5G zq}b6zJi#Dud5LjW%slO~cl=)lcC`>E66j^DD33&fEW%EUo?t&IPDVH#tftvlgw2HLL~lf+Wh0771kmuYh$3fIMTOi&9v + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ItalicFont Test + + + Italic + + + ItalicFont Test + + + ItalicFontTest-Italic + + + ItalicFont Test + + + Italic + + + ItalicFont Test + + + ItalicFontTest-Italic + + + + + + + + + + + + + + + + diff --git a/engine/src/flutter/third_party/fonts/Ja.ttf b/engine/src/flutter/third_party/fonts/Ja.ttf new file mode 100644 index 0000000000000000000000000000000000000000..b3d4e848ecf02d71b1cdf7ddc2cc4e649a7ae1cd GIT binary patch literal 1300 zcmds1OKVd>6#nibFB4M*D+(?y>O$0F3{(qMEJ1^$XdqT9l-geFZ6fAzX;Q7=LdAu+ zav?+naU&uqf{Uu4xDbSH1ktTKEp%g7QCvu`-f!#L@w8+T;sdB7ciGZuDEkPKE&r~k5YE3ZpB-FapPUa|3Uei zU#mBQ=STx~OYD$ZiIq=@R}($^zQV914&L`R->UV+o%^!3M+9b@agVhW3~+M`<3*!y2%; z<}~D9R3avmVpT#WMUPG_$t6AuQ$Q4$U^@kf0GGdLAPii2qQM6%1uGy1+-7V6RTmBqB0ieps A9smFU literal 0 HcmV?d00001 diff --git a/engine/src/flutter/third_party/fonts/Ja.ttx b/engine/src/flutter/third_party/fonts/Ja.ttx new file mode 100644 index 00000000000..562ff04ca5b --- /dev/null +++ b/engine/src/flutter/third_party/fonts/Ja.ttx @@ -0,0 +1,306 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + JapaneseFont Test + + + Regular + + + JapaneseFont Test + + + JapaneseFontTest-Regular + + + JapaneseFont Test + + + Regular + + + JapaneseFont Test + + + JapaneseFontTest-Regular + + + + + + + + + + + + + + + + diff --git a/engine/src/flutter/third_party/fonts/Katibeh-LICENSE.txt b/engine/src/flutter/third_party/fonts/Katibeh-LICENSE.txt new file mode 100644 index 00000000000..b66a0c31aab --- /dev/null +++ b/engine/src/flutter/third_party/fonts/Katibeh-LICENSE.txt @@ -0,0 +1,92 @@ +Copyright 2015, 2016 KB-Studio (www.k-b-studio.com|tarobish@gmail.com). Copyright 2015, 2016 Lasse Fister (lasse@graphicore.de). Copyright 2015, 2016 Eduardo Tunni(edu@tipo.net.ar). +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/engine/src/flutter/third_party/fonts/Katibeh-Regular.ttf b/engine/src/flutter/third_party/fonts/Katibeh-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..ccbb8f0de2ad5c5afaec2fc8f5b642b804ab6928 GIT binary patch literal 188360 zcmd>ncVJY-*7(fbTekPzyDi&GHa*#FHVGjiBqW5;d+%MUbOAw-BE48?0t!kK5gUq1 zlcp3Av4IWnJsWmW0=vI6cXz|0yzhJ8-@k;DJ9qBv%$d{Y%-jWGgpd-=Mk3U|wz@^l z3rjAJLR6FE2(i-I_U$@#?f5!}sLJyQO}$pzsY~;Q(VzZ+sMn4lDxp>&9X+!I0H=BY`_7Q~Nxi);r zfWb1+yXWB9_W(u1p@J=7Bha50?!CiDPn>$``d{tg9`NCvqs9&z@XJrr`y%AdLrAu2 z^nj`3*lg-FJZ}l@on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E@b(3$x`{Il)@Vjah51#gfFw3qg^z3|!F?II?X z3Y#fxt#Dt38x(F7hOBxgfj z{HM<0Uzmc3WXd@oDywKD#`Jh8bcs17g)ZU!q{x=I z$8md{lQ;KIwJ-453cd`nl=Mk$lT)38)R7V9SlJ;`V*fH$8pT-o~ab zOI@Ct$QwQJTgrI!2*%!Lq$a1X;p|OZ<$6$8Kkpc>q4b`o?He zDdo7g#QG*-js=ny-nB{&EJ{72zU!Xy8B1)d{-t(yz?Y=Q=nRp2OCy)PlqxwDyGVR3 zDU4-^1t2Voqu>#~@xqb1IH9*p=n|tbq*&5pN$a&>u^fquRr^+4Z$*yGBYW&wl4(Mk YB}7NwoxyKBV`rQfT+N@~ literal 0 HcmV?d00001 diff --git a/engine/src/flutter/third_party/fonts/Ko.ttf b/engine/src/flutter/third_party/fonts/Ko.ttf new file mode 100644 index 0000000000000000000000000000000000000000..51f6c4ede8b4d02b18bfd591d2a478e13b5342b0 GIT binary patch literal 824 zcmbVK!AlfT9RA*Wqr0VK2%8=v2J8@`1bc`MN`kTnmkKt+J-F6j<1Vx_v+Rzfx9Aj} zM1t+$G3t_CLJ0CEk(WFOLVrL9>1?-P`hGLxu2d&~!|?mQ@AtjO_vQ^0fQxtz1N;7i zoB7<+iPwO-LG|&H=QQ4Vvxnrb$Y-kcwPlznBL6{NsJYG)^I~h7_&wiSH44@n{e@WO z*K1z5sz0b9`d^aw*MlVoqqsxj417%&{^cu!eteI>!#nu_UmyU8VXu6JH z2>j5Vb6a7_t*+FaW>*z)JXKLdfF@ix@KGT45%O!!QE3sC*sEAUo%7~@y{FFczr4I} NIW7?G$p80m{Q=6ZhFbst literal 0 HcmV?d00001 diff --git a/engine/src/flutter/third_party/fonts/Ko.ttx b/engine/src/flutter/third_party/fonts/Ko.ttx new file mode 100644 index 00000000000..06f12ecf54b --- /dev/null +++ b/engine/src/flutter/third_party/fonts/Ko.ttx @@ -0,0 +1,224 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + KoreanFont Test + + + Regular + + + KoreanFont Test + + + KoreanFontTest-Regular + + + KoreanFont Test + + + Regular + + + KoreanFont Test + + + KoreanFontTest-Regular + + + + + + + + + + + + + + + + diff --git a/engine/src/flutter/third_party/fonts/MultiAxis.ttf b/engine/src/flutter/third_party/fonts/MultiAxis.ttf new file mode 100644 index 0000000000000000000000000000000000000000..1d687cb367d740ad61bf6e3c633ac76732d05c91 GIT binary patch literal 844 zcmZ`%Jxmlq6#iy*?+&<&8l#CuiY@4bXf8%6G?9jefbqb91?c2hcF*kn)x)YQ-zi?en8W_G!t!AWM``@Z+RnKy3+0ze+?aB%m@{GDRB z5^MotlI+WJRW(q6!P~^+Yp+%F$MNxRz_~^|8ANZ^VDcf3xQvFrTFtzByGehS^L|Le z{V2cD?{kiYRo#_Ou}u92aW<-#6)qu1{N3QH>NfB-ze9Y3*sH0k@0YW;iGOm+M!luu zFDL@i?C06DdH(0U^#?C5Kl}yZoRG)i_1=N8N6$Z<8k>$BWa=@;If;2k(Z{mru_Akm zGa;?8jL|0%$v%vtL;NV;vpPqX#0O+BB;U&=GBb%4D=3O_qsUm9UH;nr+05b`9z#Jn z9&6ZV&HGeYjp$3$IWMWqbc#dpZANGda7~1(Yt<@_iMYnwNj6cA{Y>|wg;fkrw+I+Q z`fAL&I#5dt6D3;r9G}Ha++qd79cFY4_flU{vy}SoIX=txc{SUPbY-erX-(H_+FS5j zdcX`E6EcyBk{`4q)x<2?h@ery6uMknm_{8nG9DJ-6YC2!|Ia$hnLvrzf!$r9$s0SS jH|)-i`AZiJ(}gSiEfVIR7doptOnaC1R-hAv`d{u3H>`$T literal 0 HcmV?d00001 diff --git a/engine/src/flutter/third_party/fonts/MultiAxis.ttx b/engine/src/flutter/third_party/fonts/MultiAxis.ttx new file mode 100644 index 00000000000..7c17198c5c8 --- /dev/null +++ b/engine/src/flutter/third_party/fonts/MultiAxis.ttx @@ -0,0 +1,223 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + wdth + -1.0 + 0.0 + 1.0 + 256 + + + wght + -1.0 + 0.0 + 1.0 + 256 + + + + + + MultiAxisFont Test + + + MultiAxis + + + MultiAxisFont Test + + + MultiAxisFontTest-Regular + + + MultiAxisFont Test + + + MultiAxis + + + MultiAxisFont Test + + + MultiAxisFontTest-Regular + + + + + + + + + + + + + + + + diff --git a/engine/src/flutter/third_party/fonts/NoCmapFormat14.ttf b/engine/src/flutter/third_party/fonts/NoCmapFormat14.ttf new file mode 100644 index 0000000000000000000000000000000000000000..2a0c46c7aca19c80833cf8f1a3f0e1e39be7b232 GIT binary patch literal 844 zcmbVKF;5gh6#iy*y*uCnmE9#wL5u~&a3O{QjgbTrAV;{xV1qh`%U!YSUheh+6eep2 zR1%Bh2UyaQ5U|9A#zy~u1qGcAmS+8CckhB48)h@_z3+YBym>n_5C8@d!Gc0C~u9(NyyWKCwe>)gkHa;79$SmR->nfgR&1#mNyg|?Mxuxk zwum1MbrYQ>t2~7}D9C;JoSDVcix(&h(;cb)_@nx>#kC5aIFS=sialJg=L;$mjkuQP zBvjg&IVldoyBMS|!Zr-8ZPZQ_$EiJfm#!w4=Xv&eW?&S3E=52A*{zWo?emgrM>DN` zBcH=Peinp1K=v_~vRHDb{VcX` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No Cmap Format 14 Subtable Test + + + Regular + + + No Cmap Format 14 Subtable Test + + + No Cmap Format 14 SubtableTest-Regular + + + No Cmap Format 14 Subtable Test + + + Regular + + + No Cmap Format 14 Subtable Test + + + No Cmap Format 14 SubtableTest-Regular + + + + + + + + + + + + + + + + diff --git a/engine/src/flutter/third_party/fonts/NoGlyphFont.ttf b/engine/src/flutter/third_party/fonts/NoGlyphFont.ttf new file mode 100644 index 0000000000000000000000000000000000000000..0243f820408af7cd33497de3b01c19e43ab71e67 GIT binary patch literal 712 zcmZuvze~eF7=3paZT&%=1P6r-4kC)sK^zoZDu|#^E4uh2)YuA56KsmsNe4m1!L9#* zpo4>hii4X9E-tRF4*mgkj_;Bv^~Z(F_ul*7efjP#5CGb-2L*F(ek5J&E8GBLfa+S_ zu{?BQg#4Jizfh`eKm-B#6?v*?TkC3nbCmdkbF@goIF*mYZ=C%_$KMeREYp8TZj{`- z#h4(!)ZDRlJluC&lPAf|vgO!kuQ!|I59Dv2Tk(Tiqyc%Z^U%F=dX_uA+BNJBZ9pjOJj1kwU_h5{R*^Q{PBVDO^h_BjlMsnZ1*rsKoqaGTS%!(7VASsXJ z5|x=KiWQ{Akao0$w(#|%`ohfOEGA)MSDEbLi9J8j6?#NN-VvKoXQ8Ti8{pRs^f1b3 z5BkhGqq>PWGOhJ+B*B{rkwA(u!jfm5im}n8x1yVmf-u^c?Zse>B|TFyHk$NSI&vAu z^J`OX**9}`#n0M>YRTIA7PU4Ui^#x%2Ol+7b5SNTk%Ns2QI@fQDoU`h^^fz*H~h<~ NqKyXE`hWO4J^@wzZEXMm literal 0 HcmV?d00001 diff --git a/engine/src/flutter/third_party/fonts/NoGlyphFont.ttx b/engine/src/flutter/third_party/fonts/NoGlyphFont.ttx new file mode 100644 index 00000000000..72c9f292f05 --- /dev/null +++ b/engine/src/flutter/third_party/fonts/NoGlyphFont.ttx @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + EmptyFont Test + + + Regular + + + EmptyFont Test + + + EmptyFontTest-Regular + + + EmptyFont Test + + + Regular + + + EmptyFont Test + + + EmptyFontTest-Regular + + + + + + + + + + + + + + + + diff --git a/engine/src/flutter/third_party/fonts/Regular.ttf b/engine/src/flutter/third_party/fonts/Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..ab638f58de03bb8514e197653aee37795765ad39 GIT binary patch literal 984 zcmd5*ziSjh7=1Id-mN)Ni#uYWGC>QGT*NCviVIrBA{gO}n8K(_+}suS%iM;XLLik9 zt8@oeDeM%n38WCL0zrtyl{PklDJ^2BuJ7C3J1^!R@LRr{_ulu-%$pew3cwK7U|?_E zzEY^1UvC5I64i$bHLrQ25WFSdB!674K3PO63;{h#{<7kGkIcK*W5jQm;}r_dE4@Sf zm3gsJ3)*H!v#y?#pQ$z$JaqAs^RvQhUb~6C%ogh|xvhIOf9}Iasqd11Z#G&%xQzl} zwxtg7%6z)Mk$rHg_yfx9Q$aV^*^9jpyW1K>WBF3$DQfBGq{csTQrs)cIjD8 z7xkzE{hrvy&gkptCtl*kvwWi=;;T5x-*Zfb-vV + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + RegularFont Test + + + Regular + + + RegularFont Test + + + RegularFontTest-Regular + + + RegularFont Test + + + Regular + + + RegularFont Test + + + RegularFontTest-Regular + + + + + + + + + + + + + + + + diff --git a/engine/src/flutter/third_party/fonts/Roboto-Black.ttf b/engine/src/flutter/third_party/fonts/Roboto-Black.ttf new file mode 100644 index 0000000000000000000000000000000000000000..689fe5cb3c715f2944fec30e43ccb8a2b10625d3 GIT binary patch literal 171480 zcmbUK2V4|M^FNMv_sr~)S+a=YF42I3lFVYx0WqNnn6qLI=b6(P&YW{NJ@c|=&z!TE zv!Y@K#XGYw`+xTg3(ND|^Zoo@|Hayx>6z)SuBxu8uI^b0C4{)*OCqSm*jJn#Xss$7WW*CTtpOn(bDGD6R#-YL^)4awPt=m! zrC+BMI=r1PAwKO;X}vDPhUhhp<*E@9wgA`LcTefjZ{kn?t%Q_agJ%x)=rlNm*bq0g z$DeoT(RXC`Hd7rXLaOKpeOjbv*M1{@U%SRch-VBTQjwnBI(5x;yxtPehT#6Fo+z;I zX!il8O6Yxw$!gkZG)I_7G&mQ;y}~41A<{A_995Q3v2cxa=gnA}A|#zKa|@#HfI>a5 zyngfM^+^mN=3EVt3F)p~#&ChI=GVl^k`X6*A_z0l@4OGiZ5&u6>A`*@-r`2$E3PAP zQZ{KXbtM&PRZ@oCAS2i{Qc~DYii-6}Syqyi5tfoAtPdH=u9~0Y{?>qvfGU8{Jlp~} z4iEuo1!&HCkYTJDsUy0Ra^g-hPAp0Wh;F2Wwlt|C4L0XWrAU7%hSZfpNPlq@AQ|UF zNK0uo>CbwTDdJcXAo-%a4e75HaBUS}3hs|oa096#Fe5RNJ?@Joy`+ZV!zbb)`4Cak zm~+Laq&llf`U<_wnZQoM0umrV`fMMG5^IpM;&{?YED3tY0XmRs>?Ls!myu|35^2lA zNdhZno(Y;d;W$N;fqN&CcH$V^%by!dA_N;?Z{p96;<pWk|GQSZ&r|Hgyak&B)1uGb3hIuKQXRzvITqc zL7YLlv3X>=IE?g_J`tTXjWm?}2^A-hSZOWk3*1oCnKY2T5`U>1_&SbM6(2x%iem(f zC6VG((h)q0;^Sf zWN?!V5r3L9HJ8kv(S{esXI-1FB)}#a^!x-pGe{fJ3_Z*yPB!g`y<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vSTup633F9j5DB#`B%D zr_aHU>oTr!ui~C>zVbP}?!!d+X}9;;>wVtzK4ERQh&wtQNiUwC4*T#&eE3=7>n34? zm4`j;gm#hs$VV$C<)@aEKL@+O2zO6&Q?SGGzXKJ|MS=Xc+UFr7wGa)IgpKxP#QRtA z{{IwzZsDRd?=s)Jld1o;l&xds?}WH{p`+24EMuzSw#0 z7VHA_jwgm3f=j-;2fNS>#m;kgVHdbu?DA>eflIy{j$P>P#LjbfV;8t#*k}up!7oDz zuV=7h<}98cXR`w@!j7P}$hUUv_W@UmJwBWQ#w_SGWl~u#gRrVDoaQ10Z zBsr2&`j#a-N#13j$12`0`;>*06#%~it{;p&_tfRMC6O-NrsX8|E-FV0$L7R^;T+|% zF!OwvYqgAj^ub(R;zBmZHl4Y5|m##A)Gep(Ljp)t{ltYNzF_XHAR6 zyAAhla&~kq9Oo!=aei}I8`NRn%sFy8a+ymCE-g$;Tnw$+BhIHDyL39SyQj0c+FWDq zFhk9q<}P!$$u+|WmCBy4X7p(rT0Wf1c4Z%y%v@t>v!lS=V}=_ko28e#n!DnBTX5Rk z&8ENUV{R}vn%<_bxyjsO`k5Z4i|J~*nH*mpC+j6nbV zgquh?V)>Dxn`lPh{zvzud&)g+hPY?kpGd1asdXjg!K$|DMVehm(UhimgXzyxtz0UU z<(9aT-9)KwhCAcWNR|_ls}oD+CZrcFF?mp4N*PxQDFY=fmxFuSJrfHszk&uaIA#wSxH^0m*~a#G%yXB(=|3t2onoYn_jq7{Rbz$ Xk2aT?%S{K<(OhA!BxPw6dg^}wc$YKS literal 0 HcmV?d00001 diff --git a/engine/src/flutter/third_party/fonts/Roboto-BlackItalic.ttf b/engine/src/flutter/third_party/fonts/Roboto-BlackItalic.ttf new file mode 100644 index 0000000000000000000000000000000000000000..0b4e0ee108899ddfef739f48d2aa9475b8b41a03 GIT binary patch literal 177552 zcmcG%2UrzH7dJj__g;Dj6@&{2*ilii_uji;?MOro*H z9=n3rdqF{g-T!a)as~3{{lDMyJ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ZrbCkH6dhm~-?9b40$xcD^3YHbWM$U8v`<{S+QGGc{v0-P|wWlpz#m0p>C>;l!oIlkN+2d4B1&Ymo1&+%niSy!finroR4F=aCJX7vQy z3|5kuGX0Bfj2mmnXEL8)Y8ZR+4t_0QE`cM=!*TU7R5CKcIt=INE_0Om6~pO=*&-iK z8O_Ru1wsWjJ*=zmC7J zsnY^xt;~HtU^|~#D^sdV*)G)YvW?!?p^PJUhMvw79KEiW8vQx@7swLlNsF9wV)9h# z90@u{zI2X6YwI=pnZq&nYb;Nd&iU2O`QMnM+QpVwd2AORM;F771@>5I7KZb3F zG}66L&tn@c|F`5COOb7UE6aI?(bP<4pv<{3UdB1cTRO*AnB%}mQKGXa+u3t0hfJLp z=qcuiH2O4O-^n&ZwPU+bf5T}F)aroNf&d_9?M2J?=`pE->^ z3-o<#Gxc3;=j(geX6Wf`kGqw;pe3_rwtPHRHZWo3#RY87ao_26#!S>)S>~qZ-c1 za?TlN8U1HInD59&XP(2+cxv61{o4ADbC_2qx00MGiMEVvo1A&l_2M7o>T742cRgEB ztnt44oqgur(GBPE9%a6~zqy_Uomn??o_RZR{hk)==_M~Fj@5zoK8&ugPipb^Uklbv1Vz#hvdIo#aIBIg&fdx;tJg zZ=qE?<}Q?Fa-)*nNU3f@Ivc+u*}NgSEms-eg!{!x%rhu2rEF9RQwBukx%Ol>kSUCwbpaj(_~L5+)%<)MpD;X>#VgL=_*ghr|T|z ja8AP+o#4V?@n_xu|FBGxL*!6-nY>(H!JQ3F;MD&Cq{6iB literal 0 HcmV?d00001 diff --git a/engine/src/flutter/third_party/fonts/Roboto-Bold.ttf b/engine/src/flutter/third_party/fonts/Roboto-Bold.ttf new file mode 100644 index 0000000000000000000000000000000000000000..d3f01ad245b628f386ac95786f53167038720eb2 GIT binary patch literal 170760 zcmbTf2V4|M^FQ3(GqXz)mW-mX3jzidl%(jH1DLa5R?HD|j%Uv4%sFS5)idXuMZ~Ot zIe^*IQ(*S}_6$q7=bq>H|Gap$HPh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