언어

TextShaper 클래스

정의

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

[Android.Runtime.Register("android/text/TextShaper", ApiSince=31, DoNotGenerateAcw=true)]
public class TextShaper : Java.Lang.Object
[<Android.Runtime.Register("android/text/TextShaper", ApiSince=31, DoNotGenerateAcw=true)>]
type TextShaper = class
    inherit Object
상속
TextShaper
특성

설명

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

다음은 간단한 텍스트에 대한 텍스트 크기 및 문자 간격에 애니메이션 효과를 주는 예제입니다.

<code>
            // In this example, shape the text once for start and end state, then animate between two shape
            // result without re-shaping in each frame.
            class SimpleAnimationView @JvmOverloads constructor(
                    context: Context,
                    attrs: AttributeSet? = null,
                    defStyleAttr: Int = 0
            ) : View(context, attrs, defStyleAttr) {
                private val textDir = TextDirectionHeuristics.LOCALE
                private val text = "Hello, World."  // The text to be displayed

                // Class for keeping drawing parameters.
                data class DrawStyle(val textSize: Float, val alpha: Int)

                // The start and end text shaping result. This class will animate between these two.
                private val start = mutableListOf&lt;Pair&lt;PositionedGlyphs, DrawStyle&gt;&gt;()
                private val end = mutableListOf&lt;Pair&lt;PositionedGlyphs, DrawStyle&gt;&gt;()

                init {
                    val startPaint = TextPaint().apply {
                        alpha = 0 // Alpha only affect text drawing but not text shaping
                        textSize = 36f // TextSize affect both text shaping and drawing.
                        letterSpacing = 0f // Letter spacing only affect text shaping but not drawing.
                    }

                    val endPaint = TextPaint().apply {
                        alpha = 255
                        textSize =128f
                        letterSpacing = 0.1f
                    }

                    TextShaper.shapeText(text, 0, text.length, textDir, startPaint) { _, _, glyphs, paint ->
                        start.add(Pair(glyphs, DrawStyle(paint.textSize, paint.alpha)))
                    }
                    TextShaper.shapeText(text, 0, text.length, textDir, endPaint) { _, _, glyphs, paint ->
                        end.add(Pair(glyphs, DrawStyle(paint.textSize, paint.alpha)))
                    }
                }

                override fun onDraw(canvas: Canvas) {
                    super.onDraw(canvas)

                    // Set the baseline to the vertical center of the view.
                    canvas.translate(0f, height / 2f)

                    // Assume the number of PositionedGlyphs are the same. If different, you may want to
                    // animate in a different way, e.g. cross fading.
                    start.zip(end) { (startGlyphs, startDrawStyle), (endGlyphs, endDrawStyle) ->
                        // Tween the style and set to paint.
                        paint.textSize = lerp(startDrawStyle.textSize, endDrawStyle.textSize, progress)
                        paint.alpha = lerp(startDrawStyle.alpha, endDrawStyle.alpha, progress)

                        // Assume the number of glyphs are the same. If different, you may want to animate in
                        // a different way, e.g. cross fading.
                        require(startGlyphs.glyphCount() == endGlyphs.glyphCount())

                        if (startGlyphs.glyphCount() == 0) return@zip

                        var curFont = startGlyphs.getFont(0)
                        var drawStart = 0
                        for (i in 1 until startGlyphs.glyphCount()) {
                            // Assume the pair of Glyph ID and font is the same. If different, you may want
                            // to animate in a different way, e.g. cross fading.
                            require(startGlyphs.getGlyphId(i) == endGlyphs.getGlyphId(i))
                            require(startGlyphs.getFont(i) === endGlyphs.getFont(i))

                            val font = startGlyphs.getFont(i)
                            if (curFont != font) {
                                drawGlyphs(canvas, startGlyphs, endGlyphs, drawStart, i, curFont, paint)
                                curFont = font
                                drawStart = i
                            }
                        }
                        if (drawStart != startGlyphs.glyphCount() - 1) {
                            drawGlyphs(canvas, startGlyphs, endGlyphs, drawStart, startGlyphs.glyphCount(),
                                    curFont, paint)
                        }
                    }
                }

                // Draws Glyphs for the same font run.
                private fun drawGlyphs(canvas: Canvas, startGlyph: PositionedGlyphs,
                                       endGlyph: PositionedGlyphs, start: Int, end: Int, font: Font,
                                       paint: Paint) {
                    var cacheIndex = 0
                    for (i in start until end) {
                        intArrayCache[cacheIndex] = startGlyph.getGlyphId(i)
                        // The glyph positions are different from start to end since they are shaped
                        // with different letter spacing. Use linear interpolation for positions
                        // during animation.
                        floatArrayCache[cacheIndex * 2] =
                                lerp(startGlyph.getGlyphX(i), endGlyph.getGlyphX(i), progress)
                        floatArrayCache[cacheIndex * 2 + 1] =
                                lerp(startGlyph.getGlyphY(i), endGlyph.getGlyphY(i), progress)
                        if (cacheIndex == CACHE_SIZE) {  // Cached int array is full. Flashing.
                            canvas.drawGlyphs(
                                    intArrayCache, 0, // glyphID array and its starting offset
                                    floatArrayCache, 0, // position array and its starting offset
                                    cacheIndex, // glyph count
                                    font,
                                    paint
                            )
                            cacheIndex = 0
                        }
                        cacheIndex++
                    }
                    if (cacheIndex != 0) {
                        canvas.drawGlyphs(
                                intArrayCache, 0, // glyphID array and its starting offset
                                floatArrayCache, 0, // position array and its starting offset
                                cacheIndex, // glyph count
                                font,
                                paint
                        )
                    }
                }

                // Linear Interpolator
                private fun lerp(start: Float, end: Float, t: Float) = start * (1f - t) + end * t
                private fun lerp(start: Int, end: Int, t: Float) = (start * (1f - t) + end * t).toInt()

                // The animation progress.
                var progress: Float = 0f
                    set(value) {
                        field = value
                        invalidate()
                    }

                // working copy of paint.
                private val paint = Paint()

                // Array cache for reducing allocation during drawing.
                private var intArrayCache = IntArray(CACHE_SIZE)
                private var floatArrayCache = FloatArray(CACHE_SIZE * 2)
            }
