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

Commit 6e1e8b17 authored by Svetoslav's avatar Svetoslav Committed by Android Git Automerger
Browse files

am c0e1ae01: am facc08c7: Merge "Move PdfDocument to android.graphics.pdf" into klp-dev

* commit 'c0e1ae01':
  Move PdfDocument to android.graphics.pdf
parents d052ee34 c0e1ae01
Loading
Loading
Loading
Loading
+38 −36
Original line number Diff line number Diff line
@@ -10419,6 +10419,37 @@ package android.graphics.drawable.shapes {
}
package android.graphics.pdf {
  public class PdfDocument {
    ctor public PdfDocument();
    method public void close();
    method public void finishPage(android.graphics.pdf.PdfDocument.Page);
    method public java.util.List<android.graphics.pdf.PdfDocument.PageInfo> getPages();
    method public android.graphics.pdf.PdfDocument.Page startPage(android.graphics.pdf.PdfDocument.PageInfo);
    method public void writeTo(java.io.OutputStream) throws java.io.IOException;
  }
  public static final class PdfDocument.Page {
    method public android.graphics.Canvas getCanvas();
    method public android.graphics.pdf.PdfDocument.PageInfo getInfo();
  }
  public static final class PdfDocument.PageInfo {
    method public android.graphics.Rect getContentRect();
    method public int getPageHeight();
    method public int getPageNumber();
    method public int getPageWidth();
  }
  public static final class PdfDocument.PageInfo.Builder {
    ctor public PdfDocument.PageInfo.Builder(int, int, int);
    method public android.graphics.pdf.PdfDocument.PageInfo create();
    method public android.graphics.pdf.PdfDocument.PageInfo.Builder setContentRect(android.graphics.Rect);
  }
}
package android.hardware {
  public class Camera {
@@ -19313,7 +19344,7 @@ package android.print {
    method public abstract void onLayout(android.print.PrintAttributes, android.print.PrintAttributes, android.os.CancellationSignal, android.print.PrintDocumentAdapter.LayoutResultCallback, android.os.Bundle);
    method public void onStart();
    method public abstract void onWrite(android.print.PageRange[], android.os.ParcelFileDescriptor, android.os.CancellationSignal, android.print.PrintDocumentAdapter.WriteResultCallback);
    field public static final java.lang.String METADATA_KEY_PRINT_PREVIEW = "KEY_METADATA_PRINT_PREVIEW";
    field public static final java.lang.String EXTRA_PRINT_PREVIEW = "EXTRA_PRINT_PREVIEW";
  }
  public static abstract class PrintDocumentAdapter.LayoutResultCallback {
@@ -19449,41 +19480,12 @@ package android.print {
package android.print.pdf {
  public final class PdfDocument {
    method public void close();
    method public void finishPage(android.print.pdf.PdfDocument.Page);
    method public java.util.List<android.print.pdf.PdfDocument.PageInfo> getPages();
    method public static android.print.pdf.PdfDocument open();
    method public android.print.pdf.PdfDocument.Page startPage(android.print.pdf.PdfDocument.PageInfo);
    method public void writeTo(java.io.OutputStream);
  }
  public static final class PdfDocument.Page {
    method public android.graphics.Canvas getCanvas();
    method public android.print.pdf.PdfDocument.PageInfo getInfo();
  }
  public static final class PdfDocument.PageInfo {
    method public android.graphics.Rect getContentSize();
    method public android.graphics.Matrix getInitialTransform();
    method public int getPageNumber();
    method public android.graphics.Rect getPageSize();
  }
  public static final class PdfDocument.PageInfo.Builder {
    ctor public PdfDocument.PageInfo.Builder(android.graphics.Rect, int);
    method public android.print.pdf.PdfDocument.PageInfo create();
    method public android.print.pdf.PdfDocument.PageInfo.Builder setContentSize(android.graphics.Rect);
    method public android.print.pdf.PdfDocument.PageInfo.Builder setInitialTransform(android.graphics.Matrix);
  }
  public final class PrintedPdfDocument {
    method public void close();
    method public void finishPage(android.print.pdf.PdfDocument.Page);
    method public java.util.List<android.print.pdf.PdfDocument.PageInfo> getPages();
    method public static android.print.pdf.PrintedPdfDocument open(android.content.Context, android.print.PrintAttributes);
    method public android.print.pdf.PdfDocument.Page startPage(int);
    method public void writeTo(java.io.OutputStream);
  public class PrintedPdfDocument extends android.graphics.pdf.PdfDocument {
    ctor public PrintedPdfDocument(android.content.Context, android.print.PrintAttributes);
    method public android.graphics.Rect getPageContentRect();
    method public int getPageHeight();
    method public int getPageWidth();
    method public android.graphics.pdf.PdfDocument.Page startPage(int);
  }
}
+5 −5
Original line number Diff line number Diff line
@@ -74,10 +74,10 @@ import android.os.ParcelFileDescriptor;
public abstract class PrintDocumentAdapter {

    /**
     * Meta-data key: mapped to a boolean value that is <code>true</code> if
     * Extra: mapped to a boolean value that is <code>true</code> if
     * the current layout is for a print preview, <code>false</code> otherwise.
     */
    public static final String METADATA_KEY_PRINT_PREVIEW = "KEY_METADATA_PRINT_PREVIEW";
    public static final String EXTRA_PRINT_PREVIEW = "EXTRA_PRINT_PREVIEW";

    /**
     * Called when printing starts. You can use this callback to allocate
@@ -112,15 +112,15 @@ public abstract class PrintDocumentAdapter {
     * @param newAttributes The new print attributes.
     * @param cancellationSignal Signal for observing cancel layout requests.
     * @param callback Callback to inform the system for the layout result.
     * @param metadata Additional information about how layout the content.
     * @param extras Additional information about how to layout the content.
     *
     * @see LayoutResultCallback
     * @see CancellationSignal
     * @see #METADATA_KEY_PRINT_PREVIEW
     * @see #EXTRA_PRINT_PREVIEW
     */
    public abstract void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
            CancellationSignal cancellationSignal, LayoutResultCallback callback,
            Bundle metadata);
            Bundle extras);

    /**
     * Called when specific pages of the content should be written in the
+73 −74
Original line number Diff line number Diff line
@@ -18,63 +18,77 @@ package android.print.pdf;

import android.content.Context;
import android.graphics.Rect;
import android.graphics.pdf.PdfDocument;
import android.graphics.pdf.PdfDocument.Page;
import android.graphics.pdf.PdfDocument.PageInfo;
import android.print.PrintAttributes;
import android.print.PrintAttributes.Margins;
import android.print.PrintAttributes.MediaSize;
import android.print.pdf.PdfDocument;
import android.print.pdf.PdfDocument.Page;
import android.print.pdf.PdfDocument.PageInfo;

import java.io.OutputStream;
import java.util.List;

/**
 * This class is a helper for printing content to a different media
 * size. This class is responsible for computing a correct page size
 * given some print constraints, i.e. {@link PrintAttributes}. It is
 * an adapter around a {@link PdfDocument}.
 * This class is a helper for creating a PDF file for given print
 * attributes. It is useful for implementing printing via the native
 * Android graphics APIs.
 * <p>
 * This class computes the page width, page height, and content rectangle
 * from the provided print attributes and these precomputed values can be
 * accessed via {@link #getPageWidth()}, {@link #getPageHeight()}, and
 * {@link #getPageContentRect()}, respectively. The {@link #startPage(int)}
 * methods creates pages whose {@link PageInfo} is initialized with the
 * precomputed values for width, height, and content rectangle.
 * <p>
 * A typical use of the APIs looks like this:
 * </p>
 * <pre>
 * // open a new document
 * PrintedPdfDocument document = new PrintedPdfDocument(context,
 *         printAttributes);
 *
 * // start a page
 * Page page = document.startPage(0);
 *
 * // draw something on the page
 * View content = getContentView();
 * content.draw(page.getCanvas());
 *
 * // finish the page
 * document.finishPage(page);
 * . . .
 * // add more pages
 * . . .
 * // write the document content
 * document.writeTo(getOutputStream());
 *
 * //close the document
 * document.close();
 * </pre>
 */
public final class PrintedPdfDocument {
public class PrintedPdfDocument extends PdfDocument {
    private static final int MILS_PER_INCH = 1000;
    private static final int POINTS_IN_INCH = 72;

    private final PdfDocument mDocument = PdfDocument.open();
    private final Rect mPageSize = new Rect();
    private final Rect mContentSize = new Rect();
    private final int mPageWidth;
    private final int mPageHeight;
    private final Rect mContentRect;

    /**
     * Opens a new document. The document pages are computed based on
     * the passes in {@link PrintAttributes}.
     * Creates a new document.
     * <p>
     * <strong>Note:</strong> You must close the document after you are
     * done by calling {@link #close()}
     * done by calling {@link #close()}.
     * </p>
     *
     * @param context Context instance for accessing resources.
     * @param attributes The print attributes.
     * @return The document.
     *
     * @see #close()
     */
    public static PrintedPdfDocument open(Context context, PrintAttributes attributes) {
        return new PrintedPdfDocument(context, attributes);
    }

    /**
     * Creates a new instance.
     *
     * @param context Context instance for accessing resources and services.
     * @param attributes The {@link PrintAttributes} to user.
     */
    private PrintedPdfDocument(Context context, PrintAttributes attributes) {
    public PrintedPdfDocument(Context context, PrintAttributes attributes) {
        MediaSize mediaSize = attributes.getMediaSize();

        // Compute the size of the target canvas from the attributes.
        final int pageWidth = (int) (((float) mediaSize.getWidthMils() / MILS_PER_INCH)
        mPageWidth = (int) (((float) mediaSize.getWidthMils() / MILS_PER_INCH)
                * POINTS_IN_INCH);
        final int pageHeight = (int) (((float) mediaSize.getHeightMils() / MILS_PER_INCH)
        mPageHeight = (int) (((float) mediaSize.getHeightMils() / MILS_PER_INCH)
                * POINTS_IN_INCH);
        mPageSize.set(0, 0, pageWidth, pageHeight);

        // Compute the content size from the attributes.
        Margins minMargins = attributes.getMinMargins();
@@ -86,14 +100,14 @@ public final class PrintedPdfDocument {
                * POINTS_IN_INCH);
        final int marginBottom = (int) (((float) minMargins.getBottomMils() / MILS_PER_INCH)
                * POINTS_IN_INCH);
        mContentSize.set(mPageSize.left + marginLeft, mPageSize.top + marginTop,
                mPageSize.right - marginRight, mPageSize.bottom - marginBottom);
        mContentRect = new Rect(marginLeft, marginTop, mPageWidth - marginRight,
                mPageHeight - marginBottom);
    }

    /**
     * Starts a page using a page size computed from the print attributes
     * passed in {@link #open(Context, PrintAttributes)} and the given page
     * number to create appropriate {@link PageInfo}.
     * Starts a new page. The page is created using width, height  and content
     * rectangle computed from the print attributes passed in the constructor
     * and the given page number to create an appropriate {@link PageInfo}.
     * <p>
     * After the page is created you can draw arbitrary content on the page's
     * canvas which you can get by calling {@link Page#getCanvas() Page.getCanvas()}.
@@ -103,63 +117,48 @@ public final class PrintedPdfDocument {
     * </p>
     * <p>
     * <strong>Note:</strong> Do not call this method after {@link #close()}.
     * Also do not call this method if the last page returned by this method
     * is not finished by calling {@link #finishPage(Page)}.
     * </p>
     *
     * @param pageNumber The page number.
     * @param pageNumber The page number. Must be a positive value.
     * @return A blank page.
     *
     * @see #finishPage(Page)
     */
    public Page startPage(int pageNumber) {
        PageInfo pageInfo = new PageInfo
                .Builder(mPageSize, 0)
                .setContentSize(mContentSize)
                .Builder(mPageWidth, mPageHeight, pageNumber)
                .setContentRect(mContentRect)
                .create();
        Page page = mDocument.startPage(pageInfo);
        return page;
        return startPage(pageInfo);
    }

    /**
     * Finishes a started page. You should always finish the last started page.
     * <p>
     * <strong>Note:</strong> Do not call this method after {@link #close()}.
     * </p>
     *
     * @param page The page.
     * Gets the page width.
     *
     * @see #startPage(int)
     * @return The page width in PostScript points (1/72th of an inch).
     */
    public void finishPage(Page page) {
        mDocument.finishPage(page);
    public int getPageWidth() {
        return mPageWidth;
    }

    /**
     * Writes the document to an output stream.
     * <p>
     * <strong>Note:</strong> Do not call this method after {@link #close()}.
     * </p>
     * Gets the page height.
     *
     * @param out The output stream.
     * @return The page height in PostScript points (1/72th of an inch).
     */
    public void writeTo(OutputStream out) {
        mDocument.writeTo(out);
    public int getPageHeight() {
        return mPageHeight;
    }

    /**
     * Gets the pages of the document.
     * Gets the content rectangle. This is the area of the page that
     * contains printed data and is relative to the page top left.
     *
     * @return The pages.
     */
    public List<PageInfo> getPages() {
        return mDocument.getPages();
    }

    /**
     * Closes this document. This method should be called after you
     * are done working with the document. After this call the document
     * is considered closed and none of its methods should be called.
     * @return The content rectangle.
     */
    public void close() {
        mDocument.close();
    public Rect getPageContentRect() {
        return mContentRect;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -4,12 +4,12 @@
Provides classes for implementing print services. Print services are plug-in components
that know how to talk to printers via some standard protocols. These services serve as a
bridge between the system and the printers. Hence, the printer and print protocol specific
implementation is factored out of the system and can by independently developed and updated.
implementation is factored out of the system and can be independently developed and updated.
</p>
<p>
A print service implementation should extend {@link android.printservice.PrintService}
and implement its abstract methods. Also the print service has to follow the contract for
managing print {@link android.printservice.PrintJob}s.
managing {@link android.printservice.PrintJob}s.
<p/>
<p>
The system is responsible for starting and stopping a print service depending on whether
+1 −1
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ LOCAL_SRC_FILES:= \
	android/graphics/Utils.cpp \
	android/graphics/Xfermode.cpp \
	android/graphics/YuvToJpegEncoder.cpp \
	android/graphics/pdf/PdfDocument.cpp \
	android_media_AudioRecord.cpp \
	android_media_AudioSystem.cpp \
	android_media_AudioTrack.cpp \
@@ -135,7 +136,6 @@ LOCAL_SRC_FILES:= \
	android_util_FileObserver.cpp \
	android/opengl/poly_clip.cpp.arm \
	android/opengl/util.cpp.arm \
	android/print/android_print_pdf_PdfDocument.cpp \
	android_server_NetworkManagementSocketTagger.cpp \
	android_server_Watchdog.cpp \
	android_ddm_DdmHandleNativeHeap.cpp \
Loading