aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/pdf
diff options
context:
space:
mode:
Diffstat (limited to 'include/pdf')
-rwxr-xr-xinclude/pdf/SkBitSet.h6
-rw-r--r--include/pdf/SkPDFDevice.h19
-rw-r--r--include/pdf/SkPDFDocument.h1
-rw-r--r--include/pdf/SkPDFFont.h172
-rw-r--r--include/pdf/SkPDFPage.h5
5 files changed, 138 insertions, 65 deletions
diff --git a/include/pdf/SkBitSet.h b/include/pdf/SkBitSet.h
index 84d52e547c..01d9c6cf3a 100755
--- a/include/pdf/SkBitSet.h
+++ b/include/pdf/SkBitSet.h
@@ -40,12 +40,12 @@ public:
/** Test if bit index is set.
*/
- bool isBitSet(int index);
+ bool isBitSet(int index) const;
/** Or bits from source. false is returned if this doesn't have the same
* bit count as source.
*/
- bool orBits(SkBitSet& source);
+ bool orBits(const SkBitSet& source);
private:
SkAutoFree fBitData;
@@ -53,7 +53,7 @@ private:
size_t fDwordCount;
size_t fBitCount;
- uint32_t* internalGet(int index) {
+ uint32_t* internalGet(int index) const {
SkASSERT((size_t)index < fBitCount);
size_t internalIndex = index / 32;
SkASSERT(internalIndex < fDwordCount);
diff --git a/include/pdf/SkPDFDevice.h b/include/pdf/SkPDFDevice.h
index 7a3e7bb7f1..1a0807aa67 100644
--- a/include/pdf/SkPDFDevice.h
+++ b/include/pdf/SkPDFDevice.h
@@ -30,6 +30,7 @@ class SkPDFDevice;
class SkPDFDict;
class SkPDFFont;
class SkPDFFormXObject;
+class SkPDFGlyphSetMap;
class SkPDFGraphicState;
class SkPDFObject;
class SkPDFShader;
@@ -150,11 +151,18 @@ public:
* for calling data->unref() when it is finished.
*/
SK_API SkData* copyContentToData() const;
-
+
SK_API const SkMatrix& initialTransform() const {
return fInitialTransform;
}
+ /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font
+ * that shows on this device.
+ */
+ const SkPDFGlyphSetMap& getFontGlyphUsage() const {
+ return *(fFontGlyphUsage.get());
+ }
+
private:
// TODO(vandebo) push most of SkPDFDevice's state into a core object in
// order to get the right access levels without using friend.
@@ -183,17 +191,20 @@ private:
ContentEntry* getLastContentEntry();
void setLastContentEntry(ContentEntry* contentEntry);
+ // Glyph ids used for each font on this device.
+ SkTScopedPtr<SkPDFGlyphSetMap> fFontGlyphUsage;
+
SkPDFDevice(const SkISize& layerSize, const SkClipStack& existingClipStack,
const SkRegion& existingClipRegion);
// override from SkDevice
- virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config,
- int width, int height,
+ virtual SkDevice* onCreateCompatibleDevice(SkBitmap::Config config,
+ int width, int height,
bool isOpaque,
Usage usage);
void init();
- void cleanUp();
+ void cleanUp(bool clearFontUsage);
void createFormXObjectFromDevice(SkRefPtr<SkPDFFormXObject>* xobject);
// Clear the passed clip from all existing content entries.
diff --git a/include/pdf/SkPDFDocument.h b/include/pdf/SkPDFDocument.h
index 3f171f5f27..8b472e1bd0 100644
--- a/include/pdf/SkPDFDocument.h
+++ b/include/pdf/SkPDFDocument.h
@@ -81,6 +81,7 @@ private:
SkTDArray<SkPDFDict*> fPageTree;
SkRefPtr<SkPDFDict> fDocCatalog;
SkTDArray<SkPDFObject*> fPageResources;
+ SkTDArray<SkPDFObject*> fSubstitutes;
int fSecondPageFirstResourceIndex;
SkRefPtr<SkPDFDict> fTrailerDict;
diff --git a/include/pdf/SkPDFFont.h b/include/pdf/SkPDFFont.h
index 182f27d062..00dcb95a6a 100644
--- a/include/pdf/SkPDFFont.h
+++ b/include/pdf/SkPDFFont.h
@@ -18,11 +18,63 @@
#define SkPDFFont_DEFINED
#include "SkAdvancedTypefaceMetrics.h"
+#include "SkBitSet.h"
#include "SkPDFTypes.h"
#include "SkTDArray.h"
#include "SkThread.h"
+#include "SkTypeface.h"
class SkPaint;
+class SkPDFCatalog;
+class SkPDFFont;
+
+class SkPDFGlyphSet : public SkNoncopyable {
+public:
+ SkPDFGlyphSet();
+
+ void set(const uint16_t* glyphIDs, int numGlyphs);
+ bool has(uint16_t glyphID) const;
+ void merge(const SkPDFGlyphSet& usage);
+
+private:
+ SkBitSet fBitSet;
+};
+
+class SkPDFGlyphSetMap : public SkNoncopyable {
+public:
+ struct FontGlyphSetPair {
+ FontGlyphSetPair(SkPDFFont* font, SkPDFGlyphSet* glyphSet);
+
+ SkPDFFont* fFont;
+ SkPDFGlyphSet* fGlyphSet;
+ };
+
+ SkPDFGlyphSetMap();
+ ~SkPDFGlyphSetMap();
+
+ class F2BIter {
+ public:
+ F2BIter(const SkPDFGlyphSetMap& map);
+ FontGlyphSetPair* next() const;
+ void reset(const SkPDFGlyphSetMap& map);
+
+ private:
+ const SkTDArray<FontGlyphSetPair>* fMap;
+ mutable int fIndex;
+ };
+
+ void merge(const SkPDFGlyphSetMap& usage);
+ void reset();
+
+ void noteGlyphUsage(SkPDFFont* font, const uint16_t* glyphIDs,
+ int numGlyphs);
+
+private:
+ SkPDFGlyphSet* getGlyphSetForFont(SkPDFFont* font);
+
+ SkTDArray<FontGlyphSetPair> fMap;
+};
+
/** \class SkPDFFont
A PDF Object class representing a font. The font may have resources
@@ -45,15 +97,15 @@ public:
/** Returns the font type represented in this font. For Type0 fonts,
* returns the type of the decendant font.
*/
- SK_API SkAdvancedTypefaceMetrics::FontType getType();
+ SK_API virtual SkAdvancedTypefaceMetrics::FontType getType();
- /** Return true if this font has an encoding for the passed glyph id.
+ /** Returns true if this font encoding supports glyph IDs above 255.
*/
- SK_API bool hasGlyph(uint16_t glyphID);
+ SK_API virtual bool multiByteGlyphs() const = 0;
- /** Returns true if this font encoding supports glyph IDs above 255.
+ /** Return true if this font has an encoding for the passed glyph id.
*/
- SK_API bool multiByteGlyphs();
+ SK_API bool hasGlyph(uint16_t glyphID);
/** Convert (in place) the input glyph IDs into the font encoding. If the
* font has more glyphs than can be encoded (like a type 1 font with more
@@ -76,13 +128,64 @@ public:
SK_API static SkPDFFont* GetFontResource(SkTypeface* typeface,
uint16_t glyphID);
+ /** Subset the font based on usage set. Returns a SkPDFFont instance with
+ * subset.
+ * @param usage Glyph subset requested.
+ * @return NULL if font does not support subsetting, a new instance
+ * of SkPDFFont otherwise.
+ */
+ SK_API virtual SkPDFFont* getFontSubset(const SkPDFGlyphSet* usage);
+
+protected:
+ // Common constructor to handle common members.
+ SkPDFFont(SkAdvancedTypefaceMetrics* fontInfo, SkTypeface* typeface,
+ uint16_t glyphID, bool descendantFont);
+
+ // Accessors for subclass.
+ SkAdvancedTypefaceMetrics* fontInfo();
+ uint16_t firstGlyphID() const;
+ uint16_t lastGlyphID() const;
+ void setLastGlyphID(uint16_t glyphID);
+
+ // Add object to resource list.
+ void addResource(SkPDFObject* object);
+
+ // Accessors for FontDescriptor associated with this object.
+ SkPDFDict* getFontDescriptor();
+ void setFontDescriptor(SkPDFDict* descriptor);
+
+ // Add common entries to FontDescriptor.
+ bool addCommonFontDescriptorEntries(int16_t defaultWidth);
+
+ /** Set fFirstGlyphID and fLastGlyphID to span at most 255 glyphs,
+ * including the passed glyphID.
+ */
+ void adjustGlyphRangeForSingleByteEncoding(int16_t glyphID);
+
+ // Generate ToUnicode table according to glyph usage subset.
+ // If subset is NULL, all available glyph ids will be used.
+ void populateToUnicodeTable(const SkPDFGlyphSet* subset);
+
+ // Create instances of derived types based on fontInfo.
+ static SkPDFFont* Create(SkAdvancedTypefaceMetrics* fontInfo,
+ SkTypeface* typeface, uint16_t glyphID,
+ SkPDFDict* fontDescriptor);
+
+ static bool Find(uint32_t fontID, uint16_t glyphID, int* index);
+
private:
+ class FontRec {
+ public:
+ SkPDFFont* fFont;
+ uint32_t fFontID;
+ uint16_t fGlyphID;
+
+ // A fGlyphID of 0 with no fFont always matches.
+ bool operator==(const FontRec& b) const;
+ FontRec(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID);
+ };
+
SkRefPtr<SkTypeface> fTypeface;
- SkAdvancedTypefaceMetrics::FontType fType;
-#ifdef SK_DEBUG
- bool fDescendant;
-#endif
- bool fMultiByteGlyphs;
// The glyph IDs accessible with this font. For Type1 (non CID) fonts,
// this will be a subset if the font has more than 255 glyphs.
@@ -94,58 +197,11 @@ private:
SkTDArray<SkPDFObject*> fResources;
SkRefPtr<SkPDFDict> fDescriptor;
- class FontRec {
- public:
- SkPDFFont* fFont;
- uint32_t fFontID;
- uint16_t fGlyphID;
-
- // A fGlyphID of 0 with no fFont always matches.
- bool operator==(const FontRec& b) const;
- FontRec(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID);
- };
+ SkAdvancedTypefaceMetrics::FontType fFontType;
// This should be made a hash table if performance is a problem.
static SkTDArray<FontRec>& CanonicalFonts();
static SkMutex& CanonicalFontsMutex();
-
- /** Construct a new font dictionary and support objects.
- * @param fontInfo Information about the to create.
- * @param typeface The typeface for the font.
- * @param glyphID The glyph ID the caller is interested in. This
- * is important only for Type1 fonts, which have
- * more than 255 glyphs.
- * @param descendantFont If this is the descendant (true) or root
- * (Type 0 font - false) font dictionary. Only True
- * Type and CID encoded fonts will use a true value.
- * @param fontDescriptor If the font descriptor has already have generated
- * for this font, pass it in here, otherwise pass
- * NULL.
- */
- SkPDFFont(class SkAdvancedTypefaceMetrics* fontInfo, SkTypeface* typeface,
- uint16_t glyphID, bool descendantFont, SkPDFDict* fontDescriptor);
-
- void populateType0Font();
- void populateCIDFont();
- bool populateType1Font(int16_t glyphID);
-
- /** Populate the PDF font dictionary as Type3 font which includes glyph
- * descriptions with instructions for painting the glyphs. This function
- * doesn't use any fields from SkAdvancedTypefaceMetrics (fFontInfo). Font
- * information including glyph paths are queried from the platform
- * dependent SkGlyphCache.
- */
- void populateType3Font(int16_t glyphID);
- bool addFontDescriptor(int16_t defaultWidth);
- void populateToUnicodeTable();
- void addWidthInfoFromRange(int16_t defaultWidth,
- const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry);
- /** Set fFirstGlyphID and fLastGlyphID to span at most 255 glyphs,
- * including the passed glyphID.
- */
- void adjustGlyphRangeForSingleByteEncoding(int16_t glyphID);
-
- static bool Find(uint32_t fontID, uint16_t glyphID, int* index);
};
#endif
diff --git a/include/pdf/SkPDFPage.h b/include/pdf/SkPDFPage.h
index a3978744e7..7a9505bbed 100644
--- a/include/pdf/SkPDFPage.h
+++ b/include/pdf/SkPDFPage.h
@@ -90,6 +90,11 @@ public:
*/
SK_API const SkTDArray<SkPDFFont*>& getFontResources() const;
+ /** Returns a SkPDFGlyphSetMap which represents glyph usage of every font
+ * that shows on this page.
+ */
+ const SkPDFGlyphSetMap& getFontGlyphUsage() const;
+
private:
// Multiple pages may reference the content.
SkRefPtr<SkPDFDevice> fDevice;