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
This commit is contained in:
parent
478652e918
commit
9d85145590
@ -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) {
|
||||
|
@ -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);
|
||||
|
||||
/** 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.
|
||||
*
|
||||
* @param pdfDevice The page to add to this document.
|
||||
*/
|
||||
bool appendPage(SkPDFDevice* pdfDevice) {
|
||||
fPageDevices.push(SkRef(pdfDevice));
|
||||
return true;
|
||||
bool emitPDF(SkWStream* stream) const {
|
||||
return SkPDFDocument::EmitPDF(fPageDevices, stream);
|
||||
}
|
||||
|
||||
/** Append the passed pdf device to the document as a new page.
|
||||
*
|
||||
* @param pdfDevice The page to add to this document. All pages
|
||||
* added to this document should be created
|
||||
* using the same SkPDFCanon.
|
||||
*/
|
||||
void appendPage(SkPDFDevice* pdfDevice) {
|
||||
fPageDevices.push(SkRef(pdfDevice));
|
||||
}
|
||||
|
||||
/** 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;
|
||||
|
Loading…
Reference in New Issue
Block a user