Search in sources :

Example 1 with TabStopSpan

use of jp.sblo.pandora.jota.text.style.TabStopSpan in project Jota-Text-Editor-old by jiro-aqua.

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 = ((Spanned) text).getSpans(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;
}
Also used : TabStopSpan(jp.sblo.pandora.jota.text.style.TabStopSpan) Spanned(android.text.Spanned) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 2 with TabStopSpan

use of jp.sblo.pandora.jota.text.style.TabStopSpan in project Jota-Text-Editor-old by jiro-aqua.

the class Layout method getHorizontal.

private float getHorizontal(int offset, boolean trailing, boolean alt, int line) {
    int start = getLineStart(line);
    int end = getLineVisibleEnd(line);
    int dir = getParagraphDirection(line);
    boolean tab = getLineContainsTab(line);
    Directions directions = getLineDirections(line);
    TabStopSpan[] tabs = null;
    if (tab && mText instanceof Spanned) {
        tabs = ((Spanned) mText).getSpans(start, end, TabStopSpan.class);
    }
    float wid = measureText(mPaint, mWorkPaint, mText, start, offset, end, dir, directions, trailing, alt, tab, tabs);
    if (offset > end) {
        if (dir == DIR_RIGHT_TO_LEFT)
            wid -= measureText(mPaint, mWorkPaint, mText, end, offset, null, tab, tabs);
        else
            wid += measureText(mPaint, mWorkPaint, mText, end, offset, null, tab, tabs);
    }
    Alignment align = getParagraphAlignment(line);
    int left = getParagraphLeft(line);
    int right = getParagraphRight(line);
    if (align == Alignment.ALIGN_NORMAL) {
        if (dir == DIR_RIGHT_TO_LEFT)
            return right + wid;
        else
            return left + wid;
    }
    float max = getLineMax(line);
    if (align == Alignment.ALIGN_OPPOSITE) {
        if (dir == DIR_RIGHT_TO_LEFT)
            return left + max + wid;
        else
            return right - max + wid;
    } else {
        /* align == Alignment.ALIGN_CENTER */
        int imax = ((int) max) & ~1;
        if (dir == DIR_RIGHT_TO_LEFT)
            return right - (((right - left) - imax) / 2) + wid;
        else
            return left + ((right - left) - imax) / 2 + wid;
    }
}
Also used : TabStopSpan(jp.sblo.pandora.jota.text.style.TabStopSpan) Spanned(android.text.Spanned) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)2 Spanned (android.text.Spanned)2 TextPaint (android.text.TextPaint)2 TabStopSpan (jp.sblo.pandora.jota.text.style.TabStopSpan)2