</code>

에 대한 android.text.TextShaperJava 설명서

이 페이지의 일부는 만들고 공유한 작업을 기반으로 하며 에 설명된 조건에 따라 사용됩니다.

생성자

속성 Description
TextShaper(IntPtr, JniHandleOwnership)

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

속성

속성 Description
Class

Object런타임 클래스를 반환합니다.

(다음에서 상속됨 Object)
Handle

기본 Android 인스턴스에 대한 핸들입니다.

(다음에서 상속됨 Object)
JniIdentityHashCode

interop 런타임에 의해 이 Java 피어에 할당된 ID 해시 코드를 가져옵니다.

(다음에서 상속됨 Object)
JniManagedPeerState

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

(다음에서 상속됨 JavaObject)
JniPeerMembers

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

PeerReference

이 Java 피어에 대한 JNI 개체 참조를 가져옵니다.

(다음에서 상속됨 Object)
ThresholdClass

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

ThresholdType

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

메서드

속성 Description
Clone()

이 개체의 복사본을 만들고 반환합니다.

(다음에서 상속됨 Object)
Construct(JniObjectReference, JniObjectReferenceOptions)

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

(다음에서 상속됨 JavaObject)
Dispose()

이 Java 피어에서 보유한 리소스를 해제합니다.

(다음에서 상속됨 Object)
Dispose(Boolean)

이 Java 피어에서 보유한 리소스를 해제합니다.

(다음에서 상속됨 Object)
DisposeUnlessReferenced()

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

