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

Unified Diff: experimental/PdfViewer/SkPdfFont.h

Issue 18117005: more work on pdf fonts, more to come (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/PdfReference-okular-1.txt ('k') | experimental/PdfViewer/SkPdfFont.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/PdfViewer/SkPdfFont.h
===================================================================
--- experimental/PdfViewer/SkPdfFont.h (revision 9787)
+++ experimental/PdfViewer/SkPdfFont.h (working copy)
@@ -17,7 +17,6 @@
class SkPdfType1Font;
class SkPdfType3Font;
class SkPdfTrueTypeFont;
-class SkPdfCIDFont;
class SkPdfMultiMasterFont;
class SkPdfFont;
@@ -30,7 +29,7 @@
std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts();
SkTypeface* SkTypefaceFromPdfStandardFont(const char* fontName, bool bold, bool italic);
-SkPdfFont* SkPdfFontFromName(SkPdfObject* obj, const char* fontName);
+SkPdfFont* fontFromName(SkPdfObject* obj, const char* fontName);
struct SkUnencodedText {
void* text;
@@ -100,7 +99,29 @@
}
};
+// 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;
+ }
+};
+
class SkPdfCIDToGIDMapIdentityEncoding : public SkPdfEncoding {
public:
virtual bool decodeText(const SkUnencodedText& textIn, SkDecodedText* textOut) const {
@@ -131,13 +152,15 @@
public:
- SkPdfFont() : fBaseFont(NULL), fEncoding(NULL), fToUnicode(NULL) {}
+ SkPdfFont() : fBaseFont(NULL), fEncoding(SkPdfDefaultEncoding::instance()), fToUnicode(NULL) {}
const SkPdfEncoding* encoding() const {return fEncoding;}
- void drawText(const SkDecodedText& text, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas, SkMatrix* matrix) {
+ void drawText(const SkDecodedText& text, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
for (int i = 0 ; i < text.size(); i++) {
- drawOneChar(text[i], paint, pdfContext, canvas, matrix);
+ double width = drawOneChar(text[i], paint, pdfContext, canvas);
+ pdfContext->fGraphicsState.fMatrixTm.preTranslate(SkDoubleToScalar(width), SkDoubleToScalar(0.0));
+ canvas->translate(SkDoubleToScalar(width), SkDoubleToScalar(0.0));
}
}
@@ -163,18 +186,18 @@
};
static SkPdfFont* fontFromPdfDictionary(SkPdfFontDictionary* dict);
- static SkPdfFont* Default() {return SkPdfFontFromName(NULL, "TimesNewRoman");}
+ static SkPdfFont* Default() {return fontFromName(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);
+ static SkPdfFont* fontFromFontDescriptor(SkPdfFontDescriptorDictionary* fd, bool loadFromName = true);
+
public:
- virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas, SkMatrix* matrix) = 0;
- virtual void afterChar(SkPaint* paint, SkMatrix* matrix) = 0;
+ virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) = 0;
virtual void afterWord(SkPaint* paint, SkMatrix* matrix) = 0;
};
@@ -185,7 +208,7 @@
SkPdfStandardFont(SkTypeface* typeface) : fTypeface(typeface) {}
public:
- virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas, SkMatrix* matrix) {
+ virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
paint->setTypeface(fTypeface);
paint->setTextEncoding(SkPaint::kUTF8_TextEncoding);
@@ -196,10 +219,9 @@
canvas->drawText(utf8, len, SkDoubleToScalar(0), SkDoubleToScalar(0), *paint);
SkScalar textWidth = paint->measureText(utf8, len);
- matrix->preTranslate(textWidth, SkDoubleToScalar(0.0));
+ return SkScalarToDouble(textWidth);
}
- virtual void afterChar(SkPaint* paint, SkMatrix* matrix) {}
virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {}
};
@@ -209,99 +231,44 @@
public:
- virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas, SkMatrix* matrix) {
- fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas, matrix);
+ virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
+ return fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas);
}
- 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, PdfContext* pdfContext, 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());
+ if (dict->has_FontDescriptor()) {
+ fBaseFont = SkPdfFont::fontFromFontDescriptor(dict->FontDescriptor());
+ } else {
+ fBaseFont = fontFromName(dict, dict->BaseFont().c_str());
+ }
}
-
public:
- virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas, SkMatrix* matrix) {
-
+ virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
+ return fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas);
}
- virtual void afterChar(SkPaint* paint, SkMatrix* matrix) {
-
- }
-
virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {
}
- };
+};
-
-class SkPdfCIDFont : public SkPdfFont {
+class SkPdfTrueTypeFont : public SkPdfType1Font {
public:
- SkPdfCIDFont(SkPdfCIDFontDictionary* dict) {
- fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str());
+ SkPdfTrueTypeFont(SkPdfTrueTypeFontDictionary* dict) : SkPdfType1Font(dict) {
}
-
-public:
- virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas, SkMatrix* matrix) {
-
- }
-
- virtual void afterChar(SkPaint* paint, SkMatrix* matrix) {
-
- }
-
- virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {
-
- }
};
-class SkPdfMultiMasterFont : public SkPdfFont {
+class SkPdfMultiMasterFont : public SkPdfType1Font {
public:
- SkPdfMultiMasterFont(SkPdfMultiMasterFontDictionary* dict) {
- fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str());
+ SkPdfMultiMasterFont(SkPdfMultiMasterFontDictionary* dict) : SkPdfType1Font(dict) {
}
-
-public:
- virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas, SkMatrix* matrix) {
-
- }
-
- virtual void afterChar(SkPaint* paint, SkMatrix* matrix) {
-
- }
-
- virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {
-
- }
};
/*
class CIDToGIDMap {
@@ -351,7 +318,7 @@
public:
SkPdfType3Font(SkPdfType3FontDictionary* dict) {
- fBaseFont = SkPdfFontFromName(dict, dict->BaseFont().c_str());
+ fBaseFont = fontFromName(dict, dict->BaseFont().c_str());
if (dict->has_Encoding()) {
if (dict->isEncodingAName()) {
@@ -410,10 +377,9 @@
}
public:
- virtual void drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas, SkMatrix* matrix) {
+ virtual double drawOneChar(unsigned int ch, SkPaint* paint, PdfContext* pdfContext, SkCanvas* canvas) {
if (ch < fFirstChar || ch > fLastChar || !fChars[ch - fFirstChar].fObj) {
- fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas, matrix);
- return;
+ return fBaseFont->drawOneChar(ToUnicode(ch), paint, pdfContext, canvas);
}
#ifdef PDF_TRACE
@@ -424,9 +390,10 @@
#endif
doType3Char(pdfContext, canvas, fChars[ch - fFirstChar].fObj, fFontBBox, fFonMatrix, pdfContext->fGraphicsState.fCurFontSize);
- }
- virtual void afterChar(SkPaint* paint, SkMatrix* matrix) {
+ // TODO(edisonn): verify/test translate code, not tested yet
+ pdfContext->fGraphicsState.fMatrixTm.preTranslate(SkDoubleToScalar(pdfContext->fGraphicsState.fCurFontSize * fChars[ch - fFirstChar].fWidth),
+ SkDoubleToScalar(0.0));
}
virtual void afterWord(SkPaint* paint, SkMatrix* matrix) {
« no previous file with comments | « experimental/PdfViewer/PdfReference-okular-1.txt ('k') | experimental/PdfViewer/SkPdfFont.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698