From 49f7deb494064351c72ef4d31577e04f634e63f3 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 16 Feb 2017 14:02:22 -0500 Subject: Convert fx_font points to CFX_Point{F}s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This converts the two Origin{X,Y} points in fx_font to CFX_Point{F} points. Change-Id: Id7cbb34a6e76043f1b26e9d7091d89f300dfc563 Reviewed-on: https://pdfium-review.googlesource.com/2720 Reviewed-by: Nicolás Peña Commit-Queue: dsinclair --- core/fpdfapi/render/cpdf_renderstatus.cpp | 18 ++++++++--------- core/fxge/fx_font.h | 13 +++++++----- core/fxge/ge/cfx_renderdevice.cpp | 33 +++++++++++++++---------------- core/fxge/ge/fx_ge_text.cpp | 10 ++++++++-- core/fxge/win32/fx_win32_print.cpp | 4 ++-- 5 files changed, 42 insertions(+), 36 deletions(-) diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index fd44d42484..5a340cd8b1 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp @@ -1833,8 +1833,8 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj, continue; m_pDevice->SetBitMask(&glyph.m_pGlyph->m_Bitmap, - glyph.m_OriginX + glyph.m_pGlyph->m_Left, - glyph.m_OriginY - glyph.m_pGlyph->m_Top, + glyph.m_Origin.x + glyph.m_pGlyph->m_Left, + glyph.m_Origin.y - glyph.m_pGlyph->m_Top, fill_argb); } glyphs.clear(); @@ -1892,15 +1892,13 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj, if (!pBitmap) continue; - int origin_x = FXSYS_round(matrix.e); - int origin_y = FXSYS_round(matrix.f); + CFX_Point origin(FXSYS_round(matrix.e), FXSYS_round(matrix.f)); if (glyphs.empty()) { - m_pDevice->SetBitMask(&pBitmap->m_Bitmap, origin_x + pBitmap->m_Left, - origin_y - pBitmap->m_Top, fill_argb); + m_pDevice->SetBitMask(&pBitmap->m_Bitmap, origin.x + pBitmap->m_Left, + origin.y - pBitmap->m_Top, fill_argb); } else { glyphs[iChar].m_pGlyph = pBitmap; - glyphs[iChar].m_OriginX = origin_x; - glyphs[iChar].m_OriginY = origin_y; + glyphs[iChar].m_Origin = origin; } } else { CFX_Matrix image_matrix = pType3Char->m_ImageMatrix; @@ -1930,14 +1928,14 @@ bool CPDF_RenderStatus::ProcessType3Text(CPDF_TextObject* textobj, if (!glyph.m_pGlyph) continue; - pdfium::base::CheckedNumeric left = glyph.m_OriginX; + pdfium::base::CheckedNumeric left = glyph.m_Origin.x; left += glyph.m_pGlyph->m_Left; left -= rect.left; left *= sa; if (!left.IsValid()) continue; - pdfium::base::CheckedNumeric top = glyph.m_OriginY; + pdfium::base::CheckedNumeric top = glyph.m_Origin.y; top -= glyph.m_pGlyph->m_Top; top -= rect.top; top *= sd; diff --git a/core/fxge/fx_font.h b/core/fxge/fx_font.h index 224720fbc3..3c095d1976 100644 --- a/core/fxge/fx_font.h +++ b/core/fxge/fx_font.h @@ -222,12 +222,15 @@ class CFX_GlyphBitmap { CFX_DIBitmap m_Bitmap; }; -struct FXTEXT_GLYPHPOS { +class FXTEXT_GLYPHPOS { + public: + FXTEXT_GLYPHPOS(); + FXTEXT_GLYPHPOS(const FXTEXT_GLYPHPOS&); + ~FXTEXT_GLYPHPOS(); + const CFX_GlyphBitmap* m_pGlyph; - int m_OriginX; - int m_OriginY; - FX_FLOAT m_fOriginX; - FX_FLOAT m_fOriginY; + CFX_Point m_Origin; + CFX_PointF m_fOrigin; }; FX_RECT FXGE_GetGlyphsBBox(const std::vector& glyphs, diff --git a/core/fxge/ge/cfx_renderdevice.cpp b/core/fxge/ge/cfx_renderdevice.cpp index f2bf48912c..86e74cafc4 100644 --- a/core/fxge/ge/cfx_renderdevice.cpp +++ b/core/fxge/ge/cfx_renderdevice.cpp @@ -27,19 +27,19 @@ namespace { void AdjustGlyphSpace(std::vector* pGlyphAndPos) { ASSERT(pGlyphAndPos->size() > 1); std::vector& glyphs = *pGlyphAndPos; - bool bVertical = glyphs.back().m_OriginX == glyphs.front().m_OriginX; - if (!bVertical && (glyphs.back().m_OriginY != glyphs.front().m_OriginY)) + bool bVertical = glyphs.back().m_Origin.x == glyphs.front().m_Origin.x; + if (!bVertical && (glyphs.back().m_Origin.y != glyphs.front().m_Origin.y)) return; for (size_t i = glyphs.size() - 1; i > 1; --i) { FXTEXT_GLYPHPOS& next = glyphs[i]; - int next_origin = bVertical ? next.m_OriginY : next.m_OriginX; - FX_FLOAT next_origin_f = bVertical ? next.m_fOriginY : next.m_fOriginX; + int next_origin = bVertical ? next.m_Origin.y : next.m_Origin.x; + FX_FLOAT next_origin_f = bVertical ? next.m_fOrigin.y : next.m_fOrigin.x; FXTEXT_GLYPHPOS& current = glyphs[i - 1]; - int& current_origin = bVertical ? current.m_OriginY : current.m_OriginX; + int& current_origin = bVertical ? current.m_Origin.y : current.m_Origin.x; FX_FLOAT current_origin_f = - bVertical ? current.m_fOriginY : current.m_fOriginX; + bVertical ? current.m_fOrigin.y : current.m_fOrigin.x; int space = next_origin - current_origin; FX_FLOAT space_f = next_origin_f - current_origin_f; @@ -927,15 +927,14 @@ bool CFX_RenderDevice::DrawNormalText(int nChars, for (size_t i = 0; i < glyphs.size(); ++i) { FXTEXT_GLYPHPOS& glyph = glyphs[i]; const FXTEXT_CHARPOS& charpos = pCharPos[i]; - glyph.m_fOriginX = charpos.m_Origin.x; - glyph.m_fOriginY = charpos.m_Origin.y; - text2Device.TransformPoint(glyph.m_fOriginX, glyph.m_fOriginY); + glyph.m_fOrigin = text2Device.Transform(charpos.m_Origin); if (anti_alias < FXFT_RENDER_MODE_LCD) - glyph.m_OriginX = FXSYS_round(glyph.m_fOriginX); + glyph.m_Origin.x = FXSYS_round(glyph.m_fOrigin.x); else - glyph.m_OriginX = (int)FXSYS_floor(glyph.m_fOriginX); - glyph.m_OriginY = FXSYS_round(glyph.m_fOriginY); + glyph.m_Origin.x = static_cast(FXSYS_floor(glyph.m_fOrigin.x)); + glyph.m_Origin.y = FXSYS_round(glyph.m_fOrigin.y); + if (charpos.m_bGlyphAdjust) { CFX_Matrix new_matrix( charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], @@ -981,8 +980,8 @@ bool CFX_RenderDevice::DrawNormalText(int nChars, continue; const CFX_DIBitmap* pGlyph = &glyph.m_pGlyph->m_Bitmap; bitmap.TransferBitmap( - glyph.m_OriginX + glyph.m_pGlyph->m_Left - pixel_left, - glyph.m_OriginY - glyph.m_pGlyph->m_Top - pixel_top, + glyph.m_Origin.x + glyph.m_pGlyph->m_Left - pixel_left, + glyph.m_Origin.y - glyph.m_pGlyph->m_Top - pixel_top, pGlyph->GetWidth(), pGlyph->GetHeight(), pGlyph, 0, 0); } return SetBitMask(&bitmap, bmp_rect.left, bmp_rect.top, fill_color); @@ -1016,13 +1015,13 @@ bool CFX_RenderDevice::DrawNormalText(int nChars, if (!glyph.m_pGlyph) continue; - pdfium::base::CheckedNumeric left = glyph.m_OriginX; + pdfium::base::CheckedNumeric left = glyph.m_Origin.x; left += glyph.m_pGlyph->m_Left; left -= pixel_left; if (!left.IsValid()) return false; - pdfium::base::CheckedNumeric top = glyph.m_OriginY; + pdfium::base::CheckedNumeric top = glyph.m_Origin.y; top -= glyph.m_pGlyph->m_Top; top -= pixel_top; if (!top.IsValid()) @@ -1042,7 +1041,7 @@ bool CFX_RenderDevice::DrawNormalText(int nChars, } bool bBGRStripe = !!(text_flags & FXTEXT_BGR_STRIPE); ncols /= 3; - int x_subpixel = (int)(glyph.m_fOriginX * 3) % 3; + int x_subpixel = static_cast(glyph.m_fOrigin.x * 3) % 3; int start_col = pdfium::base::ValueOrDieForType(pdfium::base::CheckMax(left, 0)); pdfium::base::CheckedNumeric end_col_safe = left; diff --git a/core/fxge/ge/fx_ge_text.cpp b/core/fxge/ge/fx_ge_text.cpp index cc7ef7c6d7..669969db0b 100644 --- a/core/fxge/ge/fx_ge_text.cpp +++ b/core/fxge/ge/fx_ge_text.cpp @@ -28,6 +28,12 @@ void ResetTransform(FT_Face face) { } // namespace +FXTEXT_GLYPHPOS::FXTEXT_GLYPHPOS() : m_pGlyph(nullptr) {} + +FXTEXT_GLYPHPOS::FXTEXT_GLYPHPOS(const FXTEXT_GLYPHPOS&) = default; + +FXTEXT_GLYPHPOS::~FXTEXT_GLYPHPOS(){}; + ScopedFontTransform::ScopedFontTransform(FT_Face face, FXFT_Matrix* matrix) : m_Face(face) { FXFT_Set_Transform(m_Face, matrix, 0); @@ -48,7 +54,7 @@ FX_RECT FXGE_GetGlyphsBBox(const std::vector& glyphs, if (!pGlyph) continue; - FX_SAFE_INT32 char_left = glyph.m_OriginX; + FX_SAFE_INT32 char_left = glyph.m_Origin.x; char_left += pGlyph->m_Left; if (!char_left.IsValid()) continue; @@ -64,7 +70,7 @@ FX_RECT FXGE_GetGlyphsBBox(const std::vector& glyphs, if (!char_right.IsValid()) continue; - FX_SAFE_INT32 char_top = glyph.m_OriginY; + FX_SAFE_INT32 char_top = glyph.m_Origin.y; char_top -= pGlyph->m_Top; if (!char_top.IsValid()) continue; diff --git a/core/fxge/win32/fx_win32_print.cpp b/core/fxge/win32/fx_win32_print.cpp index 3b0c6969f9..cda83ebc95 100644 --- a/core/fxge/win32/fx_win32_print.cpp +++ b/core/fxge/win32/fx_win32_print.cpp @@ -296,11 +296,11 @@ bool CGdiPrinterDriver::DrawDeviceText(int nChars, ASSERT(charpos.m_AdjustMatrix[1] == 0); ASSERT(charpos.m_AdjustMatrix[2] == 0); ASSERT(charpos.m_AdjustMatrix[3] == 0); - ASSERT(charpos.m_OriginY == 0); + ASSERT(charpos.m_Origin.y == 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 fOriginX = charpos.m_Origin.x * kScaleFactor; FX_FLOAT fPixelSpacing = fOriginX - fPreviousOriginX; spacing[i] = FXSYS_round(fPixelSpacing); fPreviousOriginX = fOriginX - (fPixelSpacing - spacing[i]); -- cgit v1.2.3