Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Unified Diff: experimental/PdfViewer/SkPdfFont.cpp

Issue 18059003: Basic load base font when specified in a FontDescriptor. basic load of TrueType font (FontFile2) (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/PdfViewer/SkPdfBasics.h ('k') | experimental/PdfViewer/autogen/SkPdfPodofoMapper_autogen.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/PdfViewer/SkPdfFont.cpp
===================================================================
--- experimental/PdfViewer/SkPdfFont.cpp (revision 9773)
+++ experimental/PdfViewer/SkPdfFont.cpp (working copy)
@@ -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 @@
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();
}
« no previous file with comments | « experimental/PdfViewer/SkPdfBasics.h ('k') | experimental/PdfViewer/autogen/SkPdfPodofoMapper_autogen.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698