• 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 package android.graphics.text;
18 
19 import android.annotation.NonNull;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 
25 // Based on the native implementation of LineBreaker in
26 // frameworks/base/core/jni/android_text_StaticLayout.cpp revision b808260
27 public abstract class BaseLineBreaker {
28 
29     protected static final int TAB_MASK   = 0x20000000;  // keep in sync with StaticLayout
30 
31     protected final @NonNull List<Primitive> mPrimitives;
32     protected final @NonNull
33     LineWidth mLineWidth;
34     protected final @NonNull
35     TabStops mTabStops;
36 
BaseLineBreaker(@onNull List<Primitive> primitives, @NonNull LineWidth lineWidth, @NonNull TabStops tabStops)37     public BaseLineBreaker(@NonNull List<Primitive> primitives, @NonNull LineWidth lineWidth,
38             @NonNull TabStops tabStops) {
39         mPrimitives = Collections.unmodifiableList(primitives);
40         mLineWidth = lineWidth;
41         mTabStops = tabStops;
42     }
43 
computeBreaks()44     public abstract Result computeBreaks();
45 
46     public static class Result {
47         List<Integer> mLineBreakOffset = new ArrayList<>();
48         List<Float> mLineWidths = new ArrayList<>();
49         List<Float> mLineAscents = new ArrayList<>();
50         List<Float> mLineDescents = new ArrayList<>();
51         List<Integer> mLineFlags = new ArrayList<>();
52     }
53 }
54