Search in sources :

Example 1 with BreakIterator

use of android.icu.text.BreakIterator in project android_frameworks_base by ResurrectionRemix.

the class StaticLayout_Delegate method nComputeLineBreaks.

@LayoutlibDelegate
static /*package*/
int nComputeLineBreaks(long nativeBuilder, LineBreaks recycle, int[] recycleBreaks, float[] recycleWidths, int[] recycleFlags, int recycleLength) {
    Builder builder = sBuilderManager.getDelegate(nativeBuilder);
    if (builder == null) {
        return 0;
    }
    // compute all possible breakpoints.
    int length = builder.mWidths.length;
    BreakIterator it = BreakIterator.getLineInstance(new ULocale(builder.mLocale));
    it.setText(new Segment(builder.mText, 0, length));
    // average word length in english is 5. So, initialize the possible breaks with a guess.
    List<Integer> breaks = new ArrayList<Integer>((int) Math.ceil(length / 5d));
    int loc;
    it.first();
    while ((loc = it.next()) != BreakIterator.DONE) {
        breaks.add(loc);
    }
    List<Primitive> primitives = computePrimitives(builder.mText, builder.mWidths, length, breaks);
    switch(builder.mBreakStrategy) {
        case Layout.BREAK_STRATEGY_SIMPLE:
            builder.mLineBreaker = new GreedyLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        case Layout.BREAK_STRATEGY_HIGH_QUALITY:
        //                break;
        case Layout.BREAK_STRATEGY_BALANCED:
            builder.mLineBreaker = new OptimizingLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        default:
            throw new AssertionError("Unknown break strategy: " + builder.mBreakStrategy);
    }
    builder.mLineBreaker.computeBreaks(recycle);
    return recycle.breaks.length;
}
Also used : ULocale(android.icu.util.ULocale) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) Segment(javax.swing.text.Segment) BreakIterator(android.icu.text.BreakIterator) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 2 with BreakIterator

use of android.icu.text.BreakIterator in project android_frameworks_base by DirtyUnicorns.

the class StaticLayout_Delegate method nComputeLineBreaks.

@LayoutlibDelegate
static /*package*/
int nComputeLineBreaks(long nativeBuilder, LineBreaks recycle, int[] recycleBreaks, float[] recycleWidths, int[] recycleFlags, int recycleLength) {
    Builder builder = sBuilderManager.getDelegate(nativeBuilder);
    if (builder == null) {
        return 0;
    }
    // compute all possible breakpoints.
    int length = builder.mWidths.length;
    BreakIterator it = BreakIterator.getLineInstance(new ULocale(builder.mLocale));
    it.setText(new Segment(builder.mText, 0, length));
    // average word length in english is 5. So, initialize the possible breaks with a guess.
    List<Integer> breaks = new ArrayList<Integer>((int) Math.ceil(length / 5d));
    int loc;
    it.first();
    while ((loc = it.next()) != BreakIterator.DONE) {
        breaks.add(loc);
    }
    List<Primitive> primitives = computePrimitives(builder.mText, builder.mWidths, length, breaks);
    switch(builder.mBreakStrategy) {
        case Layout.BREAK_STRATEGY_SIMPLE:
            builder.mLineBreaker = new GreedyLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        case Layout.BREAK_STRATEGY_HIGH_QUALITY:
        //                break;
        case Layout.BREAK_STRATEGY_BALANCED:
            builder.mLineBreaker = new OptimizingLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        default:
            throw new AssertionError("Unknown break strategy: " + builder.mBreakStrategy);
    }
    builder.mLineBreaker.computeBreaks(recycle);
    return recycle.breaks.length;
}
Also used : ULocale(android.icu.util.ULocale) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) Segment(javax.swing.text.Segment) BreakIterator(android.icu.text.BreakIterator) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 3 with BreakIterator

use of android.icu.text.BreakIterator in project android_frameworks_base by crdroidandroid.

the class StaticLayout_Delegate method nComputeLineBreaks.

@LayoutlibDelegate
static /*package*/
int nComputeLineBreaks(long nativeBuilder, LineBreaks recycle, int[] recycleBreaks, float[] recycleWidths, int[] recycleFlags, int recycleLength) {
    Builder builder = sBuilderManager.getDelegate(nativeBuilder);
    if (builder == null) {
        return 0;
    }
    // compute all possible breakpoints.
    int length = builder.mWidths.length;
    BreakIterator it = BreakIterator.getLineInstance(new ULocale(builder.mLocale));
    it.setText(new Segment(builder.mText, 0, length));
    // average word length in english is 5. So, initialize the possible breaks with a guess.
    List<Integer> breaks = new ArrayList<Integer>((int) Math.ceil(length / 5d));
    int loc;
    it.first();
    while ((loc = it.next()) != BreakIterator.DONE) {
        breaks.add(loc);
    }
    List<Primitive> primitives = computePrimitives(builder.mText, builder.mWidths, length, breaks);
    switch(builder.mBreakStrategy) {
        case Layout.BREAK_STRATEGY_SIMPLE:
            builder.mLineBreaker = new GreedyLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        case Layout.BREAK_STRATEGY_HIGH_QUALITY:
        //                break;
        case Layout.BREAK_STRATEGY_BALANCED:
            builder.mLineBreaker = new OptimizingLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        default:
            throw new AssertionError("Unknown break strategy: " + builder.mBreakStrategy);
    }
    builder.mLineBreaker.computeBreaks(recycle);
    return recycle.breaks.length;
}
Also used : ULocale(android.icu.util.ULocale) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) Segment(javax.swing.text.Segment) BreakIterator(android.icu.text.BreakIterator) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 4 with BreakIterator

