diff options
author | edisonn@google.com <edisonn@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-06-27 13:22:42 +0000 |
---|---|---|
committer | edisonn@google.com <edisonn@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-06-27 13:22:42 +0000 |
commit | eee4b65d0b91070946353fbac04327bd616d8932 (patch) | |
tree | 659e22b3b06d46be28de69c43ce4eff7f9ffcde2 /experimental/PdfViewer/SkPdfFont.cpp | |
parent | bf557012914f3d6c0a14914fb60565ea95718e0f (diff) |
Basic load base font when specified in a FontDescriptor. basic load of TrueType font (FontFile2)
Review URL: https://codereview.chromium.org/18059003
git-svn-id: http://skia.googlecode.com/svn/trunk@9788 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental/PdfViewer/SkPdfFont.cpp')
-rw-r--r-- | experimental/PdfViewer/SkPdfFont.cpp | 72 |
1 files changed, 65 insertions, 7 deletions
diff --git a/experimental/PdfViewer/SkPdfFont.cpp b/experimental/PdfViewer/SkPdfFont.cpp index 4fac286ec2..42c8056da8 100644 --- a/experimental/PdfViewer/SkPdfFont.cpp +++ b/experimental/PdfViewer/SkPdfFont.cpp @@ -1,6 +1,9 @@ #include "SkPdfFont.h" #include "SkPdfParser.h" +#include "SkStream.h" +#include "SkTypeface.h" + std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts() { static std::map<std::string, SkPdfStandardFontEntry> gPdfStandardFonts; @@ -145,18 +148,73 @@ SkTypeface* SkTypefaceFromPdfStandardFont(const char* fontName, bool bold, bool return typeface; } +static SkPdfFont* fontFromFontDescriptor(SkPdfFontDescriptorDictionary* fd) { + // Only one, at most be available + if (fd->has_FontFile()) { + + } else if (fd->has_FontFile2()) { + SkPdfStream* pdfStream = fd->FontFile2(); + + if (!pdfStream->podofo()->GetStream()) { + // TODO(edisonn): report warning to be used in testing. + return NULL; + } + + char* uncompressedStream = NULL; + pdf_long uncompressedStreamLength = 0; + + // TODO(edisonn): get rid of try/catch exceptions! We should not throw on user data! + try { + pdfStream->podofo()->GetStream()->GetFilteredCopy(&uncompressedStream, &uncompressedStreamLength); + } catch (PdfError& e) { + // TODO(edisonn): report warning to be used in testing. + return NULL; + } + SkMemoryStream* skStream = new SkMemoryStream(uncompressedStream, uncompressedStreamLength); + SkTypeface* face = SkTypeface::CreateFromStream(skStream); + + if (face == NULL) { + // TODO(edisonn): report warning to be used in testing. + return NULL; + } + + face->ref(); + + return new SkPdfStandardFont(face); + } if (fd->has_FontFile3()) { + + } else { + + } + + return NULL; +} + 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 + + // TODO(edisonn): perf - make a map + for (int i = 0 ; i < obj->doc()->GetObjects().GetSize(); i++) { + PdfVecObjects& objects = (PdfVecObjects&)obj->doc()->GetObjects(); + const PdfObject* podofoFont = objects[i]; + SkPdfFontDescriptorDictionary* fd = NULL; + if (mapFontDescriptorDictionary(*obj->doc(), *podofoFont, &fd)) { + if (fd->has_FontName() && fd->FontName() == fontName) { + SkPdfFont* font = fontFromFontDescriptor(fd); + if (font) { + return font; + } else { + // failed to load font descriptor + break; + } + } + } + } + + // TODO(edisonn): warning/report issue return SkPdfFont::Default(); } |