use of android.text.style.TabStopSpan in project android_frameworks_base by ResurrectionRemix.
the class Layout method getHorizontal.
private float getHorizontal(int offset, boolean trailing, int line, boolean clamped) {
int start = getLineStart(line);
int end = getLineEnd(line);
int dir = getParagraphDirection(line);
boolean hasTab = getLineContainsTab(line);
Directions directions = getLineDirections(line);
TabStops tabStops = null;
if (hasTab && mText instanceof Spanned) {
// Just checking this line should be good enough, tabs should be
// consistent across all lines in a paragraph.
TabStopSpan[] tabs = getParagraphSpans((Spanned) mText, start, end, TabStopSpan.class);
if (tabs.length > 0) {
// XXX should reuse
tabStops = new TabStops(TAB_INCREMENT, tabs);
}
}
TextLine tl = TextLine.obtain();
tl.set(mPaint, mText, start, end, dir, directions, hasTab, tabStops);
float wid = tl.measure(offset - start, trailing, null);
TextLine.recycle(tl);
if (clamped && wid > mWidth) {
wid = mWidth;
}
int left = getParagraphLeft(line);
int right = getParagraphRight(line);
return getLineStartPos(line, left, right) + wid;
}
use of android.text.style.TabStopSpan in project android_frameworks_base by ResurrectionRemix.
the class Layout method getLineStartPos.
/**
* Return the start position of the line, given the left and right bounds
* of the margins.
*
* @param line the line index
* @param left the left bounds (0, or leading margin if ltr para)
* @param right the right bounds (width, minus leading margin if rtl para)
* @return the start position of the line (to right of line if rtl para)
*/
private int getLineStartPos(int line, int left, int right) {
// Adjust the point at which to start rendering depending on the
// alignment of the paragraph.
Alignment align = getParagraphAlignment(line);
int dir = getParagraphDirection(line);
if (align == Alignment.ALIGN_LEFT) {
align = (dir == DIR_LEFT_TO_RIGHT) ? Alignment.ALIGN_NORMAL : Alignment.ALIGN_OPPOSITE;
} else if (align == Alignment.ALIGN_RIGHT) {
align = (dir == DIR_LEFT_TO_RIGHT) ? Alignment.ALIGN_OPPOSITE : Alignment.ALIGN_NORMAL;
}
int x;
if (align == Alignment.ALIGN_NORMAL) {
if (dir == DIR_LEFT_TO_RIGHT) {
x = left + getIndentAdjust(line, Alignment.ALIGN_LEFT);
} else {
x = right + getIndentAdjust(line, Alignment.ALIGN_RIGHT);
}
} else {
TabStops tabStops = null;
if (mSpannedText && getLineContainsTab(line)) {
Spanned spanned = (Spanned) mText;
int start = getLineStart(line);
int spanEnd = spanned.nextSpanTransition(start, spanned.length(), TabStopSpan.class);
TabStopSpan[] tabSpans = getParagraphSpans(spanned, start, spanEnd, TabStopSpan.class);
if (tabSpans.length > 0) {
tabStops = new TabStops(TAB_INCREMENT, tabSpans);
}
}
int max = (int) getLineExtent(line, tabStops, false);
if (align == Alignment.ALIGN_OPPOSITE) {
if (dir == DIR_LEFT_TO_RIGHT) {
x = right - max + getIndentAdjust(line, Alignment.ALIGN_RIGHT);
} else {
// max is negative here
x = left - max + getIndentAdjust(line, Alignment.ALIGN_LEFT);
}
} else {
// Alignment.ALIGN_CENTER
max = max & ~1;
x = (left + right - max) >> 1 + getIndentAdjust(line, Alignment.ALIGN_CENTER);
}
}
return x;
}
use of android.text.style.TabStopSpan in project android_frameworks_base by AOSPA.
the class Layout method measurePara.
/* package */
static float measurePara(TextPaint paint, CharSequence text, int start, int end) {
MeasuredText mt = MeasuredText.obtain();
TextLine tl = TextLine.obtain();
try {
mt.setPara(text, start, end, TextDirectionHeuristics.LTR, null);
Directions directions;
int dir;
if (mt.mEasy) {
directions = DIRS_ALL_LEFT_TO_RIGHT;
dir = Layout.DIR_LEFT_TO_RIGHT;
} else {
directions = AndroidBidi.directions(mt.mDir, mt.mLevels, 0, mt.mChars, 0, mt.mLen);
dir = mt.mDir;
}
char[] chars = mt.mChars;
int len = mt.mLen;
boolean hasTabs = false;
TabStops tabStops = null;
// leading margins should be taken into account when measuring a paragraph
int margin = 0;
if (text instanceof Spanned) {
Spanned spanned = (Spanned) text;
LeadingMarginSpan[] spans = getParagraphSpans(spanned, start, end, LeadingMarginSpan.class);
for (LeadingMarginSpan lms : spans) {
margin += lms.getLeadingMargin(true);
}
}
for (int i = 0; i < len; ++i) {
if (chars[i] == '\t') {
hasTabs = true;
if (text instanceof Spanned) {
Spanned spanned = (Spanned) text;
int spanEnd = spanned.nextSpanTransition(start, end, TabStopSpan.class);
TabStopSpan[] spans = getParagraphSpans(spanned, start, spanEnd, TabStopSpan.class);
if (spans.length > 0) {
tabStops = new TabStops(TAB_INCREMENT, spans);
}
}
break;
}
}
tl.set(paint, text, start, end, dir, directions, hasTabs, tabStops);
return margin + tl.metrics(null);
} finally {
TextLine.recycle(tl);
MeasuredText.recycle(mt);
}
}
use of android.text.style.TabStopSpan in project android_frameworks_base by AOSPA.
the class Layout method getLineExtent.
/**
* Like {@link #getLineExtent(int,TabStops,boolean)} but determines the
* tab stops instead of using the ones passed in.
* @param line the index of the line
* @param full whether to include trailing whitespace
* @return the extent of the line
*/
private float getLineExtent(int line, boolean full) {
int start = getLineStart(line);
int end = full ? getLineEnd(line) : getLineVisibleEnd(line);
boolean hasTabs = getLineContainsTab(line);
TabStops tabStops = null;
if (hasTabs && mText instanceof Spanned) {
// Just checking this line should be good enough, tabs should be
// consistent across all lines in a paragraph.
TabStopSpan[] tabs = getParagraphSpans((Spanned) mText, start, end, TabStopSpan.class);
if (tabs.length > 0) {
// XXX should reuse
tabStops = new TabStops(TAB_INCREMENT, tabs);
}
}
Directions directions = getLineDirections(line);
// Returned directions can actually be null
if (directions == null) {
return 0f;
}
int dir = getParagraphDirection(line);
TextLine tl = TextLine.obtain();
tl.set(mPaint, mText, start, end, dir, directions, hasTabs, tabStops);
float width = tl.metrics(null);
TextLine.recycle(tl);
return width;
}
use of android.text.style.TabStopSpan in project android_frameworks_base by crdroidandroid.
the class Layout method nextTab.
/**
* Returns the position of the next tab stop after h on the line.
*
* @param text the text
* @param start start of the line
* @param end limit of the line
* @param h the current horizontal offset
* @param tabs the tabs, can be null. If it is null, any tabs in effect
* on the line will be used. If there are no tabs, a default offset
* will be used to compute the tab stop.
* @return the offset of the next tab stop.
*/
/* package */
static float nextTab(CharSequence text, int start, int end, float h, Object[] tabs) {
float nh = Float.MAX_VALUE;
boolean alltabs = false;
if (text instanceof Spanned) {
if (tabs == null) {
tabs = getParagraphSpans((Spanned) text, start, end, TabStopSpan.class);
alltabs = true;
}
for (int i = 0; i < tabs.length; i++) {
if (!alltabs) {
if (!(tabs[i] instanceof TabStopSpan))
continue;
}
int where = ((TabStopSpan) tabs[i]).getTabStop();
if (where < nh && where > h)
nh = where;
}
if (nh != Float.MAX_VALUE)
return nh;
}
return ((int) ((h + TAB_INCREMENT) / TAB_INCREMENT)) * TAB_INCREMENT;
}
Aggregations