(다음에서 상속됨 JavaObject)
Equals(Object)

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

(다음에서 상속됨 JavaObject)
Equals(Object)

다른 개체가 이 개체와 "같음"인지 여부를 나타냅니다.

(다음에서 상속됨 Object)
GetHashCode()

개체에 대한 해시 코드 값을 반환합니다.

(다음에서 상속됨 Object)
JavaFinalize()
사용되지 않음.

가비지 수집에서 개체에 대한 참조가 더 이상 없다고 판단할 때 개체의 가비지 수집기에서 호출됩니다.

(다음에서 상속됨 Object)
Notify()

이 개체의 모니터에서 대기 중인 단일 스레드를 해제합니다.

(다음에서 상속됨 Object)
NotifyAll()

이 개체의 모니터에서 대기 중인 모든 스레드를 해제합니다.

(다음에서 상속됨 Object)
SetHandle(IntPtr, JniHandleOwnership)

Handle 속성을 설정합니다.

(다음에서 상속됨 Object)
SetPeerReference(JniObjectReference, JniObjectReferenceOptions)

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

(다음에서 상속됨 JavaObject)
ShapeText(ICharSequence, Int32, Int32, ITextDirectionHeuristic, TextPaint, TextShaper+IGlyphsConsumer)

도형 다중 스타일 텍스트입니다.

ShapeText(String, Int32, Int32, ITextDirectionHeuristic, TextPaint, TextShaper+IGlyphsConsumer)

도형 다중 스타일 텍스트입니다.

ToArray<T>()

이 Java 배열 래퍼에서 관리되는 배열을 만듭니다.

(다음에서 상속됨 Object)
ToString()

개체의 문자열 표현을 반환합니다.

(다음에서 상속됨 Object)
UnregisterFromRuntime()

interop 런타임에서 이 Java 피어의 등록을 취소합니다.

(다음에서 상속됨 Object)
Wait()

현재 스레드가 각성될 때까지 대기하게 하며, 일반적으로 <알림을 받><거나 ><>중단/종료<합니다.>

(다음에서 상속됨 Object)
Wait(Int64, Int32)

현재 스레드가 각성될 때까지 대기하게 하며, 일반적으로 <>알림을 받<거나 >중단/<종료><>하거나 일정량의 실시간 경과가 발생할 때까지 대기합니다.

(다음에서 상속됨 Object)
Wait(Int64)

현재 스레드가 각성될 때까지 대기하게 하며, 일반적으로 <>알림을 받<거나 >중단/<종료><>하거나 일정량의 실시간 경과가 발생할 때까지 대기합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

속성 Description
IJavaPeerable.Disposed()

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

(다음에서 상속됨 JavaObject)
IJavaPeerable.Finalized()

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

(다음에서 상속됨 JavaObject)
IJavaPeerable.JniObjectReferenceControlBlock

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

(다음에서 상속됨 JavaObject)
IJavaPeerable.SetJniIdentityHashCode(Int32)

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

(다음에서 상속됨 JavaObject)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates)

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

(다음에서 상속됨 JavaObject)
IJavaPeerable.SetPeerReference(JniObjectReference)

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

(다음에서 상속됨 JavaObject)

확장명 메서드

속성 Description
GetJniTypeName(IJavaPeerable)

인스턴스 self형식의 JNI 이름을 가져옵니다.

JavaAs<TResult>(IJavaPeerable)

형식self을 강제 TResult 변환하여 강제 변환이 Java 쪽에서 유효한지 확인합니다.

JavaCast<TResult>(IJavaObject)

Android 런타임 확인 형식 변환을 수행합니다.

JavaCast<TResult>(IJavaObject)

다중 스타일 텍스트에 대한 텍스트 셰이핑을 제공합니다.

TryJavaCast<TResult>(IJavaPeerable, TResult)

형식self을 강제 TResult 변환하여 강제 변환이 Java 쪽에서 유효한지 확인합니다.

적용 대상