aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf
diff options
context:
space:
mode:
authorGravatar halcanary <halcanary@google.com>2015-03-25 07:11:08 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-03-25 07:11:08 -0700
commit9d85145590894e8114056f0bbe24ba76581336c5 (patch)
treeb84a08d5255defbc617360a3abccaa7b786cb0c1 /src/pdf
parent478652e918d73a4c0330e27e03eaa9564138c0f7 (diff)
SkPDF: clean up skpdfdocument, add static functions
Add SkPDFDocument::EmitPDF and SkPDFDocument::GetCountOfFontTypes Also, make SkPDFDocument::appendPage return void, not bool. Motivation: These static functions can be used to print subsets of a pdf document (functionality to be added in a later CL). BUG=skia:3585 Review URL: https://codereview.chromium.org/1036853002
Diffstat (limited to 'src/pdf')
-rw-r--r--src/pdf/SkPDFDocument.cpp24
-rw-r--r--src/pdf/SkPDFDocument.h50
2 files changed, 47 insertions, 27 deletions
diff --git a/src/pdf/SkPDFDocument.cpp b/src/pdf/SkPDFDocument.cpp
index 4009cef9b6..57eab950ed 100644
--- a/src/pdf/SkPDFDocument.cpp
+++ b/src/pdf/SkPDFDocument.cpp
@@ -39,10 +39,6 @@ static void perform_font_subsetting(SkPDFCatalog* catalog,
}
}
-SkPDFDocument::SkPDFDocument() {}
-
-SkPDFDocument::~SkPDFDocument() { fPageDevices.unrefAll(); }
-
static void emit_pdf_header(SkWStream* stream) {
stream->writeText("%PDF-1.4\n%");
// The PDF spec recommends including a comment with four bytes, all
@@ -69,15 +65,16 @@ static void emit_pdf_footer(SkWStream* stream,
stream->writeText("\n%%EOF");
}
-bool SkPDFDocument::emitPDF(SkWStream* stream) {
- // SkTDArray<SkPDFDevice*> fPageDevices;
- if (fPageDevices.isEmpty()) {
+bool SkPDFDocument::EmitPDF(const SkTDArray<SkPDFDevice*>& pageDevices,
+ SkWStream* stream) {
+ if (pageDevices.isEmpty()) {
return false;
}
SkTDArray<SkPDFPage*> pages;
- for (int i = 0; i < fPageDevices.count(); i++) {
+ for (int i = 0; i < pageDevices.count(); i++) {
+ SkASSERT(pageDevices[i]);
// Reference from new passed to pages.
- pages.push(SkNEW_ARGS(SkPDFPage, (fPageDevices[i])));
+ pages.push(SkNEW_ARGS(SkPDFPage, (pageDevices[i])));
}
SkPDFCatalog catalog;
@@ -194,19 +191,20 @@ bool SkPDFDocument::emitPDF(SkWStream* stream) {
}
// TODO(halcanary): expose notEmbeddableCount in SkDocument
-void SkPDFDocument::getCountOfFontTypes(
+void SkPDFDocument::GetCountOfFontTypes(
+ const SkTDArray<SkPDFDevice*>& pageDevices,
int counts[SkAdvancedTypefaceMetrics::kOther_Font + 1],
int* notSubsettableCount,
- int* notEmbeddableCount) const {
+ int* notEmbeddableCount) {
sk_bzero(counts, sizeof(int) *
(SkAdvancedTypefaceMetrics::kOther_Font + 1));
SkTDArray<SkFontID> seenFonts;
int notSubsettable = 0;
int notEmbeddable = 0;
- for (int pageNumber = 0; pageNumber < fPageDevices.count(); pageNumber++) {
+ for (int pageNumber = 0; pageNumber < pageDevices.count(); pageNumber++) {
const SkTDArray<SkPDFFont*>& fontResources =
- fPageDevices[pageNumber]->getFontResources();
+ pageDevices[pageNumber]->getFontResources();
for (int font = 0; font < fontResources.count(); font++) {
SkFontID fontID = fontResources[font]->typeface()->uniqueID();
if (seenFonts.find(fontID) == -1) {
diff --git a/src/pdf/SkPDFDocument.h b/src/pdf/SkPDFDocument.h
index e4c0521cbe..fce9f9df83 100644
--- a/src/pdf/SkPDFDocument.h
+++ b/src/pdf/SkPDFDocument.h
@@ -29,34 +29,56 @@ template <typename T> class SkTSet;
*/
class SkPDFDocument {
public:
- SkPDFDocument();
- ~SkPDFDocument();
+ SkPDFDocument() {}
+ ~SkPDFDocument() { fPageDevices.unrefAll(); }
/** Output the PDF to the passed stream. It is an error to call this (it
- * will return false and not modify stream) if no pages have been added
- * or there are pages missing (i.e. page 1 and 3 have been added, but not
- * page 2).
+ * will return false and not modify stream) if pageDevices is empty.
+ * No device pointer can be NULL.
+ *
+ * @param pageDevices An array of pages, in order. All pages
+ * should be created using the same SkPDFCanon.
+ * TODO(halcanary): ASSERT this condition.
+ * @param SkWStream The writable output stream to send the PDF to.
+ */
+ static bool EmitPDF(const SkTDArray<SkPDFDevice*>& pageDevices, SkWStream*);
+
+ /** Output the PDF to the passed stream. It is an error to call this (it
+ * will return false and not modify stream) if no pages have been added.
*
* @param stream The writable output stream to send the PDF to.
*/
- bool emitPDF(SkWStream* stream);
+ bool emitPDF(SkWStream* stream) const {
+ return SkPDFDocument::EmitPDF(fPageDevices, stream);
+ }
- /** Append the passed pdf device to the document as a new page. Returns
- * true if successful. Will fail if the document has already been emitted.
+ /** Append the passed pdf device to the document as a new page.
*
- * @param pdfDevice The page to add to this document.
+ * @param pdfDevice The page to add to this document. All pages
+ * added to this document should be created
+ * using the same SkPDFCanon.
*/
- bool appendPage(SkPDFDevice* pdfDevice) {
+ void appendPage(SkPDFDevice* pdfDevice) {
fPageDevices.push(SkRef(pdfDevice));
- return true;
}
+ /** Get the count of unique font types used in the given pages.
+ */
+ static void GetCountOfFontTypes(
+ const SkTDArray<SkPDFDevice*>& pageDevices,
+ int counts[SkAdvancedTypefaceMetrics::kOther_Font + 1],
+ int* notSubsettableCount,
+ int* notEmbedddableCount);
+
/** Get the count of unique font types used in the document.
*/
void getCountOfFontTypes(
- int counts[SkAdvancedTypefaceMetrics::kOther_Font + 1],
- int* notSubsettableCount,
- int* notEmbedddableCount) const;
+ int counts[SkAdvancedTypefaceMetrics::kOther_Font + 1],
+ int* notSubsettableCount,
+ int* notEmbedddableCount) const {
+ return SkPDFDocument::GetCountOfFontTypes(
+ fPageDevices, counts, notSubsettableCount, notEmbedddableCount);
+ }
private:
SkTDArray<SkPDFDevice*> fPageDevices;