Android Open Source - SysLog Paint Renderer






From Project

Back to project page SysLog.

License

The source code is released under:

GNU General Public License

If you think the Android project SysLog listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2007 The Android Open Source Project
 */*from w  ww . j a  v  a 2s.  c  o m*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jackpal.androidterm.emulatorview;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.util.FloatMath;


class PaintRenderer extends BaseTextRenderer {
    public PaintRenderer(int fontSize, ColorScheme scheme) {
        super(scheme);
        mTextPaint = new Paint();
        mTextPaint.setTypeface(Typeface.MONOSPACE);
        mTextPaint.setAntiAlias(true);
        mTextPaint.setTextSize(fontSize);

        mCharHeight = (int) FloatMath.ceil(mTextPaint.getFontSpacing());
        mCharAscent = (int) FloatMath.ceil(mTextPaint.ascent());
        mCharDescent = mCharHeight + mCharAscent;
        mCharWidth = mTextPaint.measureText(EXAMPLE_CHAR, 0, 1);
    }

    public void drawTextRun(Canvas canvas, float x, float y, int lineOffset,
            int runWidth, char[] text, int index, int count,
            boolean selectionStyle, int textStyle,
            int cursorOffset, int cursorIndex, int cursorIncr, int cursorWidth, int cursorMode) {
        int foreColor = TextStyle.decodeForeColor(textStyle);
        int backColor = TextStyle.decodeBackColor(textStyle);
        int effect = TextStyle.decodeEffect(textStyle);

        boolean inverse =  mReverseVideo ^
                (effect & (TextStyle.fxInverse | TextStyle.fxItalic)) != 0;
        if (inverse) {
            int temp = foreColor;
            foreColor = backColor;
            backColor = temp;
        }

        if (selectionStyle) {
            backColor = TextStyle.ciCursorBackground;
        }

        boolean blink = (effect & TextStyle.fxBlink) != 0;
        if (blink && backColor < 8) {
            backColor += 8;
        }
        mTextPaint.setColor(mPalette[backColor]);

        float left = x + lineOffset * mCharWidth;
        canvas.drawRect(left, y + mCharAscent - mCharDescent,
                left + runWidth * mCharWidth, y,
                mTextPaint);

        boolean cursorVisible = lineOffset <= cursorOffset && cursorOffset < (lineOffset + runWidth);
        float cursorX = 0;
        if (cursorVisible) {
            cursorX = x + cursorOffset * mCharWidth;
            drawCursorImp(canvas, (int) cursorX, y, cursorWidth * mCharWidth, mCharHeight, cursorMode);
        }

        boolean invisible = (effect & TextStyle.fxInvisible) != 0;
        if (!invisible) {
            boolean bold = (effect & TextStyle.fxBold) != 0;
            boolean underline = (effect & TextStyle.fxUnderline) != 0;
            if (bold) {
                mTextPaint.setFakeBoldText(true);
            }
            if (underline) {
                mTextPaint.setUnderlineText(true);
            }
            int textPaintColor;
            if (foreColor < 8 && bold) {
                // In 16-color mode, bold also implies bright foreground colors
                textPaintColor = mPalette[foreColor+8];
            } else {
                textPaintColor = mPalette[foreColor];
            }
            mTextPaint.setColor(textPaintColor);

            float textOriginY = y - mCharDescent;

            if (cursorVisible) {
                // Text before cursor
                int countBeforeCursor = cursorIndex - index;
                int countAfterCursor = count - (countBeforeCursor + cursorIncr);
                if (countBeforeCursor > 0){
                    canvas.drawText(text, index, countBeforeCursor, left, textOriginY, mTextPaint);
                }
                // Text at cursor
                mTextPaint.setColor(mPalette[TextStyle.ciCursorForeground]);
                canvas.drawText(text, cursorIndex, cursorIncr, cursorX,
                        textOriginY, mTextPaint);
                // Text after cursor
                if (countAfterCursor > 0) {
                    mTextPaint.setColor(textPaintColor);
                    canvas.drawText(text, cursorIndex + cursorIncr, countAfterCursor,
                            cursorX + cursorWidth * mCharWidth,
                            textOriginY, mTextPaint);
                }
            } else {
                canvas.drawText(text, index, count, left, textOriginY, mTextPaint);
            }
            if (bold) {
                mTextPaint.setFakeBoldText(false);
            }
            if (underline) {
                mTextPaint.setUnderlineText(false);
            }
        }
    }

    public int getCharacterHeight() {
        return mCharHeight;
    }

    public float getCharacterWidth() {
        return mCharWidth;
    }

    public int getTopMargin() {
        return mCharDescent;
    }

    private Paint mTextPaint;
    private float mCharWidth;
    private int mCharHeight;
    private int mCharAscent;
    private int mCharDescent;
    private static final char[] EXAMPLE_CHAR = {'X'};
}




Java Source Code List

com.tortel.syslog.GrepOption.java
com.tortel.syslog.LiveLogActivity.java
com.tortel.syslog.MainActivity.java
com.tortel.syslog.Result.java
com.tortel.syslog.RunCommand.java
com.tortel.syslog.ZipWriter.java
com.tortel.syslog.dialog.AboutDialog.java
com.tortel.syslog.dialog.CustomPathDialog.java
com.tortel.syslog.dialog.ExceptionDialog.java
com.tortel.syslog.dialog.FaqDialog.java
com.tortel.syslog.dialog.LowSpaceDialog.java
com.tortel.syslog.dialog.OhShitDialog.java
com.tortel.syslog.exception.CreateFolderException.java
com.tortel.syslog.exception.LowSpaceException.java
com.tortel.syslog.exception.NoFilesException.java
com.tortel.syslog.exception.RunCommandException.java
com.tortel.syslog.utils.InputStreamWrapper.java
com.tortel.syslog.utils.ScrubberUtils.java
com.tortel.syslog.utils.Utils.java
jackpal.androidterm.emulatorview.BaseTextRenderer.java
jackpal.androidterm.emulatorview.Bitmap4x8FontRenderer.java
jackpal.androidterm.emulatorview.ByteQueue.java
jackpal.androidterm.emulatorview.ColorScheme.java
jackpal.androidterm.emulatorview.EmulatorDebug.java
jackpal.androidterm.emulatorview.EmulatorView.java
jackpal.androidterm.emulatorview.GrowableIntArray.java
jackpal.androidterm.emulatorview.PaintRenderer.java
jackpal.androidterm.emulatorview.Screen.java
jackpal.androidterm.emulatorview.StyleRow.java
jackpal.androidterm.emulatorview.TermKeyListener.java
jackpal.androidterm.emulatorview.TermSession.java
jackpal.androidterm.emulatorview.TerminalEmulator.java
jackpal.androidterm.emulatorview.TextRenderer.java
jackpal.androidterm.emulatorview.TextStyle.java
jackpal.androidterm.emulatorview.TranscriptScreen.java
jackpal.androidterm.emulatorview.UnicodeTranscript.java
jackpal.androidterm.emulatorview.UpdateCallback.java
jackpal.androidterm.emulatorview.compat.AndroidCharacterCompat.java
jackpal.androidterm.emulatorview.compat.AndroidCompat.java
jackpal.androidterm.emulatorview.compat.ClipboardManagerCompatFactory.java
jackpal.androidterm.emulatorview.compat.ClipboardManagerCompatV11.java
jackpal.androidterm.emulatorview.compat.ClipboardManagerCompatV1.java
jackpal.androidterm.emulatorview.compat.ClipboardManagerCompat.java
jackpal.androidterm.emulatorview.compat.KeyCharacterMapCompat.java
jackpal.androidterm.emulatorview.compat.KeycodeConstants.java
jackpal.androidterm.emulatorview.compat.Patterns.java