diff options
author | caryclark <caryclark@google.com> | 2016-11-21 04:41:31 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-21 04:41:31 -0800 |
commit | a1053a07ab1fe8c799acb4a46a61588616d85c5a (patch) | |
tree | 4a3bbe412b118ec1c206d782ea3b999c7c0f0323 /core/fxge | |
parent | d8f710cedd62c1d28beee15d7dc3d31ddd148437 (diff) | |
download | pdfium-a1053a07ab1fe8c799acb4a46a61588616d85c5a.tar.xz |
use skia text
This adds text to the _SUPPORT_SKIA_PATHS_
variant.
The output of the test corpus has more
differences, but no feature changes or
dropouts that I can see.
The text is a bit lighter. Bungeman thinks
this is because of our support of SRGB
color, although the fonts also look different
so maybe there's more to the story.
The output looks compatible with the
variations I see in Adobe Reader and Firefox
on the same platform.
There's probably more text tuning to do.
Additionally, this turns off the caching
feature for this variation. Caching can't
work because the drawing alternates between
Skia and PDFium's native blits, so any
state caching won't know about changes
and drawing performed by the other.
R=dsinclair@chromium.org, bungeman@chromium.org
Review-Url: https://codereview.chromium.org/2520483002
Diffstat (limited to 'core/fxge')
-rw-r--r-- | core/fxge/cfx_facecache.h | 4 | ||||
-rw-r--r-- | core/fxge/fx_font.h | 4 | ||||
-rw-r--r-- | core/fxge/ge/cfx_facecache.cpp | 11 | ||||
-rw-r--r-- | core/fxge/ge/cfx_font.cpp | 2 | ||||
-rw-r--r-- | core/fxge/skia/fx_skia_device.cpp | 52 | ||||
-rw-r--r-- | core/fxge/skia/fx_skia_device.h | 7 |
6 files changed, 47 insertions, 33 deletions
diff --git a/core/fxge/cfx_facecache.h b/core/fxge/cfx_facecache.h index 96fc73b57d..60528ba6a5 100644 --- a/core/fxge/cfx_facecache.h +++ b/core/fxge/cfx_facecache.h @@ -27,7 +27,7 @@ class CFX_FaceCache { uint32_t glyph_index, int dest_width); -#ifdef _SKIA_SUPPORT_ +#if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ CFX_TypeFace* GetDeviceCache(const CFX_Font* pFont); #endif @@ -56,7 +56,7 @@ class CFX_FaceCache { FXFT_Face const m_Face; std::map<CFX_ByteString, std::unique_ptr<CFX_SizeGlyphCache>> m_SizeMap; std::map<uint32_t, std::unique_ptr<CFX_PathData>> m_PathMap; -#ifdef _SKIA_SUPPORT_ +#if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ CFX_TypeFace* m_pTypeface; #endif }; diff --git a/core/fxge/fx_font.h b/core/fxge/fx_font.h index a1acbfdcf4..c0d204199c 100644 --- a/core/fxge/fx_font.h +++ b/core/fxge/fx_font.h @@ -23,7 +23,7 @@ class CFX_GlyphBitmap; class CFX_PathData; class CFX_SizeGlyphCache; -#ifdef _SKIA_SUPPORT_ +#if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_ class SkTypeface; using CFX_TypeFace = SkTypeface; @@ -129,7 +129,7 @@ class CFX_Font { int& text_flags) const; const CFX_PathData* LoadGlyphPath(uint32_t glyph_index, int dest_width) const; -#ifdef _SKIA_SUPPORT_ +#if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_ CFX_TypeFace* GetDeviceCache() const; #endif diff --git a/core/fxge/ge/cfx_facecache.cpp b/core/fxge/ge/cfx_facecache.cpp index e7e6e0e42c..942814b75a 100644 --- a/core/fxge/ge/cfx_facecache.cpp +++ b/core/fxge/ge/cfx_facecache.cpp @@ -16,7 +16,7 @@ #include "core/fxge/ge/fx_text_int.h" #include "third_party/base/numerics/safe_math.h" -#ifdef _SKIA_SUPPORT_ +#if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ #include "third_party/skia/include/core/SkStream.h" #include "third_party/skia/include/core/SkTypeface.h" #endif @@ -76,7 +76,7 @@ void ContrastAdjust(uint8_t* pDataIn, CFX_FaceCache::CFX_FaceCache(FXFT_Face face) : m_Face(face) -#ifdef _SKIA_SUPPORT_ +#if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ , m_pTypeface(nullptr) #endif @@ -84,7 +84,7 @@ CFX_FaceCache::CFX_FaceCache(FXFT_Face face) } CFX_FaceCache::~CFX_FaceCache() { -#ifdef _SKIA_SUPPORT_ +#if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ SkSafeUnref(m_pTypeface); #endif } @@ -300,7 +300,8 @@ const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(const CFX_Font* pFont, } #endif CFX_ByteString FaceGlyphsKey(keygen.m_Key, keygen.m_KeyLen); -#if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ || defined _SKIA_SUPPORT_ +#if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ || defined _SKIA_SUPPORT_ || \ + defined _SKIA_SUPPORT_PATHS_ return LookUpGlyphBitmap(pFont, pMatrix, FaceGlyphsKey, glyph_index, bFontStyle, dest_width, anti_alias); #else @@ -348,7 +349,7 @@ const CFX_GlyphBitmap* CFX_FaceCache::LoadGlyphBitmap(const CFX_Font* pFont, #endif } -#ifdef _SKIA_SUPPORT_ +#if defined _SKIA_SUPPORT_ || defined _SKIA_SUPPORT_PATHS_ CFX_TypeFace* CFX_FaceCache::GetDeviceCache(const CFX_Font* pFont) { if (!m_pTypeface) { m_pTypeface = diff --git a/core/fxge/ge/cfx_font.cpp b/core/fxge/ge/cfx_font.cpp index 5604e53e40..b778031606 100644 --- a/core/fxge/ge/cfx_font.cpp +++ b/core/fxge/ge/cfx_font.cpp @@ -709,7 +709,7 @@ const CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index, return GetFaceCache()->LoadGlyphPath(this, glyph_index, dest_width); } -#ifdef _SKIA_SUPPORT_ +#if defined _SKIA_SUPPORT_ || _SKIA_SUPPORT_PATHS_ CFX_TypeFace* CFX_Font::GetDeviceCache() const { return GetFaceCache()->GetDeviceCache(this); } diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index 6c9763765a..d525c470af 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp @@ -30,6 +30,7 @@ #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkStream.h" +#include "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/effects/SkDashPathEffect.h" #include "third_party/skia/include/pathops/SkPathOps.h" @@ -39,7 +40,6 @@ #include "third_party/skia/include/core/SkMaskFilter.h" #include "third_party/skia/include/core/SkPictureRecorder.h" #include "third_party/skia/include/core/SkShader.h" -#include "third_party/skia/include/core/SkTypeface.h" #include "third_party/skia/include/effects/SkGradientShader.h" #endif // _SKIA_SUPPORT_ @@ -266,7 +266,6 @@ SkMatrix ToSkMatrix(const CFX_Matrix& m) { return skMatrix; } -#ifdef _SKIA_SUPPORT_ // use when pdf's y-axis points up insead of down SkMatrix ToFlippedSkMatrix(const CFX_Matrix& m, SkScalar flip) { SkMatrix skMatrix; @@ -274,7 +273,6 @@ SkMatrix ToFlippedSkMatrix(const CFX_Matrix& m, SkScalar flip) { 0, 1); return skMatrix; } -#endif // _SKIA_SUPPORT_ SkBlendMode GetSkiaBlendMode(int blend_type) { switch (blend_type) { @@ -602,6 +600,7 @@ bool Upsample(const CFX_DIBSource* pSource, } // namespace +#ifdef _SKIA_SUPPORT_ // Encapsulate the state used for successive text and path draws so that // they can be combined. class SkiaState { @@ -619,13 +618,10 @@ class SkiaState { m_strokeColor(0), m_blendType(0), m_commandIndex(0), -#if _SKIA_SUPPORT_ m_drawText(false), -#endif // _SKIA_SUPPORT_ m_drawPath(false), m_fillPath(false), - m_debugDisable(true) { - } + m_debugDisable(false) {} bool DrawPath(const CFX_PathData* pPathData, const CFX_Matrix* pMatrix, @@ -639,10 +635,8 @@ class SkiaState { return false; if (m_commandIndex < m_commands.count()) FlushCommands(pDriver); -#if _SKIA_SUPPORT_ if (m_drawText) FlushText(pDriver); -#endif // _SKIA_SUPPORT_ if (m_drawPath && DrawChanged(pMatrix, pDrawState, fill_color, stroke_color, fill_mode, blend_type)) { FlushPath(pDriver); @@ -709,7 +703,6 @@ class SkiaState { m_drawPath = false; } -#ifdef _SKIA_SUPPORT_ bool DrawText(int nChars, const FXTEXT_CHARPOS* pCharPos, CFX_Font* pFont, @@ -773,7 +766,6 @@ class SkiaState { skCanvas->restore(); m_drawText = false; } -#endif // _SKIA_SUPPORT_ bool SetClipFill(const CFX_PathData* pPathData, const CFX_Matrix* pMatrix, @@ -963,10 +955,8 @@ class SkiaState { void Flush(CFX_SkiaDeviceDriver* pDriver) { if (m_drawPath) FlushPath(pDriver); -#ifdef _SKIA_SUPPORT_ if (m_drawText) FlushText(pDriver); -#endif // _SKIA_SUPPORT_ } void Dump(const CFX_SkiaDeviceDriver* pDriver) const { @@ -1009,13 +999,12 @@ class SkiaState { uint32_t m_strokeColor; int m_blendType; int m_commandIndex; // active position in clip command stack -#ifdef _SKIA_SUPPORT_ bool m_drawText; -#endif // _SKIA_SUPPORT_ bool m_drawPath; bool m_fillPath; bool m_debugDisable; // turn off cache for debugging }; +#endif // _SKIA_SUPPORT_ // convert a stroking path to scanlines void CFX_SkiaDeviceDriver::PaintStroke(SkPaint* spaint, @@ -1089,7 +1078,9 @@ CFX_SkiaDeviceDriver::CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, : m_pBitmap(pBitmap), m_pOriDevice(pOriDevice), m_pRecorder(nullptr), +#ifdef _SKIA_SUPPORT_ m_pCache(new SkiaState), +#endif #ifdef _SKIA_SUPPORT_PATHS_ m_pClipRgn(nullptr), m_FillFlags(0), @@ -1136,8 +1127,10 @@ CFX_SkiaDeviceDriver::~CFX_SkiaDeviceDriver() { } void CFX_SkiaDeviceDriver::Flush() { +#ifdef _SKIA_SUPPORT_ m_pCache->Flush(this); m_pCache->FlushCommands(this); +#endif } bool CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, @@ -1151,6 +1144,7 @@ bool CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, color, this)) { return true; } +#endif sk_sp<SkTypeface> typeface(SkSafeRef(pFont->GetDeviceCache())); SkPaint paint; paint.setAntiAlias(true); @@ -1162,6 +1156,9 @@ bool CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, paint.setSubpixelText(true); m_pCanvas->save(); SkScalar flip = font_size < 0 ? -1 : 1; + SkScalar vFlip = flip; + if (pFont->IsVertical()) + vFlip *= -1; SkMatrix skMatrix = ToFlippedSkMatrix(*pObject2Device, flip); m_pCanvas->concat(skMatrix); SkTDArray<SkPoint> positions; @@ -1170,17 +1167,18 @@ bool CFX_SkiaDeviceDriver::DrawDeviceText(int nChars, glyphs.setCount(nChars); for (int index = 0; index < nChars; ++index) { const FXTEXT_CHARPOS& cp = pCharPos[index]; - positions[index] = {cp.m_OriginX * flip, cp.m_OriginY * flip}; + positions[index] = {cp.m_OriginX * flip, cp.m_OriginY * vFlip}; glyphs[index] = (uint16_t)cp.m_GlyphIndex; } m_pCanvas->drawPosText(glyphs.begin(), nChars * 2, positions.begin(), paint); m_pCanvas->restore(); - return true; -#endif // _SKIA_SUPPORT_ #ifdef _SKIA_SUPPORT_PATHS_ - return false; + if (FXARGB_A(color) < 255) { + m_pBitmap->MarkForUnPreMultiply(true); + } #endif // _SKIA_SUPPORT_PATHS_ + return true; } int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const { @@ -1236,7 +1234,9 @@ int CFX_SkiaDeviceDriver::GetDeviceCaps(int caps_id) const { } void CFX_SkiaDeviceDriver::SaveState() { +#ifdef _SKIA_SUPPORT_ if (!m_pCache->ClipSave(this)) +#endif m_pCanvas->save(); #ifdef _SKIA_SUPPORT_PATHS_ @@ -1248,11 +1248,17 @@ void CFX_SkiaDeviceDriver::SaveState() { } void CFX_SkiaDeviceDriver::RestoreState(bool bKeepSaved) { +#ifdef _SKIA_SUPPORT_ if (!m_pCache->ClipRestore(this)) +#endif m_pCanvas->restore(); - if (bKeepSaved && !m_pCache->ClipSave(this)) + if (bKeepSaved +#ifdef _SKIA_SUPPORT_ + && !m_pCache->ClipSave(this) +#endif + ) { m_pCanvas->save(); - + } #ifdef _SKIA_SUPPORT_PATHS_ m_pClipRgn.reset(); @@ -1398,10 +1404,12 @@ bool CFX_SkiaDeviceDriver::DrawPath( uint32_t stroke_color, // stroke color int fill_mode, // fill mode, WINDING or ALTERNATE. 0 for not filled int blend_type) { +#ifdef _SKIA_SUPPORT_ if (m_pCache->DrawPath(pPathData, pObject2Device, pGraphState, fill_color, stroke_color, fill_mode, blend_type, this)) { return true; } +#endif SkIRect rect; rect.set(0, 0, GetDeviceCaps(FXDC_PIXEL_WIDTH), GetDeviceCaps(FXDC_PIXEL_HEIGHT)); @@ -1451,7 +1459,7 @@ bool CFX_SkiaDeviceDriver::DrawPath( m_pCanvas->drawPath(skPath, skPaint); } m_pCanvas->restore(); -#if defined _SKIA_SUPPORT_PATHS_ +#ifdef _SKIA_SUPPORT_PATHS_ if ((fill_mode & 3 && FXARGB_A(fill_color) < 255) || (pGraphState && stroke_alpha < 255)) { m_pBitmap->MarkForUnPreMultiply(true); diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h index e14ea7c458..bbbbdaa2dd 100644 --- a/core/fxge/skia/fx_skia_device.h +++ b/core/fxge/skia/fx_skia_device.h @@ -15,10 +15,13 @@ class SkMatrix; class SkPaint; class SkPath; class SkPictureRecorder; -class SkiaState; struct FXTEXT_CHARPOS; struct SkIRect; +#ifdef _SKIA_SUPPORT_ +class SkiaState; +#endif + class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver { public: CFX_SkiaDeviceDriver(CFX_DIBitmap* pBitmap, @@ -166,7 +169,9 @@ class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver { CFX_DIBitmap* m_pOriDevice; SkCanvas* m_pCanvas; SkPictureRecorder* const m_pRecorder; +#ifdef _SKIA_SUPPORT_ std::unique_ptr<SkiaState> m_pCache; +#endif #ifdef _SKIA_SUPPORT_PATHS_ std::unique_ptr<CFX_ClipRgn> m_pClipRgn; std::vector<std::unique_ptr<CFX_ClipRgn>> m_StateStack; |