Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 525a66b2 authored by Svet Ganov's avatar Svet Ganov Committed by Svetoslav Ganov
Browse files

Adding print preview.

This change adds the pring preview part of the new print UX. The
UI has two parts, the top section is the print options and the
bottom section print preview with a list of pages. The user can
interact only with one of them. When print options are expanded
they cover the preview content and a scrim is laid out on top of
the preview. Tapping the scrim collapses the print options. When
the user types in page ranges and closes the options to look at
the preview, the latter is updated to show only these pages. In
the list of pages the user can further prune pages by deselecting
them.

Change-Id: I0b23d2c598afe2a34400ccfa43e4e935af83c72f
parent d8da5c8f
Loading
Loading
Loading
Loading
+24 −0
Original line number Original line Diff line number Diff line
@@ -78,6 +78,30 @@ public final class PageRange implements Parcelable {
        return mEnd;
        return mEnd;
    }
    }


    /**
     * Gets whether a page range contains a a given page.
     *
     * @param pageIndex The page index.
     * @return True if the page is within this range.
     *
     * @hide
     */
    public boolean contains(int pageIndex) {
        return pageIndex >= mStart && pageIndex <= mEnd;
    }

    /**
     * Get the size of this range which is the number of
     * pages it contains.
     *
     * @return The size of the range.
     *
     * @hide
     */
    public int getSize() {
        return mEnd - mStart + 1;
    }

    @Override
    @Override
    public int describeContents() {
    public int describeContents() {
        return 0;
        return 0;
+18 −16
Original line number Original line Diff line number Diff line
@@ -105,6 +105,13 @@ public final class PrintAttributes implements Parcelable {
    /**
    /**
     * Gets the minimal margins. If the content does not fit
     * Gets the minimal margins. If the content does not fit
     * these margins it will be clipped.
     * these margins it will be clipped.
     * <p>
     * <strong>These margins are physically imposed by the printer and they
     * are <em>not</em> rotated, i.e. they are the same for both portrait and
     * landscape. For example, a printer may not be able to print in a stripe
     * on both left and right sides of the page.
     * </strong>
     * </p>
     *
     *
     * @return The margins or <code>null</code> if not set.
     * @return The margins or <code>null</code> if not set.
     */
     */
@@ -115,6 +122,13 @@ public final class PrintAttributes implements Parcelable {
    /**
    /**
     * Sets the minimal margins. If the content does not fit
     * Sets the minimal margins. If the content does not fit
     * these margins it will be clipped.
     * these margins it will be clipped.
     * <p>
     * <strong>These margins are physically imposed by the printer and they
     * are <em>not</em> rotated, i.e. they are the same for both portrait and
     * landscape. For example, a printer may not be able to print in a stripe
     * on both left and right sides of the page.
     * </strong>
     * </p>
     *
     *
     * @param The margins.
     * @param The margins.
     *
     *
@@ -193,14 +207,8 @@ public final class PrintAttributes implements Parcelable {
                oldResolution.getHorizontalDpi());
                oldResolution.getHorizontalDpi());
        attributes.setResolution(newResolution);
        attributes.setResolution(newResolution);


        // Rotate the physical margins.
        // Do not rotate the physical margins.
        Margins oldMinMargins = getMinMargins();
        attributes.setMinMargins(getMinMargins());
        Margins newMinMargins = new Margins(
                oldMinMargins.getBottomMils(),
                oldMinMargins.getLeftMils(),
                oldMinMargins.getTopMils(),
                oldMinMargins.getRightMils());
        attributes.setMinMargins(newMinMargins);


        attributes.setColorMode(getColorMode());
        attributes.setColorMode(getColorMode());


@@ -236,14 +244,8 @@ public final class PrintAttributes implements Parcelable {
                oldResolution.getHorizontalDpi());
                oldResolution.getHorizontalDpi());
        attributes.setResolution(newResolution);
        attributes.setResolution(newResolution);


        // Rotate the physical margins.
        // Do not rotate the physical margins.
        Margins oldMinMargins = getMinMargins();
        attributes.setMinMargins(getMinMargins());
        Margins newMargins = new Margins(
                oldMinMargins.getTopMils(),
                oldMinMargins.getRightMils(),
                oldMinMargins.getBottomMils(),
                oldMinMargins.getLeftMils());
        attributes.setMinMargins(newMargins);


        attributes.setColorMode(getColorMode());
        attributes.setColorMode(getColorMode());


+1 −1
Original line number Original line Diff line number Diff line
@@ -105,7 +105,7 @@ public final class PrintManager {


    private static final String LOG_TAG = "PrintManager";
    private static final String LOG_TAG = "PrintManager";


    private static final boolean DEBUG = false;
    private static final boolean DEBUG = true;


    private static final int MSG_NOTIFY_PRINT_JOB_STATE_CHANGED = 1;
    private static final int MSG_NOTIFY_PRINT_JOB_STATE_CHANGED = 1;


+8 −3
Original line number Original line Diff line number Diff line
@@ -204,9 +204,13 @@ static void renderPageBitmap(FPDF_BITMAP bitmap, FPDF_PAGE page, int destLeft, i
        // PDF's coordinate system origin is left-bottom while
        // PDF's coordinate system origin is left-bottom while
        // in graphics it is the top-left, so remap the origin.
        // in graphics it is the top-left, so remap the origin.
        matrix.Set(1, 0, 0, -1, 0, pPage->GetPageHeight());
        matrix.Set(1, 0, 0, -1, 0, pPage->GetPageHeight());
        matrix.Scale(transform->getScaleX(), transform->getScaleY());

        matrix.Rotate(transform->getSkewX(), transform->getSkewY());
        SkScalar transformValues[6];
        matrix.Translate(transform->getTranslateX(), transform->getTranslateY());
        transform->asAffine(transformValues);

        matrix.Concat(transformValues[SkMatrix::kAScaleX], transformValues[SkMatrix::kASkewY],
                transformValues[SkMatrix::kASkewX], transformValues[SkMatrix::kAScaleY],
                transformValues[SkMatrix::kATransX], transformValues[SkMatrix::kATransY]);
    }
    }
    pageContext->AppendObjectList(pPage, &matrix);
    pageContext->AppendObjectList(pPage, &matrix);


@@ -251,6 +255,7 @@ static void nativeRenderPage(JNIEnv* env, jclass thiz, jlong documentPtr, jlong
    renderPageBitmap(bitmap, page, destLeft, destTop, destRight,
    renderPageBitmap(bitmap, page, destLeft, destTop, destRight,
            destBottom, skMatrix, renderFlags);
            destBottom, skMatrix, renderFlags);


    skBitmap->notifyPixelsChanged();
    skBitmap->unlockPixels();
    skBitmap->unlockPixels();
}
}


+28 −2
Original line number Original line Diff line number Diff line
@@ -70,6 +70,32 @@ import java.lang.annotation.RetentionPolicy;
 * renderer.close();
 * renderer.close();
 * </pre>
 * </pre>
 *
 *
 * <h3>Print preview and print output</h3>
 * <p>
 * If you are using this class to rasterize a PDF for printing or show a print
 * preview, it is recommended that you respect the following contract in order
 * to provide a consistent user experience when seeing a preview and printing,
 * i.e. the user sees a preview that is the same as the printout.
 * </p>
 * <ul>
 * <li>
 * Respect the property whether the document would like to be scaled for printing
 * as per {@link #shouldScaleForPrinting()}.
 * </li>
 * <li>
 * When scaling a document for printing the aspect ratio should be preserved.
 * </li>
 * <li>
 * Do not inset the content with any margins from the {@link android.print.PrintAttributes}
 * as the application is responsible to render it such that the margins are respected.
 * </li>
 * <li>
 * If document page size is greater than the printed media size the content should
 * be anchored to the upper left corner of the page for left-to-right locales and
 * top right corner for right-to-left locales.
 * </li>
 * </ul>
 *
 * @see #close()
 * @see #close()
 */
 */
public final class PdfRenderer implements AutoCloseable {
public final class PdfRenderer implements AutoCloseable {
@@ -188,7 +214,6 @@ public final class PdfRenderer implements AutoCloseable {
    private void doClose() {
    private void doClose() {
        if (mCurrentPage != null) {
        if (mCurrentPage != null) {
            mCurrentPage.close();
            mCurrentPage.close();
            mCurrentPage = null;
        }
        }
        nativeClose(mNativeDocument);
        nativeClose(mNativeDocument);
        try {
        try {
@@ -280,7 +305,7 @@ public final class PdfRenderer implements AutoCloseable {
         * </p>
         * </p>
         * <p>
         * <p>
         * You may optionally specify a matrix to transform the content from page coordinates
         * You may optionally specify a matrix to transform the content from page coordinates
         * which are in points (1/72") to bitmap coordintates which are in pixels. If this
         * which are in points (1/72") to bitmap coordinates which are in pixels. If this
         * matrix is not provided this method will apply a transformation that will fit the
         * matrix is not provided this method will apply a transformation that will fit the
         * whole page to the destination clip if provided or the destination bitmap if no
         * whole page to the destination clip if provided or the destination bitmap if no
         * clip is provided.
         * clip is provided.
@@ -375,6 +400,7 @@ public final class PdfRenderer implements AutoCloseable {
            nativeClosePage(mNativePage);
            nativeClosePage(mNativePage);
            mNativePage = 0;
            mNativePage = 0;
            mCloseGuard.close();
            mCloseGuard.close();
            mCurrentPage = null;
        }
        }


        private void throwIfClosed() {
        private void throwIfClosed() {
Loading