summaryrefslogtreecommitdiff
path: root/core/fxge/win32
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-08-15 11:27:48 -0700
committerCommit bot <commit-bot@chromium.org>2016-08-15 11:27:48 -0700
commit2ba53c176df1bc5bb963901e7cc42c6a60af24eb (patch)
tree26802ed7b0ef893b13435b4a30a5bdceb391f44f /core/fxge/win32
parent98e10199db97c8cae846cb2c0c571bda5033f61a (diff)
downloadpdfium-2ba53c176df1bc5bb963901e7cc42c6a60af24eb.tar.xz
Fix CGdiPrinterDriver::DrawDeviceText() to draw multiple characters.
Previously, Skia generated PDFs would only output one character at a time, but now they output whole strings. Handle this case. BUG=409472 Review-Url: https://codereview.chromium.org/2197553002
Diffstat (limited to 'core/fxge/win32')
-rw-r--r--core/fxge/win32/fx_win32_print.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp
index 16a429c636..207ff24552 100644
--- a/core/fxge/win32/fx_win32_print.cpp
+++ b/core/fxge/win32/fx_win32_print.cpp
@@ -209,6 +209,10 @@ FX_BOOL CGdiPrinterDriver::DrawDeviceText(int nChars,
if (nChars < 1 || !pFont || !pFont->IsEmbedded() || !pFont->IsTTFont())
return FALSE;
+ // Scale factor used to minimize the kerning problems caused by rounding
+ // errors below. Value choosen based on the title of https://crbug.com/18383
+ const double kScaleFactor = 10;
+
// Font
//
// Note that |pFont| has the actual font to render with embedded within, but
@@ -222,7 +226,7 @@ FX_BOOL CGdiPrinterDriver::DrawDeviceText(int nChars,
// In sandboxed environments, font loading may not work at all, so this may be
// the best possible effort.
LOGFONT lf = {};
- lf.lfHeight = -font_size;
+ lf.lfHeight = -font_size * kScaleFactor;
lf.lfWeight = pFont->IsBold() ? FW_BOLD : FW_NORMAL;
lf.lfItalic = pFont->IsItalic();
lf.lfCharSet = DEFAULT_CHARSET;
@@ -266,10 +270,10 @@ FX_BOOL CGdiPrinterDriver::DrawDeviceText(int nChars,
// Transforms
SetGraphicsMode(m_hDC, GM_ADVANCED);
XFORM xform;
- xform.eM11 = pObject2Device->GetA();
- xform.eM12 = pObject2Device->GetB();
- xform.eM21 = -pObject2Device->GetC();
- xform.eM22 = -pObject2Device->GetD();
+ xform.eM11 = pObject2Device->GetA() / kScaleFactor;
+ xform.eM12 = pObject2Device->GetB() / kScaleFactor;
+ xform.eM21 = -pObject2Device->GetC() / kScaleFactor;
+ xform.eM22 = -pObject2Device->GetD() / kScaleFactor;
xform.eDx = pObject2Device->GetE();
xform.eDy = pObject2Device->GetF();
ModifyWorldTransform(m_hDC, &xform, MWT_LEFTMULTIPLY);
@@ -283,23 +287,32 @@ FX_BOOL CGdiPrinterDriver::DrawDeviceText(int nChars,
// Text
CFX_WideString wsText;
+ std::vector<INT> spacing(nChars);
+ FX_FLOAT fPreviousOriginX = 0;
for (int i = 0; i < nChars; ++i) {
// Only works with PDFs from Skia's PDF generator. Cannot handle arbitrary
// values from PDFs.
const FXTEXT_CHARPOS& charpos = pCharPos[i];
- ASSERT(charpos.m_OriginX == 0);
- ASSERT(charpos.m_OriginY == 0);
ASSERT(charpos.m_AdjustMatrix[0] == 0);
ASSERT(charpos.m_AdjustMatrix[1] == 0);
ASSERT(charpos.m_AdjustMatrix[2] == 0);
ASSERT(charpos.m_AdjustMatrix[3] == 0);
+ ASSERT(charpos.m_OriginY == 0);
+
+ // Round the spacing to the nearest integer, but keep track of the rounding
+ // error for calculating the next spacing value.
+ FX_FLOAT fOriginX = charpos.m_OriginX * kScaleFactor;
+ FX_FLOAT fPixelSpacing = fOriginX - fPreviousOriginX;
+ spacing[i] = FXSYS_round(fPixelSpacing);
+ fPreviousOriginX = fOriginX - (fPixelSpacing - spacing[i]);
+
wsText += charpos.m_GlyphIndex;
}
// Draw
SetTextAlign(m_hDC, TA_LEFT | TA_BASELINE);
if (ExtTextOutW(m_hDC, 0, 0, ETO_GLYPH_INDEX, nullptr, wsText.c_str(), nChars,
- nullptr)) {
+ nChars > 1 ? &spacing[1] : nullptr)) {
return TRUE;
}
@@ -310,7 +323,7 @@ FX_BOOL CGdiPrinterDriver::DrawDeviceText(int nChars,
// Try to get the font and draw again.
g_pdfium_typeface_accessible_func(&lf, wsText.c_str(), nChars);
return ExtTextOutW(m_hDC, 0, 0, ETO_GLYPH_INDEX, nullptr, wsText.c_str(),
- nChars, nullptr);
+ nChars, nChars > 1 ? &spacing[1] : nullptr);
#else
return FALSE;
#endif