Search in sources :

Example 1 with ParagraphStyle

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

the class TextView method spanChange.

/**
     * Not private so it can be called from an inner class without going
     * through a thunk.
     */
void spanChange(Spanned buf, Object what, int oldStart, int newStart, int oldEnd, int newEnd) {
    // XXX Make the start and end move together if this ends up
    // spending too much time invalidating.
    boolean selChanged = false;
    int newSelStart = -1, newSelEnd = -1;
    final InputMethodState ims = mInputMethodState;
    if (what == Selection.SELECTION_END) {
        mHighlightPathBogus = true;
        selChanged = true;
        newSelEnd = newStart;
        if (!isFocused()) {
            mSelectionMoved = true;
        }
        if (oldStart >= 0 || newStart >= 0) {
            invalidateCursor(Selection.getSelectionStart(buf), oldStart, newStart);
            registerForPreDraw();
            if (isFocused()) {
                mShowCursor = SystemClock.uptimeMillis();
                makeBlink();
            }
        }
    }
    if (what == Selection.SELECTION_START) {
        mHighlightPathBogus = true;
        selChanged = true;
        newSelStart = newStart;
        if (!isFocused()) {
            mSelectionMoved = true;
        }
        if (oldStart >= 0 || newStart >= 0) {
            int end = Selection.getSelectionEnd(buf);
            invalidateCursor(end, oldStart, newStart);
        }
    }
    if (selChanged) {
        if ((buf.getSpanFlags(what) & Spanned.SPAN_INTERMEDIATE) == 0) {
            if (newSelStart < 0) {
                newSelStart = Selection.getSelectionStart(buf);
            }
            if (newSelEnd < 0) {
                newSelEnd = Selection.getSelectionEnd(buf);
            }
            onSelectionChanged(newSelStart, newSelEnd);
        }
    }
    if (what instanceof UpdateAppearance || what instanceof ParagraphStyle) {
        if (ims == null || ims.mBatchEditNesting == 0) {
            invalidate();
            mHighlightPathBogus = true;
            checkForResize();
        } else {
            ims.mContentChanged = true;
        }
    }
    if (MetaKeyKeyListener.isMetaTracker(buf, what)) {
        mHighlightPathBogus = true;
        if (ims != null && MetaKeyKeyListener.isSelectingMetaTracker(buf, what)) {
            ims.mSelectionModeChanged = true;
        }
        if (Selection.getSelectionStart(buf) >= 0) {
            if (ims == null || ims.mBatchEditNesting == 0) {
                invalidateCursor();
            } else {
                ims.mCursorChanged = true;
            }
        }
    }
    if (what instanceof ParcelableSpan) {
        // the current extract editor would be interested in it.
        if (ims != null && ims.mExtracting != null) {
            if (ims.mBatchEditNesting != 0) {
                if (oldStart >= 0) {
                    if (ims.mChangedStart > oldStart) {
                        ims.mChangedStart = oldStart;
                    }
                    if (ims.mChangedStart > oldEnd) {
                        ims.mChangedStart = oldEnd;
                    }
                }
                if (newStart >= 0) {
                    if (ims.mChangedStart > newStart) {
                        ims.mChangedStart = newStart;
                    }
                    if (ims.mChangedStart > newEnd) {
                        ims.mChangedStart = newEnd;
                    }
                }
            } else {
                if (DEBUG_EXTRACT)
                    Log.v(TAG, "Span change outside of batch: " + oldStart + "-" + oldEnd + "," + newStart + "-" + newEnd + what);
                ims.mContentChanged = true;
            }
        }
    }
}
Also used : UpdateAppearance(jp.sblo.pandora.jota.text.style.UpdateAppearance) ParagraphStyle(jp.sblo.pandora.jota.text.style.ParagraphStyle) ParcelableSpan(android.text.ParcelableSpan) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 2 with ParagraphStyle

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

the class Layout method draw.

