1 /*
2 * Copyright (C) 2020 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 #include "minikin/BoundsCache.h"
18
19 namespace minikin {
20
operator ()(const LayoutPiece & layoutPiece,const MinikinPaint & paint)21 void ValueExtractor::operator()(const LayoutPiece& layoutPiece, const MinikinPaint& paint) {
22 value.reset(new BoundsValue);
23 value->rect = BoundsCache::getBounds(layoutPiece, paint);
24 value->advance = layoutPiece.advance();
25 }
26
27 // static
getBounds(const LayoutPiece & layoutPiece,const MinikinPaint & paint)28 MinikinRect BoundsCache::getBounds(const LayoutPiece& layoutPiece, const MinikinPaint& paint) {
29 MinikinRect pieceBounds;
30 MinikinRect tmpRect;
31 for (uint32_t i = 0; i < layoutPiece.glyphCount(); ++i) {
32 const FakedFont& font = layoutPiece.fontAt(i);
33 const Point& point = layoutPiece.pointAt(i);
34
35 MinikinFont* minikinFont = font.font->typeface().get();
36 minikinFont->GetBounds(&tmpRect, layoutPiece.glyphIdAt(i), paint, font.fakery);
37 tmpRect.offset(point.x, point.y);
38 pieceBounds.join(tmpRect);
39 }
40 return pieceBounds;
41 }
42
43 } // namespace minikin
44