• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINIKIN_LAYOUT_CORE_H
18 #define MINIKIN_LAYOUT_CORE_H
19 
20 #include <gtest/gtest_prod.h>
21 
22 #include <vector>
23 
24 #include "minikin/Constants.h"
25 #include "minikin/FontFamily.h"
26 #include "minikin/Hyphenator.h"
27 #include "minikin/MinikinExtent.h"
28 #include "minikin/MinikinFont.h"
29 #include "minikin/MinikinRect.h"
30 #include "minikin/Point.h"
31 #include "minikin/Range.h"
32 #include "minikin/U16StringPiece.h"
33 
34 namespace minikin {
35 
36 struct MinikinPaint;
37 
38 // Immutable, recycle-able layout result.
39 class LayoutPiece {
40 public:
41     LayoutPiece(const U16StringPiece& textBuf, const Range& range, bool isRtl,
42                 const MinikinPaint& paint, StartHyphenEdit startHyphen, EndHyphenEdit endHyphen);
43     ~LayoutPiece();
44 
45     // Low level accessors.
fontIndices()46     const std::vector<uint8_t>& fontIndices() const { return mFontIndices; }
glyphIds()47     const std::vector<uint32_t>& glyphIds() const { return mGlyphIds; }
points()48     const std::vector<Point>& points() const { return mPoints; }
advances()49     const std::vector<float>& advances() const { return mAdvances; }
advance()50     float advance() const { return mAdvance; }
extent()51     const MinikinExtent& extent() const { return mExtent; }
fonts()52     const std::vector<FakedFont>& fonts() const { return mFonts; }
clusterCount()53     uint32_t clusterCount() const { return mClusterCount; }
54 
55     // Helper accessors
glyphCount()56     uint32_t glyphCount() const { return mGlyphIds.size(); }
fontAt(int glyphPos)57     const FakedFont& fontAt(int glyphPos) const { return mFonts[mFontIndices[glyphPos]]; }
glyphIdAt(int glyphPos)58     uint32_t glyphIdAt(int glyphPos) const { return mGlyphIds[glyphPos]; }
pointAt(int glyphPos)59     const Point& pointAt(int glyphPos) const { return mPoints[glyphPos]; }
clusterAt(int glyphPos)60     uint16_t clusterAt(int glyphPos) const { return mClusters[glyphPos]; }
61 
getMemoryUsage()62     uint32_t getMemoryUsage() const {
63         return sizeof(uint8_t) * mFontIndices.size() + sizeof(uint32_t) * mGlyphIds.size() +
64                sizeof(Point) * mPoints.size() + sizeof(float) * mAdvances.size() + sizeof(float) +
65                sizeof(MinikinRect) + sizeof(MinikinExtent);
66     }
67 
68     static MinikinRect calculateBounds(const LayoutPiece& layout, const MinikinPaint& paint);
69 
70 private:
71     FRIEND_TEST(LayoutTest, doLayoutWithPrecomputedPiecesTest);
72 
73     std::vector<uint8_t> mFontIndices;      // per glyph
74     std::vector<uint32_t> mGlyphIds;        // per glyph
75     std::vector<Point> mPoints;             // per glyph
76     std::vector<uint8_t> mClusters;         // per glyph
77 
78     std::vector<float> mAdvances;  // per code units
79 
80     float mAdvance;
81     MinikinExtent mExtent;
82     uint32_t mClusterCount;
83 
84     std::vector<FakedFont> mFonts;
85 };
86 
87 }  // namespace minikin
88 
89 #endif  // MINIKIN_LAYOUT_CORE_H
90