/**
     * Draw this Layout on the specified canvas, with the highlight path drawn
     * between the background and the text.
     *
     * @param c the canvas
     * @param highlight the path of the highlight or cursor; can be null
     * @param highlightPaint the paint for the highlight
     * @param cursorOffsetVertical the amount to temporarily translate the
     *        canvas while rendering the highlight
     */
// Jota Text Editor
public void draw(Canvas c, Path highlight, Paint highlightPaint, int cursorOffsetVertical, int selLine, Paint underlinePaint, int lineNumWidth, Paint lineNumPaint, Paint spacePaint, Path[] spacePaths) {
    int dtop, dbottom;
    synchronized (sTempRect) {
        if (!c.getClipBounds(sTempRect)) {
            return;
        }
        dtop = sTempRect.top;
        dbottom = sTempRect.bottom;
    }
    int top = 0;
    int bottom = getLineTop(getLineCount());
    if (dtop > top) {
        top = dtop;
    }
    if (dbottom < bottom) {
        bottom = dbottom;
    }
    int first = getLineForVertical(top);
    int last = getLineForVertical(bottom);
    int previousLineBottom = getLineTop(first);
    int previousLineEnd = getLineStart(first);
    TextPaint paint = mPaint;
    CharSequence buf = mText;
    //        int width = mWidth;		// Jota Text Editor
    boolean spannedText = mSpannedText;
    ParagraphStyle[] spans = NO_PARA_SPANS;
    int spanend = 0;
    int textLength = 0;
    // a non-spanned transformation of a spanned editing buffer.
    if (highlight != null) {
        // Jota Text Editor
        if (lineNumWidth != 0) {
            c.translate(lineNumWidth, 0);
        }
        if (cursorOffsetVertical != 0) {
            c.translate(0, cursorOffsetVertical);
        }
        c.drawPath(highlight, highlightPaint);
        if (cursorOffsetVertical != 0) {
            c.translate(0, -cursorOffsetVertical);
        }
        // Jota Text Editor
        if (lineNumWidth != 0) {
            c.translate(-lineNumWidth, 0);
        }
    }
    Alignment align = mAlignment;
    // line's descent.
    for (int i = first; i <= last; i++) {
        int start = previousLineEnd;
        previousLineEnd = getLineStart(i + 1);
        int end = getLineVisibleEnd(i, start, previousLineEnd);
        int ltop = previousLineBottom;
        int lbottom = getLineTop(i + 1);
        previousLineBottom = lbottom;
        int lbaseline = lbottom - getLineDescent(i);
        boolean isFirstParaLine = false;
        // Jota Text Editor
        //            if (spannedText) {
        //                if (start == 0 || buf.charAt(start - 1) == '\n') {
        //                    isFirstParaLine = true;
        //                }
        //                // New batch of paragraph styles, compute the alignment.
        //                // Last alignment style wins.
        //                if (start >= spanend) {
        //                    Spanned sp = (Spanned) buf;
        //                    spanend = sp.nextSpanTransition(start, textLength,
        //                                                    ParagraphStyle.class);
        //                    spans = sp.getSpans(start, spanend, ParagraphStyle.class);
        //
        //                    align = mAlignment;
        //                    for (int n = spans.length-1; n >= 0; n--) {
        //                        if (spans[n] instanceof AlignmentSpan) {
        //                            align = ((AlignmentSpan) spans[n]).getAlignment();
        //                            break;
        //                        }
        //                    }
        //                }
        //            }
        int dir = getParagraphDirection(i);
        int left = 0;
        int right = mWidth;
        // Jota Text Editor
        //            // Draw all leading margin spans.  Adjust left or right according
        //            // to the paragraph direction of the line.
        //            if (spannedText) {
        //                final int length = spans.length;
        //                for (int n = 0; n < length; n++) {
        //                    if (spans[n] instanceof LeadingMarginSpan) {
        //                        LeadingMarginSpan margin = (LeadingMarginSpan) spans[n];
        //
        //                        if (dir == DIR_RIGHT_TO_LEFT) {
        //                            margin.drawLeadingMargin(c, paint, right, dir, ltop,
        //                                                     lbaseline, lbottom, buf,
        //                                                     start, end, isFirstParaLine, this);
        //
        //                            right -= margin.getLeadingMargin(isFirstParaLine);
        //                        } else {
        //                            margin.drawLeadingMargin(c, paint, left, dir, ltop,
        //                                                     lbaseline, lbottom, buf,
        //                                                     start, end, isFirstParaLine, this);
        //
        //                            boolean useMargin = isFirstParaLine;
        //                            if (margin instanceof LeadingMarginSpan.LeadingMarginSpan2) {
        //                                int count = ((LeadingMarginSpan.LeadingMarginSpan2)margin).getLeadingMarginLineCount();
        //                                useMargin = count > i;
        //                            }
        //                            left += margin.getLeadingMargin(useMargin);
        //                        }
        //                    }
        //                }
        //            }
        // Adjust the point at which to start rendering depending on the
        // alignment of the paragraph.
        int x;
        if (align == Alignment.ALIGN_NORMAL) {
            if (dir == DIR_LEFT_TO_RIGHT) {
                x = left;
            } else {
                x = right;
            }
        } else {
            int max = (int) getLineMax(i, spans, false);
            if (align == Alignment.ALIGN_OPPOSITE) {
                if (dir == DIR_RIGHT_TO_LEFT) {
                    x = left + max;
                } else {
                    x = right - max;
                }
            } else {
                // Alignment.ALIGN_CENTER
                max = max & ~1;
                int half = (right - left - max) >> 1;
                if (dir == DIR_RIGHT_TO_LEFT) {
                    x = right - half;
                } else {
                    x = left + half;
                }
            }
        }
        // Jota Text Editor
        if (selLine == i && underlinePaint != null) {
            int underlinepos = getLineBaseline(i) + 1;
            c.drawLine(0, underlinepos, getWidth() + lineNumWidth, underlinepos, underlinePaint);
        }
        // Jota Text Editor
        if (lineNumWidth != 0) {
            String linenum = "      " + (i + 1);
            c.drawText(linenum, linenum.length() - 5, linenum.length(), x, lbaseline, lineNumPaint);
            int linebottom = 0;
            if (i < getLineCount() - 1) {
                linebottom = getLineTop(i + 1);
            } else {
                linebottom = getLineBottom(i);
            }
            c.drawLine(lineNumWidth - 4, getLineTop(i), lineNumWidth - 4, linebottom, lineNumPaint);
            c.translate(lineNumWidth, 0);
        }
        Directions directions = getLineDirections(i);
        boolean hasTab = getLineContainsTab(i);
        if (directions == DIRS_ALL_LEFT_TO_RIGHT && !spannedText && !hasTab) {
            if (DEBUG) {
                Assert.assertTrue(dir == DIR_LEFT_TO_RIGHT);
                Assert.assertNotNull(c);
            }
            // XXX: assumes there's nothing additional to be done
            c.drawText(buf, start, end, x, lbaseline, paint);
        } else {
            drawText(c, buf, start, end, dir, directions, x, ltop, lbaseline, lbottom, paint, mWorkPaint, hasTab, spans, spacePaint, // Jota Text Editor
            spacePaths);
        }
        // Jota Text Editor
        if (lineNumWidth != 0) {
            c.translate(-lineNumWidth, 0);
        }
    }
}
Also used : ParagraphStyle(jp.sblo.pandora.jota.text.style.ParagraphStyle) SpannableString(android.text.SpannableString) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint)

Aggregations

Paint (android.graphics.Paint)2 TextPaint (android.text.TextPaint)2 ParagraphStyle (jp.sblo.pandora.jota.text.style.ParagraphStyle)2 ParcelableSpan (android.text.ParcelableSpan)1 SpannableString (android.text.SpannableString)1 UpdateAppearance (jp.sblo.pandora.jota.text.style.UpdateAppearance)1