PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
/*
|
2011-01-25 21:01:34 +00:00
|
|
|
* Copyright (C) 2011 Google Inc.
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkPDFFont_DEFINED
|
|
|
|
#define SkPDFFont_DEFINED
|
|
|
|
|
2011-03-04 21:43:27 +00:00
|
|
|
#include "SkAdvancedTypefaceMetrics.h"
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
#include "SkPDFTypes.h"
|
|
|
|
#include "SkTDArray.h"
|
|
|
|
#include "SkThread.h"
|
|
|
|
|
|
|
|
class SkPaint;
|
|
|
|
|
|
|
|
/** \class SkPDFFont
|
|
|
|
A PDF Object class representing a font. The font may have resources
|
|
|
|
attached to it in order to embed the font. SkPDFFonts are canonicalized
|
|
|
|
so that resource deduplication will only include one copy of a font.
|
|
|
|
This class uses the same pattern as SkPDFGraphicState, a static weak
|
|
|
|
reference to each instantiated class.
|
|
|
|
*/
|
|
|
|
class SkPDFFont : public SkPDFDict {
|
|
|
|
public:
|
|
|
|
virtual ~SkPDFFont();
|
|
|
|
|
|
|
|
virtual void getResources(SkTDArray<SkPDFObject*>* resourceList);
|
|
|
|
|
2011-03-04 21:43:27 +00:00
|
|
|
/** Returns the typeface represented by this class. Returns NULL for the
|
|
|
|
* default typeface.
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
*/
|
2011-03-04 21:43:27 +00:00
|
|
|
SkTypeface* typeface();
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
|
2011-05-29 05:55:42 +00:00
|
|
|
/** Returns the font type represented in this font. For Type0 fonts,
|
|
|
|
* returns the type of the decendant font.
|
|
|
|
*/
|
|
|
|
SkAdvancedTypefaceMetrics::FontType getType();
|
|
|
|
|
2011-01-25 21:01:34 +00:00
|
|
|
/** Return true if this font has an encoding for the passed glyph id.
|
|
|
|
*/
|
|
|
|
bool hasGlyph(uint16_t glyphID);
|
|
|
|
|
|
|
|
/** Returns true if this font encoding supports glyph IDs above 255.
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
*/
|
|
|
|
bool multiByteGlyphs();
|
|
|
|
|
2011-02-28 19:52:18 +00:00
|
|
|
/** 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
|
|
|
|
* than 255 glyphs) this method only converts up to the first out of range
|
2011-01-25 21:01:34 +00:00
|
|
|
* glyph ID.
|
|
|
|
* @param glyphIDs The input text as glyph IDs.
|
|
|
|
* @param numGlyphs The number of input glyphs.
|
|
|
|
* @return Returns the number of glyphs consumed.
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
*/
|
2011-02-28 19:52:18 +00:00
|
|
|
size_t glyphsToPDFFontEncoding(uint16_t* glyphIDs, size_t numGlyphs);
|
2011-01-25 21:01:34 +00:00
|
|
|
|
2011-03-04 21:43:27 +00:00
|
|
|
/** Get the font resource for the passed typeface and glyphID. The
|
2011-01-25 21:01:34 +00:00
|
|
|
* reference count of the object is incremented and it is the caller's
|
|
|
|
* responsibility to unreference it when done. This is needed to
|
|
|
|
* accommodate the weak reference pattern used when the returned object
|
|
|
|
* is new and has no other references.
|
2011-03-04 21:43:27 +00:00
|
|
|
* @param typeface The typeface to find.
|
|
|
|
* @param glyphID Specify which section of a large font is of interest.
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
*/
|
2011-03-04 21:43:27 +00:00
|
|
|
static SkPDFFont* getFontResource(SkTypeface* typeface, uint16_t glyphID);
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
|
|
|
|
private:
|
2011-03-04 21:43:27 +00:00
|
|
|
SkRefPtr<SkTypeface> fTypeface;
|
2011-05-29 05:55:42 +00:00
|
|
|
SkAdvancedTypefaceMetrics::FontType fType;
|
2011-01-25 21:01:34 +00:00
|
|
|
#ifdef SK_DEBUG
|
|
|
|
bool fDescendant;
|
|
|
|
#endif
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
bool fMultiByteGlyphs;
|
|
|
|
|
2011-01-25 21:01:34 +00:00
|
|
|
// 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.
|
|
|
|
uint16_t fFirstGlyphID;
|
|
|
|
uint16_t fLastGlyphID;
|
|
|
|
// The font info is only kept around after construction for large
|
|
|
|
// Type1 (non CID) fonts that need multiple "fonts" to access all glyphs.
|
2011-02-02 02:11:22 +00:00
|
|
|
SkRefPtr<SkAdvancedTypefaceMetrics> fFontInfo;
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
SkTDArray<SkPDFObject*> fResources;
|
2011-01-25 21:01:34 +00:00
|
|
|
SkRefPtr<SkPDFDict> fDescriptor;
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
|
|
|
|
class FontRec {
|
|
|
|
public:
|
|
|
|
SkPDFFont* fFont;
|
|
|
|
uint32_t fFontID;
|
2011-01-25 21:01:34 +00:00
|
|
|
uint16_t fGlyphID;
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
|
2011-01-25 21:01:34 +00:00
|
|
|
// A fGlyphID of 0 with no fFont always matches.
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
bool operator==(const FontRec& b) const;
|
2011-01-25 21:01:34 +00:00
|
|
|
FontRec(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID);
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// This should be made a hash table if performance is a problem.
|
|
|
|
static SkTDArray<FontRec>& canonicalFonts();
|
|
|
|
static SkMutex& canonicalFontsMutex();
|
|
|
|
|
2011-01-25 21:01:34 +00:00
|
|
|
/** Construct a new font dictionary and support objects.
|
|
|
|
* @param fontInfo Information about the to create.
|
2011-03-04 21:43:27 +00:00
|
|
|
* @param typeface The typeface for the font.
|
2011-01-25 21:01:34 +00:00
|
|
|
* @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.
|
|
|
|
*/
|
2011-03-04 21:43:27 +00:00
|
|
|
SkPDFFont(class SkAdvancedTypefaceMetrics* fontInfo, SkTypeface* typeface,
|
2011-01-25 21:01:34 +00:00
|
|
|
uint16_t glyphID, bool descendantFont, SkPDFDict* fontDescriptor);
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
|
2011-01-25 21:01:34 +00:00
|
|
|
void populateType0Font();
|
|
|
|
void populateCIDFont();
|
2011-03-10 22:50:28 +00:00
|
|
|
bool populateType1Font(int16_t glyphID);
|
2011-03-04 21:43:27 +00:00
|
|
|
|
|
|
|
/** 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.
|
|
|
|
*/
|
2011-03-10 22:50:28 +00:00
|
|
|
void populateType3Font(int16_t glyphID);
|
2011-02-02 02:11:22 +00:00
|
|
|
bool addFontDescriptor(int16_t defaultWidth);
|
2011-05-09 18:13:47 +00:00
|
|
|
void populateToUnicodeTable();
|
2011-03-04 21:43:27 +00:00
|
|
|
void addWidthInfoFromRange(int16_t defaultWidth,
|
|
|
|
const SkAdvancedTypefaceMetrics::WidthRange* widthRangeEntry);
|
2011-03-10 22:50:28 +00:00
|
|
|
/** Set fFirstGlyphID and fLastGlyphID to span at most 255 glyphs,
|
|
|
|
* including the passed glyphID.
|
|
|
|
*/
|
|
|
|
void adjustGlyphRangeForSingleByteEncoding(int16_t glyphID);
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
|
2011-01-25 21:01:34 +00:00
|
|
|
static bool find(uint32_t fontID, uint16_t glyphID, int* index);
|
PDF: Add text support with a font framework (font embedding to come).
Supports fakeBold, underline, strikethrough, mode (fill, stroke, both), size, skew, alignment (left, center, right).
Missing is drawFontOnPath and font lookup and embedding.
Changed SkPDFString to support how it is used from drawText methods.
Moved compile assert into SkTypes.
Moved constants and utility function used to support fakeBold, underline, and strikethrough into higher level locations.
Review URL: http://codereview.appspot.com/2946041
git-svn-id: http://skia.googlecode.com/svn/trunk@624 2bbb7eff-a529-9590-31e7-b0007b416f81
2010-11-11 21:37:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|