SharePrinterActivity.java 文件源码

java
阅读 23 收藏 0 点赞 0 评论 0

项目:android-print-plugin-cups 作者:
private void drawPage(PdfDocument.Page page)
{
    Log.d(TAG, "Drawing PDF page");
    Canvas canvas = page.getCanvas();
    int w = canvas.getWidth();
    int h = canvas.getHeight();
    int x = w / 2;
    int y = 0;
    int size = h / 50;
    Log.d(TAG, "w " + w + " h " + h + " x " + x + " y " + y + " size " + size + " bounds " + canvas.getClipBounds().toString());
    //layout.draw(canvas);
    Paint paint = new Paint();
    paint.setColor(Color.BLACK);
    paint.setTextSize(size * 1.5f);
    paint.setTextAlign(Paint.Align.CENTER);

    y += (paint.descent() - paint.ascent()) * 2.5;
    canvas.drawText(getResources().getString(R.string.add_printer_android, name), x, y, paint);
    paint.setTextSize(size / 1.3f);
    y += (paint.descent() - paint.ascent()) * 1.5;
    canvas.drawText(getResources().getString(R.string.add_printer_android_ver), x, y, paint);
    y += (paint.descent() - paint.ascent()) * 1.2;
    canvas.drawText(getResources().getString(R.string.install_barcode_scanner, name), x, y, paint);
    paint.setTextSize(size);
    y += (paint.descent() - paint.ascent()) * 1.5;
    canvas.drawText(getResources().getString(R.string.install_printer_plugin, getResources().getString(R.string.app_name)), x, y, paint);
    y += (paint.descent() - paint.ascent()) * 0.2;

    int qrSize = size * 13;
    paint.setFilterBitmap(false);
    canvas.drawBitmap(myAppAddr, null, new Rect(x - qrSize / 2, y, x + qrSize / 2, y + qrSize), paint);
    y += qrSize;

    y += (paint.descent() - paint.ascent()) * 0.7;
    canvas.drawText(getResources().getString(R.string.install_printer_plugin_enable, getResources().getString(R.string.app_name)), x, y, paint);
    y += (paint.descent() - paint.ascent()) * 1;
    canvas.drawText(getResources().getString(R.string.scan_qr, name), x, y, paint);
    paint.setTextSize(size / 1.3f);
    y += (paint.descent() - paint.ascent()) * 1;
    canvas.drawText(getResources().getString(R.string.scan_qr_open_browser), x, y, paint);
    paint.setTextSize(size);
    y += (paint.descent() - paint.ascent()) * 0.2;

    qrSize = size * 20;
    canvas.drawBitmap(qr, null, new Rect(x - qrSize / 2, y, x + qrSize / 2, y + qrSize), paint);
    y += qrSize;

    y += (paint.descent() - paint.ascent()) * 0.8;
    for (String line: notes.split("\n"))
    {
        canvas.drawText(line, x, y, paint);
        y += (paint.descent() - paint.ascent()) * 1;
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号