2013-06-21 21:43:09 +00:00
|
|
|
#ifndef __DEFINED__SkPdfFont
|
|
|
|
#define __DEFINED__SkPdfFont
|
|
|
|
|
|
|
|
#include "SkPdfHeaders_autogen.h"
|
2013-07-02 22:42:53 +00:00
|
|
|
#include "SkPdfMapper_autogen.h"
|
2013-06-21 21:43:09 +00:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2013-06-26 17:48:12 +00:00
|
|
|
#include "SkTypeface.h"
|
2013-06-21 21:43:09 +00:00
|
|
|
#include "SkUtils.h"
|
2013-06-25 20:45:40 +00:00
|
|
|
#include "SkPdfBasics.h"
|
|
|
|
#include "SkPdfUtils.h"
|
|
|
|
|
2013-06-21 21:43:09 +00:00
|
|
|
|
|
|
|
class SkPdfType0Font;
|
|
|
|
class SkPdfType1Font;
|
|
|
|
class SkPdfType3Font;
|
|
|
|
class SkPdfTrueTypeFont;
|
|
|
|
class SkPdfMultiMasterFont;
|
|
|
|
class SkPdfFont;
|
|
|
|
|
|
|
|
struct SkPdfStandardFontEntry {
|
2013-07-10 17:44:55 +00:00
|
|
|
// We don't own this pointer!
|
2013-06-21 21:43:09 +00:00
|
|
|
const char* fName;
|
|
|
|
bool fIsBold;
|
|
|
|
bool fIsItalic;
|
2013-07-10 17:44:55 +00:00
|
|
|
SkPdfStandardFontEntry()
|
|
|
|
: fName(NULL),
|
|
|
|
fIsBold(false),
|
|
|
|
fIsItalic(false) {}
|
|
|
|
|
|
|
|
SkPdfStandardFontEntry(const char* name, bool bold, bool italic)
|
|
|
|
: fName(name),
|
|
|
|
fIsBold(bold),
|
|
|
|
fIsItalic(italic) {}
|
2013-06-21 21:43:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts();
|
|
|
|
SkTypeface* SkTypefaceFromPdfStandardFont(const char* fontName, bool bold, bool italic);
|
2013-07-10 17:09:50 +00:00
|
|
|
SkPdfFont* fontFromName(SkNativeParsedPDF* doc, SkPdfObject* obj, const char* fontName);
|
2013-06-21 21:43:09 +00:00
|
|
|
|
|
|
|
struct SkUnencodedText {
|
|
|
|
void* text;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
public:
|
2013-07-02 22:42:53 +00:00
|
|
|
SkUnencodedText(const SkPdfString* obj) {
|
|
|
|
text = (void*)obj->c_str();
|
|
|
|
len = obj->len();
|
2013-06-21 21:43:09 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SkDecodedText {
|
|
|
|
uint16_t* text;
|
|
|
|
int len;
|
2013-06-25 20:45:40 +00:00
|
|
|
public:
|
|
|
|
unsigned int operator[](int i) const { return text[i]; }
|
|
|
|
int size() const { return len; }
|
2013-06-21 21:43:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SkUnicodeText {
|
|
|
|
uint16_t* text;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
public:
|
|
|
|
unsigned int operator[](int i) const { return text[i]; }
|
|
|
|
int size() const { return len; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class SkPdfEncoding {
|
|
|
|
public:
|
|
|
|
virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOut) const = 0;
|
2013-06-25 20:45:40 +00:00
|
|
|
static SkPdfEncoding* fromName(const char* name);
|
|
|
|
};
|
|
|
|
|
|
|
|
std::map<std::string, SkPdfEncoding*>& getStandardEncodings();
|
|
|
|
|
|
|
|
class SkPdfToUnicode {
|
2013-07-10 17:09:50 +00:00
|
|
|
SkNativeParsedPDF* fParsed;
|
2013-06-25 20:45:40 +00:00
|
|
|
// TODO(edisonn): hide public members
|
|
|
|
public:
|
|
|
|
unsigned short* fCMapEncoding;
|
|
|
|
unsigned char* fCMapEncodingFlag;
|
|
|
|
|
2013-07-10 17:09:50 +00:00
|
|
|
SkPdfToUnicode(SkNativeParsedPDF* parsed, SkPdfStream* stream);
|
2013-06-21 21:43:09 +00:00
|
|
|
};
|
|
|
|
|
2013-06-25 20:45:40 +00:00
|
|
|
|
2013-06-21 21:43:09 +00:00
|
|
|
class SkPdfIdentityHEncoding : public SkPdfEncoding {
|
|
|
|
public:
|
|
|
|
virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOut) const {
|
|
|
|
// TODO(edisonn): SkASSERT(textIn.len % 2 == 0); or report error?
|
|
|
|
|
|
|
|
uint16_t* text = (uint16_t*)textIn.text;
|
|
|
|
textOut->text = new uint16_t[textIn.len / 2];
|
|
|
|
textOut->len = textIn.len / 2;
|
|
|
|
|
|
|
|
for (int i = 0; i < textOut->len; i++) {
|
|
|
|
textOut->text[i] = ((text[i] << 8) & 0xff00) | ((text[i] >> 8) & 0x00ff);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkPdfIdentityHEncoding* instance() {
|
|
|
|
static SkPdfIdentityHEncoding* inst = new SkPdfIdentityHEncoding();
|
|
|
|
return inst;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-27 20:03:43 +00:00
|
|
|
// TODO(edisonn): using this one when no encoding is specified
|
|
|
|
class SkPdfDefaultEncoding : public SkPdfEncoding {
|
|
|
|
public:
|
|
|
|
virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOut) const {
|
|
|
|
// TODO(edisonn): SkASSERT(textIn.len % 2 == 0); or report error?
|
|
|
|
|
|
|
|
unsigned char* text = (unsigned char*)textIn.text;
|
|
|
|
textOut->text = new uint16_t[textIn.len];
|
|
|
|
textOut->len = textIn.len;
|
|
|
|
|
|
|
|
for (int i = 0; i < textOut->len; i++) {
|
|
|
|
textOut->text[i] = text[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkPdfDefaultEncoding* instance() {
|
|
|
|
static SkPdfDefaultEncoding* inst = new SkPdfDefaultEncoding();
|
|
|
|
return inst;
|
|
|
|
}
|
|
|
|
};
|
2013-06-25 20:45:40 +00:00
|
|
|
|
|
|
|
class SkPdfCIDToGIDMapIdentityEncoding : public SkPdfEncoding {
|
|
|
|
public:
|
|
|
|
virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOut) const {
|
|
|
|
// TODO(edisonn): SkASSERT(textIn.len % 2 == 0); or report error?
|
|
|
|
|
2013-07-10 17:09:50 +00:00
|
|
|
uint16_t* text = (uint16_t*)textIn.text;
|
|
|
|
textOut->text = new uint16_t[textIn.len / 2];
|
|
|
|
textOut->len = textIn.len / 2;
|
2013-06-25 20:45:40 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < textOut->len; i++) {
|
2013-07-10 17:09:50 +00:00
|
|
|
textOut->text[i] = ((text[i] << 8) & 0xff00) | ((text[i] >> 8) & 0x00ff);
|
2013-06-25 20:45:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkPdfCIDToGIDMapIdentityEncoding* instance() {
|
|
|
|
static SkPdfCIDToGIDMapIdentityEncoding* inst = new SkPdfCIDToGIDMapIdentityEncoding();
|
|
|
|
return inst;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-21 21:43:09 +00:00
|
|
|
class SkPdfFont {
|
|
|
|
public:
|
|
|
|
SkPdfFont* fBaseFont;
|
|
|
|
SkPdfEncoding* fEncoding;
|
2013-06-25 20:45:40 +00:00
|
|
|
SkPdfToUnicode* fToUnicode;
|
|
|
|
|
2013-06-21 21:43:09 +00:00
|
|
|
|
|
|
|
public:
|
2013-06-27 20:03:43 +00:00
|
|
|
SkPdfFont() : fBaseFont(NULL), fEncoding(SkPdfDefaultEncoding::instance()), fToUnicode(NULL) {}
|
2013-06-21 21:43:09 +00:00
|
|
|
|
|
|
|
const SkPdfEncoding* encoding() const {return fEncoding;}
|
|
|
|
|
2013-06-27 20:03:43 +00:00
|
|
|
void drawText(const SkDecodedText& text, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
|
2013-06-21 21:43:09 +00:00
|
|
|
for (int i = 0 ; i < text.size(); i++) {
|
2013-06-27 20:03:43 +00:00
|
|
|
double width = drawOneChar(text[i], paint, pdfContext, canvas);
|
|
|
|
pdfContext->fGraphicsState.fMatrixTm.preTranslate(SkDoubleToScalar(width), SkDoubleToScalar(0.0));
|
|
|
|
canvas->translate(SkDoubleToScalar(width), SkDoubleToScalar(0.0));
|
2013-06-21 21:43:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-25 20:45:40 +00:00
|
|
|
void ToUnicode(const SkDecodedText& textIn, SkUnicodeText* textOut) const {
|
|
|
|
if (fToUnicode) {
|
|
|
|
textOut->text = new uint16_t[textIn.len];
|
|
|
|
textOut->len = textIn.len;
|
|
|
|
for (int i = 0; i < textIn.len; i++) {
|
|
|
|
textOut->text[i] = fToUnicode->fCMapEncoding[textIn.text[i]];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
textOut->text = textIn.text;
|
|
|
|
textOut->len = textIn.len;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
inline unsigned int ToUnicode(unsigned int ch) const {
|
|
|
|
if (fToUnicode) {
|
|
|
|
return fToUnicode->fCMapEncoding[ch];
|
|
|
|
} else {
|
|
|
|
return ch;
|
|
|
|
}
|
2013-06-21 21:43:09 +00:00
|
|
|
};
|
|
|
|
|
2013-07-10 17:09:50 +00:00
|
|
|
static SkPdfFont* fontFromPdfDictionary(SkNativeParsedPDF* doc, SkPdfFontDictionary* dict);
|
|
|
|
static SkPdfFont* Default() {return fontFromName(NULL, NULL, "TimesNewRoman");}
|
2013-06-21 21:43:09 +00:00
|
|
|
|
2013-07-10 17:09:50 +00:00
|
|
|
static SkPdfType0Font* fontFromType0FontDictionary(SkNativeParsedPDF* doc, SkPdfType0FontDictionary* dict);
|
|
|
|
static SkPdfType1Font* fontFromType1FontDictionary(SkNativeParsedPDF* doc, SkPdfType1FontDictionary* dict);
|
|
|
|
static SkPdfType3Font* fontFromType3FontDictionary(SkNativeParsedPDF* doc, SkPdfType3FontDictionary* dict);
|
|
|
|
static SkPdfTrueTypeFont* fontFromTrueTypeFontDictionary(SkNativeParsedPDF* doc, SkPdfTrueTypeFontDictionary* dict);
|
|
|
|
static SkPdfMultiMasterFont* fontFromMultiMasterFontDictionary(SkNativeParsedPDF* doc, SkPdfMultiMasterFontDictionary* dict);
|
2013-06-21 21:43:09 +00:00
|
|
|
|
2013-07-10 17:09:50 +00:00
|
|
|
static SkPdfFont* fontFromFontDescriptor(SkNativeParsedPDF* doc, SkPdfFontDescriptorDictionary* fd, bool loadFromName = true);
|
2013-06-27 20:03:43 +00:00
|
|
|
|
2013-06-21 21:43:09 +00:00
|
|
|
public:
|
2013-06-27 20:03:43 +00:00
|
|
|
virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) = 0;
|
2013-06-21 21:43:09 +00:00
|
|
|
virtual void afterWord(SkPaint* paint, SkMatrix* matrix) = 0;
|
2013-07-10 17:09:50 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static SkPdfFont* fontFromPdfDictionaryOnce(SkNativeParsedPDF* doc, SkPdfFontDictionary* dict);
|
2013-06-21 21:43:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SkPdfStandardFont : public SkPdfFont {
|
|
|
|
SkTypeface* fTypeface;
|
|
|
|
|
|
|
|
public:
|
|
|
|
SkPdfStandardFont(SkTypeface* typeface) : fTypeface(typeface) {}
|
|
|
|
|
|
|
|
public:
|
2013-06-27 20:03:43 +00:00
|
|
|
virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
|
2013-06-21 21:43:09 +00:00
|
|
|
paint->setTypeface(fTypeface);
|
|
|
|
paint->setTextEncoding(SkPaint::kUTF8_TextEncoding);
|
|
|
|
|
|
|
|
unsigned long ch4 = ch;
|
|
|
|
char utf8[10];
|
|
|
|
int len = SkUTF8_FromUnichar(ch4, utf8);
|
|
|
|
|
|
|
|
canvas->drawText(utf8, len, SkDoubleToScalar(0), SkDoubleToScalar(0), *paint);
|
|
|
|
|
|
|
|
SkScalar textWidth = paint->measureText(utf8, len);
|
2013-06-27 20:03:43 +00:00
|
|
|
return SkScalarToDouble(textWidth);
|
2013-06-21 21:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class SkPdfType0Font : public SkPdfFont {
|
|
|
|
public:
|
2013-07-10 17:09:50 +00:00
|
|
|
SkPdfType0Font(SkNativeParsedPDF* doc, SkPdfType0FontDictionary* dict);
|
2013-06-21 21:43:09 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2013-06-27 20:03:43 +00:00
|
|
|
virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
|
|
|
|
return fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas);
|
2013-06-21 21:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class SkPdfType1Font : public SkPdfFont {
|
|
|
|
public:
|
2013-07-10 17:09:50 +00:00
|
|
|
SkPdfType1Font(SkNativeParsedPDF* doc, SkPdfType1FontDictionary* dict) {
|
2013-06-27 20:03:43 +00:00
|
|
|
if (dict->has_FontDescriptor()) {
|
2013-07-10 17:09:50 +00:00
|
|
|
fBaseFont = SkPdfFont::fontFromFontDescriptor(doc, dict->FontDescriptor(doc));
|
2013-06-27 20:03:43 +00:00
|
|
|
} else {
|
2013-07-10 17:09:50 +00:00
|
|
|
fBaseFont = fontFromName(doc, dict, dict->BaseFont(doc).c_str());
|
2013-06-27 20:03:43 +00:00
|
|
|
}
|
2013-06-21 21:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2013-06-27 20:03:43 +00:00
|
|
|
virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
|
|
|
|
return fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas);
|
2013-06-21 21:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-06-27 20:03:43 +00:00
|
|
|
class SkPdfTrueTypeFont : public SkPdfType1Font {
|
2013-06-21 21:43:09 +00:00
|
|
|
public:
|
2013-07-10 17:09:50 +00:00
|
|
|
SkPdfTrueTypeFont(SkNativeParsedPDF* doc, SkPdfTrueTypeFontDictionary* dict) : SkPdfType1Font(doc, dict) {
|
2013-06-21 21:43:09 +00:00
|
|
|
}
|
2013-06-27 20:03:43 +00:00
|
|
|
};
|
2013-06-21 21:43:09 +00:00
|
|
|
|
2013-06-27 20:03:43 +00:00
|
|
|
class SkPdfMultiMasterFont : public SkPdfType1Font {
|
2013-06-21 21:43:09 +00:00
|
|
|
public:
|
2013-07-10 17:09:50 +00:00
|
|
|
SkPdfMultiMasterFont(SkNativeParsedPDF* doc, SkPdfMultiMasterFontDictionary* dict) : SkPdfType1Font(doc, dict) {
|
2013-06-21 21:43:09 +00:00
|
|
|
}
|
|
|
|
};
|
2013-06-25 20:45:40 +00:00
|
|
|
/*
|
|
|
|
class CIDToGIDMap {
|
|
|
|
virtual unsigned int map(unsigned int cid) = 0;
|
|
|
|
static CIDToGIDMap* fromName(const char* name);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CIDToGIDMap_Identity {
|
|
|
|
virtual unsigned int map(unsigned int cid) { return cid; }
|
|
|
|
|
|
|
|
static CIDToGIDMap_Identity* instance() {
|
|
|
|
static CIDToGIDMap_Identity* inst = new CIDToGIDMap_Identity();
|
|
|
|
return inst;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
CIDToGIDMap* CIDToGIDMap::fromName(const char* name) {
|
|
|
|
// The only one supported right now is Identity
|
|
|
|
if (strcmp(name, "Identity") == 0) {
|
|
|
|
return CIDToGIDMap_Identity::instance();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef PDF_TRACE
|
|
|
|
// TODO(edisonn): warning/report
|
|
|
|
printf("Unknown CIDToGIDMap: %s\n", name);
|
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
CIDToGIDMap* fCidToGid;
|
|
|
|
*/
|
2013-06-21 21:43:09 +00:00
|
|
|
|
|
|
|
class SkPdfType3Font : public SkPdfFont {
|
2013-06-25 20:45:40 +00:00
|
|
|
struct Type3FontChar {
|
2013-07-10 17:09:50 +00:00
|
|
|
const SkPdfObject* fObj;
|
2013-06-25 20:45:40 +00:00
|
|
|
double fWidth;
|
|
|
|
};
|
|
|
|
|
|
|
|
SkPdfDictionary* fCharProcs;
|
|
|
|
SkPdfEncodingDictionary* fEncodingDict;
|
|
|
|
unsigned int fFirstChar;
|
|
|
|
unsigned int fLastChar;
|
|
|
|
|
|
|
|
SkRect fFontBBox;
|
|
|
|
SkMatrix fFonMatrix;
|
|
|
|
|
|
|
|
Type3FontChar* fChars;
|
|
|
|
|
2013-06-21 21:43:09 +00:00
|
|
|
public:
|
2013-07-10 17:09:50 +00:00
|
|
|
SkPdfType3Font(SkNativeParsedPDF* parsed, SkPdfType3FontDictionary* dict) {
|
|
|
|
fBaseFont = fontFromName(parsed, dict, dict->BaseFont(parsed).c_str());
|
2013-06-25 20:45:40 +00:00
|
|
|
|
|
|
|
if (dict->has_Encoding()) {
|
2013-07-10 17:09:50 +00:00
|
|
|
if (dict->isEncodingAName(parsed)) {
|
|
|
|
fEncoding = SkPdfEncoding::fromName(dict->getEncodingAsName(parsed).c_str());
|
|
|
|
} else if (dict->isEncodingAEncodingdictionary(parsed)) {
|
2013-07-23 19:43:48 +00:00
|
|
|
// No encoding.
|
|
|
|
fEncoding = SkPdfDefaultEncoding::instance();
|
2013-07-10 17:09:50 +00:00
|
|
|
fEncodingDict = dict->getEncodingAsEncodingdictionary(parsed);
|
2013-06-25 20:45:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// null?
|
2013-07-10 17:09:50 +00:00
|
|
|
fCharProcs = dict->CharProcs(parsed);
|
2013-06-25 20:45:40 +00:00
|
|
|
|
|
|
|
fToUnicode = NULL;
|
|
|
|
if (dict->has_ToUnicode()) {
|
2013-07-10 17:09:50 +00:00
|
|
|
fToUnicode = new SkPdfToUnicode(parsed, dict->ToUnicode(parsed));
|
2013-06-25 20:45:40 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 18:20:06 +00:00
|
|
|
fFirstChar = (unsigned int)dict->FirstChar(parsed);
|
|
|
|
fLastChar = (unsigned int)dict->LastChar(parsed);
|
2013-07-10 17:09:50 +00:00
|
|
|
fFonMatrix = dict->has_FontMatrix() ? dict->FontMatrix(parsed) : SkMatrix::I();
|
2013-06-25 20:45:40 +00:00
|
|
|
|
2013-07-10 17:09:50 +00:00
|
|
|
if (dict->has_FontBBox()) {
|
|
|
|
fFontBBox = dict->FontBBox(parsed);
|
2013-06-25 20:45:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fChars = new Type3FontChar[fLastChar - fFirstChar + 1];
|
|
|
|
|
|
|
|
memset(fChars, 0, sizeof(fChars[0]) * (fLastChar - fFirstChar + 1));
|
|
|
|
|
|
|
|
|
2013-07-10 17:09:50 +00:00
|
|
|
const SkPdfArray* widths = dict->Widths(parsed);
|
|
|
|
for (unsigned int i = 0 ; i < widths->size(); i++) {
|
2013-06-25 20:45:40 +00:00
|
|
|
if ((fFirstChar + i) < fFirstChar || (fFirstChar + i) > fLastChar) {
|
|
|
|
printf("break; error 1\n");
|
|
|
|
}
|
2013-07-10 17:09:50 +00:00
|
|
|
fChars[i].fWidth = (*widths)[i]->numberValue();
|
2013-06-25 20:45:40 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 17:09:50 +00:00
|
|
|
const SkPdfArray* diffs = fEncodingDict->Differences(parsed);
|
|
|
|
unsigned int j = fFirstChar;
|
|
|
|
for (unsigned int i = 0 ; i < diffs->size(); i++) {
|
|
|
|
if ((*diffs)[i]->isInteger()) {
|
2013-07-10 18:20:06 +00:00
|
|
|
j = (unsigned int)(*diffs)[i]->intValue();
|
2013-07-10 17:09:50 +00:00
|
|
|
} else if ((*diffs)[i]->isName()) {
|
2013-06-25 20:45:40 +00:00
|
|
|
if (j < fFirstChar || j > fLastChar) {
|
|
|
|
printf("break; error 2\n");
|
|
|
|
}
|
2013-07-23 19:43:48 +00:00
|
|
|
fChars[j - fFirstChar].fObj = fCharProcs->get((*diffs)[i]);
|
2013-06-25 20:45:40 +00:00
|
|
|
j++;
|
|
|
|
} else {
|
|
|
|
// err
|
|
|
|
}
|
|
|
|
}
|
2013-06-21 21:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2013-06-27 20:03:43 +00:00
|
|
|
virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
|
2013-06-25 20:45:40 +00:00
|
|
|
if (ch < fFirstChar || ch > fLastChar || !fChars[ch - fFirstChar].fObj) {
|
2013-06-27 20:03:43 +00:00
|
|
|
return fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas);
|
2013-06-25 20:45:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef PDF_TRACE
|
|
|
|
printf("Type 3 char to unicode: %c\n", ToUnicode(ch));
|
|
|
|
if (ToUnicode(ch) == 'A') {
|
|
|
|
printf("break;\n");
|
|
|
|
}
|
|
|
|
#endif
|
2013-06-21 21:43:09 +00:00
|
|
|
|
2013-07-10 17:09:50 +00:00
|
|
|
// TODO(edisonn): is it better to resolve the reference at load time, or now?
|
|
|
|
doType3Char(pdfContext, canvas, pdfContext->fPdfDoc->resolveReference(fChars[ch - fFirstChar].fObj), fFontBBox, fFonMatrix, pdfContext->fGraphicsState.fCurFontSize);
|
2013-06-21 21:43:09 +00:00
|
|
|
|
2013-06-27 20:03:43 +00:00
|
|
|
// TODO(edisonn): verify/test translate code, not tested yet
|
|
|
|
pdfContext->fGraphicsState.fMatrixTm.preTranslate(SkDoubleToScalar(pdfContext->fGraphicsState.fCurFontSize * fChars[ch - fFirstChar].fWidth),
|
|
|
|
SkDoubleToScalar(0.0));
|
2013-07-10 17:09:50 +00:00
|
|
|
return fChars[ch - fFirstChar].fWidth;
|
2013-06-21 21:43:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __DEFINED__SkPdfFont
|