Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "core/fxge/include/fx_ge.h" | 7 #include "core/fxge/include/fx_ge.h" |
| 8 | 8 |
| 9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ | 9 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ |
| 10 | 10 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 275 | 275 |
| 276 // Color | 276 // Color |
| 277 int iUnusedAlpha; | 277 int iUnusedAlpha; |
| 278 FX_COLORREF rgb; | 278 FX_COLORREF rgb; |
| 279 ArgbDecode(color, iUnusedAlpha, rgb); | 279 ArgbDecode(color, iUnusedAlpha, rgb); |
| 280 SetTextColor(m_hDC, rgb); | 280 SetTextColor(m_hDC, rgb); |
| 281 SetBkMode(m_hDC, TRANSPARENT); | 281 SetBkMode(m_hDC, TRANSPARENT); |
| 282 | 282 |
| 283 // Text | 283 // Text |
| 284 CFX_WideString wsText; | 284 CFX_WideString wsText; |
| 285 std::vector<INT> spacing(nChars); | |
| 286 FX_FLOAT fPreviousOriginX = 0; | |
| 285 for (int i = 0; i < nChars; ++i) { | 287 for (int i = 0; i < nChars; ++i) { |
| 286 // Only works with PDFs from Skia's PDF generator. Cannot handle arbitrary | 288 // Only works with PDFs from Skia's PDF generator. Cannot handle arbitrary |
| 287 // values from PDFs. | 289 // values from PDFs. |
| 288 const FXTEXT_CHARPOS& charpos = pCharPos[i]; | 290 const FXTEXT_CHARPOS& charpos = pCharPos[i]; |
| 289 ASSERT(charpos.m_OriginX == 0); | |
| 290 ASSERT(charpos.m_OriginY == 0); | |
| 291 ASSERT(charpos.m_AdjustMatrix[0] == 0); | 291 ASSERT(charpos.m_AdjustMatrix[0] == 0); |
| 292 ASSERT(charpos.m_AdjustMatrix[1] == 0); | 292 ASSERT(charpos.m_AdjustMatrix[1] == 0); |
| 293 ASSERT(charpos.m_AdjustMatrix[2] == 0); | 293 ASSERT(charpos.m_AdjustMatrix[2] == 0); |
| 294 ASSERT(charpos.m_AdjustMatrix[3] == 0); | 294 ASSERT(charpos.m_AdjustMatrix[3] == 0); |
| 295 ASSERT(charpos.m_OriginY == 0); | |
|
hal.canary
2016/07/29 15:26:21
why is this true?
Lei Zhang
2016/07/29 15:55:52
It's held up so far with my test cases. Do you hav
| |
| 296 | |
| 297 // Round the spacing to the nearest integer, but keep track of the rounding | |
| 298 // error for calculating the next spacing value. | |
| 299 FX_FLOAT fPixelSpacing = charpos.m_OriginX - fPreviousOriginX; | |
| 300 spacing[i] = FXSYS_round(fPixelSpacing); | |
|
Lei Zhang
2016/07/29 22:42:08
I printed a random page from Wikipedia and there a
| |
| 301 fPreviousOriginX = charpos.m_OriginX - (fPixelSpacing - spacing[i]); | |
| 302 | |
| 295 wsText += charpos.m_GlyphIndex; | 303 wsText += charpos.m_GlyphIndex; |
| 296 } | 304 } |
| 297 | 305 |
| 298 // Draw | 306 // Draw |
| 299 SetTextAlign(m_hDC, TA_LEFT | TA_BASELINE); | 307 SetTextAlign(m_hDC, TA_LEFT | TA_BASELINE); |
| 300 if (ExtTextOutW(m_hDC, 0, 0, ETO_GLYPH_INDEX, nullptr, wsText.c_str(), nChars, | 308 if (ExtTextOutW(m_hDC, 0, 0, ETO_GLYPH_INDEX, nullptr, wsText.c_str(), nChars, |
| 301 nullptr)) { | 309 nChars > 1 ? &spacing[1] : nullptr)) { |
| 302 return TRUE; | 310 return TRUE; |
| 303 } | 311 } |
| 304 | 312 |
| 305 // Give up and fail if there is no way to get the font to try again. | 313 // Give up and fail if there is no way to get the font to try again. |
| 306 if (!g_pdfium_typeface_accessible_func) | 314 if (!g_pdfium_typeface_accessible_func) |
| 307 return FALSE; | 315 return FALSE; |
| 308 | 316 |
| 309 // Try to get the font and draw again. | 317 // Try to get the font and draw again. |
| 310 g_pdfium_typeface_accessible_func(&lf, wsText.c_str(), nChars); | 318 g_pdfium_typeface_accessible_func(&lf, wsText.c_str(), nChars); |
| 311 return ExtTextOutW(m_hDC, 0, 0, ETO_GLYPH_INDEX, nullptr, wsText.c_str(), | 319 return ExtTextOutW(m_hDC, 0, 0, ETO_GLYPH_INDEX, nullptr, wsText.c_str(), |
| 312 nChars, nullptr); | 320 nChars, nChars > 1 ? &spacing[1] : nullptr); |
| 313 #else | 321 #else |
| 314 return FALSE; | 322 return FALSE; |
| 315 #endif | 323 #endif |
| 316 } | 324 } |
| 317 | 325 |
| 318 #endif // _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ | 326 #endif // _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_DESKTOP_ |
| OLD | NEW |