aboutsummaryrefslogtreecommitdiff
path: root/shadows/framework/src/main/java/org/robolectric/shadows/ShadowNativeMeasuredText.java
blob: 5b82a6cf5be2b2ff7737aa5a72917c7cb76e4e03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package org.robolectric.shadows;

import static android.os.Build.VERSION_CODES.Q;
import static android.os.Build.VERSION_CODES.S_V2;
import static android.os.Build.VERSION_CODES.TIRAMISU;

import android.annotation.FloatRange;
import android.annotation.IntRange;
import android.graphics.Rect;
import android.graphics.text.MeasuredText;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.nativeruntime.DefaultNativeRuntimeLoader;
import org.robolectric.nativeruntime.MeasuredTextBuilderNatives;
import org.robolectric.nativeruntime.MeasuredTextNatives;
import org.robolectric.shadows.ShadowNativeMeasuredText.Picker;

/** Shadow for {@link MeasuredText} that is backed by native code */
@Implements(value = MeasuredText.class, minSdk = Q, shadowPicker = Picker.class)
public class ShadowNativeMeasuredText {
  @Implementation
  protected static float nGetWidth(
      /* Non Zero */ long nativePtr, @IntRange(from = 0) int start, @IntRange(from = 0) int end) {
    return MeasuredTextNatives.nGetWidth(nativePtr, start, end);
  }

  @Implementation
  protected static /* Non Zero */ long nGetReleaseFunc() {
    DefaultNativeRuntimeLoader.injectAndLoad();
    return MeasuredTextNatives.nGetReleaseFunc();
  }

  @Implementation
  protected static int nGetMemoryUsage(/* Non Zero */ long nativePtr) {
    return MeasuredTextNatives.nGetMemoryUsage(nativePtr);
  }

  @Implementation
  protected static void nGetBounds(long nativePtr, char[] buf, int start, int end, Rect rect) {
    MeasuredTextNatives.nGetBounds(nativePtr, buf, start, end, rect);
  }

  @Implementation
  protected static float nGetCharWidthAt(long nativePtr, int offset) {
    return MeasuredTextNatives.nGetCharWidthAt(nativePtr, offset);
  }

  /** Shadow for {@link MeasuredText.Builder} that is backed by native code */
  @Implements(
      value = MeasuredText.Builder.class,
      minSdk = Q,
      shadowPicker = ShadowNativeMeasuredTextBuilder.Picker.class)
  public static class ShadowNativeMeasuredTextBuilder {
    @Implementation
    protected static /* Non Zero */ long nInitBuilder() {
      return MeasuredTextBuilderNatives.nInitBuilder();
    }

    @Implementation(maxSdk = S_V2)
    protected static void nAddStyleRun(
        /* Non Zero */ long nativeBuilderPtr,
        /* Non Zero */ long paintPtr,
        @IntRange(from = 0) int start,
        @IntRange(from = 0) int end,
        boolean isRtl) {
      MeasuredTextBuilderNatives.nAddStyleRun(nativeBuilderPtr, paintPtr, start, end, isRtl);
    }

    @Implementation(minSdk = TIRAMISU)
    protected static void nAddStyleRun(
        /* Non Zero */ long nativeBuilderPtr,
        /* Non Zero */ long paintPtr,
        int lineBreakStyle,
        int lineBreakWordStyle,
        int start,
        int end,
        boolean isRtl) {
      MeasuredTextBuilderNatives.nAddStyleRun(nativeBuilderPtr, paintPtr, start, end, isRtl);
    }

    @Implementation
    protected static void nAddReplacementRun(
        /* Non Zero */ long nativeBuilderPtr,
        /* Non Zero */ long paintPtr,
        @IntRange(from = 0) int start,
        @IntRange(from = 0) int end,
        @FloatRange(from = 0) float width) {
      MeasuredTextBuilderNatives.nAddReplacementRun(nativeBuilderPtr, paintPtr, start, end, width);
    }

    @Implementation(maxSdk = S_V2)
    protected static long nBuildMeasuredText(
        /* Non Zero */ long nativeBuilderPtr,
        long hintMtPtr,
        char[] text,
        boolean computeHyphenation,
        boolean computeLayout) {
      return MeasuredTextBuilderNatives.nBuildMeasuredText(
          nativeBuilderPtr, hintMtPtr, text, computeHyphenation, computeLayout);
    }

    @Implementation(minSdk = TIRAMISU)
    protected static long nBuildMeasuredText(
        /* Non Zero */ long nativeBuilderPtr,
        long hintMtPtr,
        char[] text,
        boolean computeHyphenation,
        boolean computeLayout,
        boolean fastHyphenationMode) {
      return MeasuredTextBuilderNatives.nBuildMeasuredText(
          nativeBuilderPtr, hintMtPtr, text, computeHyphenation, computeLayout);
    }

    @Implementation
    protected static void nFreeBuilder(/* Non Zero */ long nativeBuilderPtr) {
      MeasuredTextBuilderNatives.nFreeBuilder(nativeBuilderPtr);
    }

    /** Shadow picker for {@link MeasuredText.Builder}. */
    public static final class Picker extends GraphicsShadowPicker<Object> {
      public Picker() {
        super(
            org.robolectric.shadows.ShadowMeasuredTextBuilder.class,
            ShadowNativeMeasuredText.ShadowNativeMeasuredTextBuilder.class);
      }
    }
  }

  /** Shadow picker for {@link MeasuredText}. */
  public static final class Picker extends GraphicsShadowPicker<Object> {
    public Picker() {
      super(null, ShadowNativeMeasuredText.class);
    }
  }
}