use of android.icu.text.BreakIterator in project platform_frameworks_base by android.

the class StaticLayout_Delegate method nComputeLineBreaks.

@LayoutlibDelegate
static /*package*/
int nComputeLineBreaks(long nativeBuilder, LineBreaks recycle, int[] recycleBreaks, float[] recycleWidths, int[] recycleFlags, int recycleLength) {
    Builder builder = sBuilderManager.getDelegate(nativeBuilder);
    if (builder == null) {
        return 0;
    }
    // compute all possible breakpoints.
    int length = builder.mWidths.length;
    BreakIterator it = BreakIterator.getLineInstance(new ULocale(builder.mLocale));
    it.setText(new Segment(builder.mText, 0, length));
    // average word length in english is 5. So, initialize the possible breaks with a guess.
    List<Integer> breaks = new ArrayList<Integer>((int) Math.ceil(length / 5d));
    int loc;
    it.first();
    while ((loc = it.next()) != BreakIterator.DONE) {
        breaks.add(loc);
    }
    List<Primitive> primitives = computePrimitives(builder.mText, builder.mWidths, length, breaks);
    switch(builder.mBreakStrategy) {
        case Layout.BREAK_STRATEGY_SIMPLE:
            builder.mLineBreaker = new GreedyLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        case Layout.BREAK_STRATEGY_HIGH_QUALITY:
        //                break;
        case Layout.BREAK_STRATEGY_BALANCED:
            builder.mLineBreaker = new OptimizingLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        default:
            throw new AssertionError("Unknown break strategy: " + builder.mBreakStrategy);
    }
    builder.mLineBreaker.computeBreaks(recycle);
    return recycle.breaks.length;
}
Also used : ULocale(android.icu.util.ULocale) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) Segment(javax.swing.text.Segment) BreakIterator(android.icu.text.BreakIterator) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 5 with BreakIterator

use of android.icu.text.BreakIterator in project android_frameworks_base by AOSPA.

the class StaticLayout_Delegate method nComputeLineBreaks.

@LayoutlibDelegate
static /*package*/
int nComputeLineBreaks(long nativeBuilder, LineBreaks recycle, int[] recycleBreaks, float[] recycleWidths, int[] recycleFlags, int recycleLength) {
    Builder builder = sBuilderManager.getDelegate(nativeBuilder);
    if (builder == null) {
        return 0;
    }
    // compute all possible breakpoints.
    int length = builder.mWidths.length;
    BreakIterator it = BreakIterator.getLineInstance(new ULocale(builder.mLocale));
    it.setText(new Segment(builder.mText, 0, length));
    // average word length in english is 5. So, initialize the possible breaks with a guess.
    List<Integer> breaks = new ArrayList<Integer>((int) Math.ceil(length / 5d));
    int loc;
    it.first();
    while ((loc = it.next()) != BreakIterator.DONE) {
        breaks.add(loc);
    }
    List<Primitive> primitives = computePrimitives(builder.mText, builder.mWidths, length, breaks);
    switch(builder.mBreakStrategy) {
        case Layout.BREAK_STRATEGY_SIMPLE:
            builder.mLineBreaker = new GreedyLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        case Layout.BREAK_STRATEGY_HIGH_QUALITY:
        //                break;
        case Layout.BREAK_STRATEGY_BALANCED:
            builder.mLineBreaker = new OptimizingLineBreaker(primitives, builder.mLineWidth, builder.mTabStopCalculator);
            break;
        default:
            throw new AssertionError("Unknown break strategy: " + builder.mBreakStrategy);
    }
    builder.mLineBreaker.computeBreaks(recycle);
    return recycle.breaks.length;
}
Also used : ULocale(android.icu.util.ULocale) ArrayList(java.util.ArrayList) Paint(android.graphics.Paint) Segment(javax.swing.text.Segment) BreakIterator(android.icu.text.BreakIterator) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Aggregations

Paint (android.graphics.Paint)5 BreakIterator (android.icu.text.BreakIterator)5 ULocale (android.icu.util.ULocale)5 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)5 ArrayList (java.util.ArrayList)5 Segment (javax.swing.text.Segment)5