diff options
author | 2013-06-21 21:43:09 +0000 | |
---|---|---|
committer | 2013-06-21 21:43:09 +0000 | |
commit | 1be794fad6bef2b1ab98158bd3ad68dc4a52dbf6 (patch) | |
tree | 5e2e0dbd82169ff4200f54e15c56cca75a5b6d73 | |
parent | ff27844d15da7e691d1b4c0adc57af64e108d9fa (diff) |
add missing font.* files, map podofo to SkPdfObject for SkPdfArray::operator[]
Review URL: https://codereview.chromium.org/17063014
git-svn-id: http://skia.googlecode.com/svn/trunk@9735 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | experimental/PdfViewer/SkPdfArray_autogen.h | 2 | ||||
-rw-r--r-- | experimental/PdfViewer/SkPdfFont.cpp | 320 | ||||
-rw-r--r-- | experimental/PdfViewer/SkPdfFont.h | 277 | ||||
-rw-r--r-- | experimental/PdfViewer/generate_code.py | 2 | ||||
-rw-r--r-- | experimental/PdfViewer/pdf_viewer_main.cpp | 6 |
5 files changed, 605 insertions, 2 deletions
diff --git a/experimental/PdfViewer/SkPdfArray_autogen.h b/experimental/PdfViewer/SkPdfArray_autogen.h index a153997f05..d9671eb64e 100644 --- a/experimental/PdfViewer/SkPdfArray_autogen.h +++ b/experimental/PdfViewer/SkPdfArray_autogen.h @@ -547,7 +547,7 @@ private: public: const int size() const {return fPodofoObj->GetArray().GetSize();} - SkPdfObject* operator[](int i) const {return new SkPdfObject(fPodofoDoc, &fPodofoObj->GetArray()[i]);} + SkPdfObject* operator[](int i) const { SkPdfObject* ret = NULL; skpdfmap(*fPodofoDoc, fPodofoObj->GetArray()[i], &ret); return ret; } private: public: SkPdfArray(const PdfMemDocument* podofoDoc = NULL, const PdfObject* podofoObj = NULL) : SkPdfObject(podofoDoc, podofoObj) {} diff --git a/experimental/PdfViewer/SkPdfFont.cpp b/experimental/PdfViewer/SkPdfFont.cpp new file mode 100644 index 0000000000..520c820f1b --- /dev/null +++ b/experimental/PdfViewer/SkPdfFont.cpp @@ -0,0 +1,320 @@ +#include "SkPdfFont.h" + +std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts() { + static std::map<std::string, SkPdfStandardFontEntry> gPdfStandardFonts; + + // TODO (edisonn): , vs - ? what does it mean? + // TODO (edisonn): MT, PS, Oblique=italic?, ... what does it mean? + if (gPdfStandardFonts.empty()) { + gPdfStandardFonts["Arial"] = {"Arial", false, false}; + gPdfStandardFonts["Arial,Bold"] = {"Arial", true, false}; + gPdfStandardFonts["Arial,BoldItalic"] = {"Arial", true, true}; + gPdfStandardFonts["Arial,Italic"] = {"Arial", false, true}; + gPdfStandardFonts["Arial-Bold"] = {"Arial", true, false}; + gPdfStandardFonts["Arial-BoldItalic"] = {"Arial", true, true}; + gPdfStandardFonts["Arial-BoldItalicMT"] = {"Arial", true, true}; + gPdfStandardFonts["Arial-BoldMT"] = {"Arial", true, false}; + gPdfStandardFonts["Arial-Italic"] = {"Arial", false, true}; + gPdfStandardFonts["Arial-ItalicMT"] = {"Arial", false, true}; + gPdfStandardFonts["ArialMT"] = {"Arial", false, false}; + gPdfStandardFonts["Courier"] = {"Courier New", false, false}; + gPdfStandardFonts["Courier,Bold"] = {"Courier New", true, false}; + gPdfStandardFonts["Courier,BoldItalic"] = {"Courier New", true, true}; + gPdfStandardFonts["Courier,Italic"] = {"Courier New", false, true}; + gPdfStandardFonts["Courier-Bold"] = {"Courier New", true, false}; + gPdfStandardFonts["Courier-BoldOblique"] = {"Courier New", true, true}; + gPdfStandardFonts["Courier-Oblique"] = {"Courier New", false, true}; + gPdfStandardFonts["CourierNew"] = {"Courier New", false, false}; + gPdfStandardFonts["CourierNew,Bold"] = {"Courier New", true, false}; + gPdfStandardFonts["CourierNew,BoldItalic"] = {"Courier New", true, true}; + gPdfStandardFonts["CourierNew,Italic"] = {"Courier New", false, true}; + gPdfStandardFonts["CourierNew-Bold"] = {"Courier New", true, false}; + gPdfStandardFonts["CourierNew-BoldItalic"] = {"Courier New", true, true}; + gPdfStandardFonts["CourierNew-Italic"] = {"Courier New", false, true}; + gPdfStandardFonts["CourierNewPS-BoldItalicMT"] = {"Courier New", true, true}; + gPdfStandardFonts["CourierNewPS-BoldMT"] = {"Courier New", true, false}; + gPdfStandardFonts["CourierNewPS-ItalicMT"] = {"Courier New", false, true}; + gPdfStandardFonts["CourierNewPSMT"] = {"Courier New", false, false}; + gPdfStandardFonts["Helvetica"] = {"Helvetica", false, false}; + gPdfStandardFonts["Helvetica,Bold"] = {"Helvetica", true, false}; + gPdfStandardFonts["Helvetica,BoldItalic"] = {"Helvetica", true, true}; + gPdfStandardFonts["Helvetica,Italic"] = {"Helvetica", false, true}; + gPdfStandardFonts["Helvetica-Bold"] = {"Helvetica", true, false}; + gPdfStandardFonts["Helvetica-BoldItalic"] = {"Helvetica", true, true}; + gPdfStandardFonts["Helvetica-BoldOblique"] = {"Helvetica", true, true}; + gPdfStandardFonts["Helvetica-Italic"] = {"Helvetica", false, true}; + gPdfStandardFonts["Helvetica-Oblique"] = {"Helvetica", false, true}; + gPdfStandardFonts["Times-Bold"] = {"Times New Roman", true, false}; + gPdfStandardFonts["Times-BoldItalic"] = {"Times New Roman", true, true}; + gPdfStandardFonts["Times-Italic"] = {"Times New Roman", false, true}; + gPdfStandardFonts["Times-Roman"] = {"Times New Roman", false, false}; + gPdfStandardFonts["TimesNewRoman"] = {"Times New Roman", false, false}; + gPdfStandardFonts["TimesNewRoman,Bold"] = {"Times New Roman", true, false}; + gPdfStandardFonts["TimesNewRoman,BoldItalic"] = {"Times New Roman", true, true}; + gPdfStandardFonts["TimesNewRoman,Italic"] = {"Times New Roman", false, true}; + gPdfStandardFonts["TimesNewRoman-Bold"] = {"Times New Roman", true, false}; + gPdfStandardFonts["TimesNewRoman-BoldItalic"] = {"Times New Roman", true, true}; + gPdfStandardFonts["TimesNewRoman-Italic"] = {"Times New Roman", false, true}; + gPdfStandardFonts["TimesNewRomanPS"] = {"Times New Roman", false, false}; + gPdfStandardFonts["TimesNewRomanPS-Bold"] = {"Times New Roman", true, false}; + gPdfStandardFonts["TimesNewRomanPS-BoldItalic"] = {"Times New Roman", true, true}; + gPdfStandardFonts["TimesNewRomanPS-BoldItalicMT"] = {"Times New Roman", true, true}; + gPdfStandardFonts["TimesNewRomanPS-BoldMT"] = {"Times New Roman", true, false}; + gPdfStandardFonts["TimesNewRomanPS-Italic"] = {"Times New Roman", false, true}; + gPdfStandardFonts["TimesNewRomanPS-ItalicMT"] = {"Times New Roman", false, true}; + gPdfStandardFonts["TimesNewRomanPSMT"] = {"Times New Roman", false, false}; + gPdfStandardFonts["Symbol"] = {"Symbol", false, false}; + gPdfStandardFonts["ZapfDingbats"] = {"ZapfDingbats", false, false}; + + // TODO(edisonn): these are hacks. Load Post Script font name. + // see FT_Get_Postscript_Name + // Font config is not using it, yet. + //https://bugs.freedesktop.org/show_bug.cgi?id=18095 + gPdfStandardFonts["Arial-Black"] = {"Arial", true, false}; + gPdfStandardFonts["DejaVuSans"] = {"DejaVu Sans", false, false}; + gPdfStandardFonts["DejaVuSansMono"] = {"DejaVuSans Mono", false, false}; + gPdfStandardFonts["DejaVuSansMono-Bold"] = {"DejaVuSans Mono", true, false}; + gPdfStandardFonts["DejaVuSansMono-Oblique"] = {"DejaVuSans Mono", false, true}; + gPdfStandardFonts["Georgia-Bold"] = {"Georgia", true, false}; + gPdfStandardFonts["Georgia-BoldItalic"] = {"Georgia", true, true}; + gPdfStandardFonts["Georgia-Italic"] = {"Georgia", false, true}; + gPdfStandardFonts["TrebuchetMS"] = {"Trebuchet MS", false, false}; + gPdfStandardFonts["TrebuchetMS-Bold"] = {"Trebuchet MS", true, false}; + gPdfStandardFonts["Verdana-Bold"] = {"Verdana", true, false}; + gPdfStandardFonts["WenQuanYiMicroHei"] = {"WenQuanYi Micro Hei", false, false}; + } + + return gPdfStandardFonts; +} + +SkTypeface* SkTypefaceFromPdfStandardFont(const char* fontName, bool bold, bool italic) { + std::map<std::string, SkPdfStandardFontEntry>& standardFontMap = getStandardFonts(); + + SkTypeface* typeface = NULL; + if (standardFontMap.find(fontName) != standardFontMap.end()) { + SkPdfStandardFontEntry fontData = standardFontMap[fontName]; + + // TODO(edisonn): How does the bold/italic specified in standard definition combines with + // the one in /font key? use OR for now. + bold = bold || fontData.fIsBold; + italic = italic || fontData.fIsItalic; + + typeface = SkTypeface::CreateFromName( + fontData.fName, + SkTypeface::Style((bold ? SkTypeface::kBold : 0) | + (italic ? SkTypeface::kItalic : 0))); + } else { + typeface = SkTypeface::CreateFromName( + fontName, + SkTypeface::kNormal); + } + + if (typeface) { + typeface->ref(); + } + return typeface; +} + +SkPdfFont* SkPdfFontFromName(SkPdfObject* obj, const char* fontName) { + SkTypeface* typeface = SkTypefaceFromPdfStandardFont(fontName, false, false); + if (typeface != NULL) { + return new SkPdfStandardFont(typeface); + } +// SkPdfObject* font = obtainFont(pdfContext, fontName); +// if (!font->asFontDictionary()) { +// return NULL; +// } +// SkPdfFont::fontFromPdfDictionary(font->asDictionary()); +// } + // TODO(edisonn): deal with inherited fonts, load from parent objects + return SkPdfFont::Default(); +} + +SkPdfFont* SkPdfFont::fontFromPdfDictionary(SkPdfFontDictionary* dict) { + if (dict == NULL) { + return NULL; // TODO(edisonn): report default one? + } + + switch (dict->getType()) { + case kType0FontDictionary_SkPdfObjectType: + return fontFromType0FontDictionary(dict->asType0FontDictionary()); + + case kTrueTypeFontDictionary_SkPdfObjectType: + return fontFromTrueTypeFontDictionary(dict->asTrueTypeFontDictionary()); + + case kType1FontDictionary_SkPdfObjectType: + return fontFromType1FontDictionary(dict->asType1FontDictionary()); + + case kCIDFontDictionary_SkPdfObjectType: + return fontFromCIDFontDictionary(dict->asCIDFontDictionary()); + + case kMultiMasterFontDictionary_SkPdfObjectType: + return fontFromMultiMasterFontDictionary(dict->asMultiMasterFontDictionary()); + + case kType3FontDictionary_SkPdfObjectType: + return fontFromType3FontDictionary(dict->asType3FontDictionary()); + } + return NULL; // TODO(edisonn): report error? +} + +SkPdfType0Font* SkPdfFont::fontFromType0FontDictionary(SkPdfType0FontDictionary* dict) { + if (dict == NULL) { + return NULL; // default one? + } + + return new SkPdfType0Font(dict); +} + +SkPdfType1Font* SkPdfFont:: fontFromType1FontDictionary(SkPdfType1FontDictionary* dict) { + if (dict == NULL) { + return NULL; // default one? + } + + return new SkPdfType1Font(dict); +} + +SkPdfType3Font* SkPdfFont::fontFromType3FontDictionary(SkPdfType3FontDictionary* dict) { + if (dict == NULL) { + return NULL; // default one? + } + + return new SkPdfType3Font(dict); +} + +SkPdfTrueTypeFont* SkPdfFont::fontFromTrueTypeFontDictionary(SkPdfTrueTypeFontDictionary* dict) { + if (dict == NULL) { + return NULL; // default one? + } + + return new SkPdfTrueTypeFont(dict); +} + +SkPdfCIDFont* SkPdfFont::fontFromCIDFontDictionary(SkPdfCIDFontDictionary* dict) { + if (dict == NULL) { + return NULL; // default one? + } + + return new SkPdfCIDFont(dict); +} + +SkPdfMultiMasterFont* SkPdfFont::fontFromMultiMasterFontDictionary(SkPdfMultiMasterFontDictionary* dict) { + if (dict == NULL) { + return NULL; // default one? + } + + return new SkPdfMultiMasterFont(dict); +} + +static int skstoi(const SkPdfString* str) { + int ret = 0; + for (int i = 0 ; i < str->podofo()->GetString().GetLength(); i++) { + ret = (ret << 8) + ((unsigned char*)str->podofo()->GetString().GetString())[i]; + } + return ret; +} + +SkPdfType0Font::SkPdfType0Font(SkPdfType0FontDictionary* dict) { + fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); + + // TODO(edisonn): load encoding, let it now to be Identity-H by default + if (dict->has_Encoding()) { + if (dict->isEncodingAName()) { + //report encoding not supported + //fEncoding = loadEncodingFromName(dict->getEncodingAsName().c_str()); + } else if (dict->isEncodingAStream()) { + //fEncoding = loadEncodingFromStream(dict->getEncodingAsStream()); + } else { + // error + } + } + + fCMapEncoding = NULL; + fCMapEncodingFlag = NULL; + + if (dict->has_ToUnicode()) { + const SkPdfStream* stream = dict->ToUnicode(); + SkPdfTokenizer tokenizer(stream); + PdfToken token; + + fCMapEncoding = new unsigned short[256 * 256]; + fCMapEncodingFlag = new unsigned char[256 * 256]; + for (int i = 0 ; i < 256 * 256; i++) { + fCMapEncoding[i] = i; + fCMapEncodingFlag[i] = 0; + } + + // TODO(edisonn): deal with multibyte character, or longer strings. + // Ritght now we deal with up 2 characters, e.g. <0020> but not longer like <00660066006C> + //2 beginbfrange + //<0000> <005E> <0020> + //<005F> <0061> [<00660066> <00660069> <00660066006C>] + + while (tokenizer.readToken(&token)) { + + if (token.fType == kKeyword_TokenType && strcmp(token.fKeyword, "begincodespacerange") == 0) { + while (tokenizer.readToken(&token) && !(token.fType == kKeyword_TokenType && strcmp(token.fKeyword, "endcodespacerange") == 0)) { +// tokenizer.PutBack(token); +// tokenizer.readToken(&token); + // TODO(edisonn): check token type! ignore/report errors. + int start = skstoi(token.fObject->asString()); + tokenizer.readToken(&token); + int end = skstoi(token.fObject->asString()); + for (int i = start; i <= end; i++) { + fCMapEncodingFlag[i] |= 1; + } + } + } + + if (token.fType == kKeyword_TokenType && strcmp(token.fKeyword, "beginbfchar") == 0) { + while (tokenizer.readToken(&token) && !(token.fType == kKeyword_TokenType && strcmp(token.fKeyword, "endbfchar") == 0)) { +// tokenizer.PutBack(token); +// tokenizer.readToken(&token); + int from = skstoi(token.fObject->asString()); + tokenizer.readToken(&token); + int to = skstoi(token.fObject->asString()); + + fCMapEncodingFlag[from] |= 2; + fCMapEncoding[from] = to; + } + } + + if (token.fType == kKeyword_TokenType && strcmp(token.fKeyword, "beginbfrange") == 0) { + while (tokenizer.readToken(&token) && !(token.fType == kKeyword_TokenType && strcmp(token.fKeyword, "endbfrange") == 0)) { +// tokenizer.PutBack(token); +// tokenizer.readToken(&token); + int start = skstoi(token.fObject->asString()); + tokenizer.readToken(&token); + int end = skstoi(token.fObject->asString()); + + + tokenizer.readToken(&token); // [ or just an array directly? +// tokenizer.PutBack(token); + + if (token.fType == kObject_TokenType && token.fObject->asString()) { +// tokenizer.readToken(&token); + int value = skstoi(token.fObject->asString()); + + for (int i = start; i <= end; i++) { + fCMapEncodingFlag[i] |= 2; + fCMapEncoding[i] = value; + value++; + // if i != end, verify last byte id not if, ignore/report error + } + + // read one string + } else if (token.fType == kObject_TokenType && token.fObject->asArray()) { +// tokenizer.readToken(&token); + for (int i = 0; i < token.fObject->asArray()->size(); i++) { + fCMapEncodingFlag[start + i] |= 2; + fCMapEncoding[start + i] = skstoi((*token.fObject->asArray())[i]->asString()); + } + // read array + } + + //fCMapEncodingFlag[from] = 1; + //fCMapEncoding[from] = to; + } + } + } + } +} diff --git a/experimental/PdfViewer/SkPdfFont.h b/experimental/PdfViewer/SkPdfFont.h new file mode 100644 index 0000000000..2ba6e7af68 --- /dev/null +++ b/experimental/PdfViewer/SkPdfFont.h @@ -0,0 +1,277 @@ +#ifndef __DEFINED__SkPdfFont +#define __DEFINED__SkPdfFont + +#include "SkPdfHeaders_autogen.h" +#include "SkPdfPodofoMapper_autogen.h" + +#include <map> +#include <string> + +#include "SkUtils.h" + +class SkPdfType0Font; +class SkPdfType1Font; +class SkPdfType3Font; +class SkPdfTrueTypeFont; +class SkPdfCIDFont; +class SkPdfMultiMasterFont; +class SkPdfFont; + + +struct SkPdfStandardFontEntry { + const char* fName; + bool fIsBold; + bool fIsItalic; +}; + +std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts(); +SkTypeface* SkTypefaceFromPdfStandardFont(const char* fontName, bool bold, bool italic); +SkPdfFont* SkPdfFontFromName(SkPdfObject* obj, const char* fontName); + +struct SkUnencodedText { + void* text; + int len; + +public: + SkUnencodedText(const SkPdfObject* obj) { + text = (void*)obj->podofo()->GetString().GetString(); + len = obj->podofo()->GetString().GetLength(); + } +}; + +struct SkDecodedText { + uint16_t* text; + int len; +}; + +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; +}; + +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; + } +}; + +class SkPdfFont { +public: + SkPdfFont* fBaseFont; + SkPdfEncoding* fEncoding; + +public: + SkPdfFont() : fBaseFont(NULL), fEncoding(SkPdfIdentityHEncoding::instance()) {} + + const SkPdfEncoding* encoding() const {return fEncoding;} + + void drawText(const SkUnicodeText& text, SkPaint* paint, SkCanvas* canvas, SkMatrix* matrix) { + for (int i = 0 ; i < text.size(); i++) { + drawOneChar(text[i], paint, canvas, matrix); + } + } + + virtual void ToUnicode(const SkDecodedText& textIn, SkUnicodeText* textOut) const { + textOut->text = textIn.text; + textOut->len = textIn.len; + }; + + static SkPdfFont* fontFromPdfDictionary(SkPdfFontDictionary* dict); + static SkPdfFont* Default() {return SkPdfFontFromName(NULL, "TimesNewRoman");} + + static SkPdfType0Font* fontFromType0FontDictionary(SkPdfType0FontDictionary* dict); + static SkPdfType1Font* fontFromType1FontDictionary(SkPdfType1FontDictionary* dict); + static SkPdfType3Font* fontFromType3FontDictionary(SkPdfType3FontDictionary* dict); + static SkPdfTrueTypeFont* fontFromTrueTypeFontDictionary(SkPdfTrueTypeFontDictionary* dict); + static SkPdfCIDFont* fontFromCIDFontDictionary(SkPdfCIDFontDictionary* dict); + static SkPdfMultiMasterFont* fontFromMultiMasterFontDictionary(SkPdfMultiMasterFontDictionary* dict); + +public: + virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas, SkMatrix* matrix) = 0; + virtual void afterChar(SkPaint* paint, SkMatrix* matrix) = 0; + virtual void afterWord(SkPaint* paint, SkMatrix* matrix) = 0; +}; + +class SkPdfStandardFont : public SkPdfFont { + SkTypeface* fTypeface; + +public: + SkPdfStandardFont(SkTypeface* typeface) : fTypeface(typeface) {} + +public: + virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas, SkMatrix* matrix) { + 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); + matrix->preTranslate(textWidth, SkDoubleToScalar(0.0)); + } + + virtual void afterChar(SkPaint* paint, SkMatrix* matrix) {} + virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {} +}; + + +class SkPdfType0Font : public SkPdfFont { + unsigned short* fCMapEncoding; + unsigned char* fCMapEncodingFlag; +public: + SkPdfType0Font(SkPdfType0FontDictionary* dict); + +public: + virtual void ToUnicode(const SkDecodedText& textIn, SkUnicodeText* textOut) const { + textOut->text = new uint16_t[textIn.len]; + textOut->len = textIn.len; + for (int i = 0; i < textIn.len; i++) { + textOut->text[i] = fCMapEncoding[textIn.text[i]]; + } + }; + + virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas, SkMatrix* matrix) { + fBaseFont->drawOneChar(ch, paint, canvas, matrix); + } + + virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { + + } + + virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { + + } +}; + +class SkPdfTrueTypeFont : public SkPdfFont { +public: + SkPdfTrueTypeFont(SkPdfTrueTypeFontDictionary* dict) { + fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); + } + +public: + virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas, SkMatrix* matrix) { + + } + + virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { + + } + + virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { + + } +}; + + +class SkPdfType1Font : public SkPdfFont { +public: + SkPdfType1Font(SkPdfType1FontDictionary* dict) { + fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); + } + + +public: + virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas, SkMatrix* matrix) { + + } + + virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { + + } + + virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { + + } + }; + + +class SkPdfCIDFont : public SkPdfFont { +public: + SkPdfCIDFont(SkPdfCIDFontDictionary* dict) { + fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); + } + +public: + virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas, SkMatrix* matrix) { + + } + + virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { + + } + + virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { + + } +}; + +class SkPdfMultiMasterFont : public SkPdfFont { +public: + SkPdfMultiMasterFont(SkPdfMultiMasterFontDictionary* dict) { + fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); + } + +public: + virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas, SkMatrix* matrix) { + + } + + virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { + + } + + virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { + + } +}; + +class SkPdfType3Font : public SkPdfFont { +public: + SkPdfType3Font(SkPdfType3FontDictionary* dict) { + fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str()); + } + +public: + virtual void drawOneChar(unsigned int ch, SkPaint* paint, SkCanvas* canvas, SkMatrix* matrix) { + + } + + virtual void afterChar(SkPaint* paint, SkMatrix* matrix) { + + } + + virtual void afterWord(SkPaint* paint, SkMatrix* matrix) { + + } +}; + +#endif // __DEFINED__SkPdfFont diff --git a/experimental/PdfViewer/generate_code.py b/experimental/PdfViewer/generate_code.py index 6c78937fb8..f128e444ca 100644 --- a/experimental/PdfViewer/generate_code.py +++ b/experimental/PdfViewer/generate_code.py @@ -526,7 +526,7 @@ def generateCode(): manager.addClass('Array').check('podofoObj.GetDataType() == ePdfDataType_Array')\ .carbonCopyPublic('const int size() const {return fPodofoObj->GetArray().GetSize();}')\ - .carbonCopyPublic('SkPdfObject* operator[](int i) const {return new SkPdfObject(fPodofoDoc, &fPodofoObj->GetArray()[i]);}')\ + .carbonCopyPublic('SkPdfObject* operator[](int i) const { SkPdfObject* ret = NULL; skpdfmap(*fPodofoDoc, fPodofoObj->GetArray()[i], &ret); return ret; }')\ manager.addClass('String').check('podofoObj.GetDataType() == ePdfDataType_String || podofoObj.GetDataType() == ePdfDataType_HexString')\ .carbonCopyPublic('const std::string& value() const {return fPodofoObj->GetString().GetStringUtf8();}') diff --git a/experimental/PdfViewer/pdf_viewer_main.cpp b/experimental/PdfViewer/pdf_viewer_main.cpp index 39d93ef9a0..877849eff4 100644 --- a/experimental/PdfViewer/pdf_viewer_main.cpp +++ b/experimental/PdfViewer/pdf_viewer_main.cpp @@ -143,6 +143,7 @@ bool FunctionFromDictionary(const PdfMemDocument* pdfDoc, const char* abr, SkPdfFunction* data); +bool skpdfmap(const PdfMemDocument& podofoDoc, const PdfObject& podofoObj, SkPdfObject** out); #include "SkPdfHeaders_autogen.h" #include "SkPdfPodofoMapper_autogen.h" @@ -152,6 +153,11 @@ bool FunctionFromDictionary(const PdfMemDocument* pdfDoc, // TODO(edisonn): fix the mess with the files. #include "SkPdfFont.cpp" +bool skpdfmap(const PdfMemDocument& podofoDoc, const PdfObject& podofoObj, SkPdfObject** out) { + return PodofoMapper::map(podofoDoc, podofoObj, out); +} + + bool ArrayFromDictionary(const PdfMemDocument* pdfDoc, const PdfDictionary& dict, const char* key, |