From 4db9046e56c884a350fa2c5087f8d5b8110463c4 Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Mon, 19 Jun 2017 17:07:40 -0400 Subject: Add heuristic for improving text rendering in CPDF_CharPosList::Load MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL uses the following algorithm for improving substitute font spacing (we are assuming the text layout is horizontal): * Calculate PDFWidth, the width that the PDF says the glyph should have. * Calculate FTWidth, the width calculated by freetype for the glyph, using the substitute font that we'll use to render it. Note that some embedded fonts have PDFWidth == FTWidth + 1, so we consider that to be matching widths. * If PDFWidth > FTWidth + 1 , move the x coordinate by the difference / 2 so that the glyph is rendered in a more centered spot and the text looks better. * If PDFWidth < FTWidth, transform the glyph horizontally by PDFWidth / FTWidth so that the glyph gets compressed and does not overlap with surrounding glyphs. Bug: chromium:431507 Change-Id: Ia378344253fabe44d93af4daab98bb3b7bca22de Reviewed-on: https://pdfium-review.googlesource.com/6630 Reviewed-by: Lei Zhang Commit-Queue: Nicolás Peña --- core/fpdfapi/font/cpdf_font.cpp | 4 ++++ core/fpdfapi/font/cpdf_font.h | 1 + core/fpdfapi/font/cpdf_simplefont.cpp | 4 ++++ core/fpdfapi/font/cpdf_simplefont.h | 2 ++ 4 files changed, 11 insertions(+) (limited to 'core/fpdfapi/font') diff --git a/core/fpdfapi/font/cpdf_font.cpp b/core/fpdfapi/font/cpdf_font.cpp index 1faa4ec4be..bdd3464ed2 100644 --- a/core/fpdfapi/font/cpdf_font.cpp +++ b/core/fpdfapi/font/cpdf_font.cpp @@ -159,6 +159,10 @@ uint32_t CPDF_Font::CharCodeFromUnicode(wchar_t unicode) const { return m_pToUnicodeMap ? m_pToUnicodeMap->ReverseLookup(unicode) : 0; } +bool CPDF_Font::HasFontWidths() const { + return true; +} + void CPDF_Font::LoadFontDescriptor(CPDF_Dictionary* pFontDesc) { m_Flags = pFontDesc->GetIntegerFor("Flags", FXFONT_NONSYMBOLIC); int ItalicAngle = 0; diff --git a/core/fpdfapi/font/cpdf_font.h b/core/fpdfapi/font/cpdf_font.h index 1fef77b322..f70542223c 100644 --- a/core/fpdfapi/font/cpdf_font.h +++ b/core/fpdfapi/font/cpdf_font.h @@ -61,6 +61,7 @@ class CPDF_Font { virtual int GlyphFromCharCodeExt(uint32_t charcode); virtual CFX_WideString UnicodeFromCharCode(uint32_t charcode) const; virtual uint32_t CharCodeFromUnicode(wchar_t Unicode) const; + virtual bool HasFontWidths() const; const CFX_ByteString& GetBaseFont() const { return m_BaseFont; } CFX_SubstFont* GetSubstFont() const { return m_Font.GetSubstFont(); } diff --git a/core/fpdfapi/font/cpdf_simplefont.cpp b/core/fpdfapi/font/cpdf_simplefont.cpp index ebf2cb65c7..a6c3ba0547 100644 --- a/core/fpdfapi/font/cpdf_simplefont.cpp +++ b/core/fpdfapi/font/cpdf_simplefont.cpp @@ -212,3 +212,7 @@ uint32_t CPDF_SimpleFont::CharCodeFromUnicode(wchar_t unicode) const { return ret; return m_Encoding.CharCodeFromUnicode(unicode); } + +bool CPDF_SimpleFont::HasFontWidths() const { + return !m_bUseFontWidth; +} diff --git a/core/fpdfapi/font/cpdf_simplefont.h b/core/fpdfapi/font/cpdf_simplefont.h index 3e414fa788..6a22f46966 100644 --- a/core/fpdfapi/font/cpdf_simplefont.h +++ b/core/fpdfapi/font/cpdf_simplefont.h @@ -29,6 +29,8 @@ class CPDF_SimpleFont : public CPDF_Font { CPDF_FontEncoding* GetEncoding() { return &m_Encoding; } + bool HasFontWidths() const override; + protected: virtual void LoadGlyphMap() = 0; -- cgit v1.2.3