From 2c02faed1da2375a91c7f9c003beb606a0611074 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 16 Feb 2017 13:42:11 -0500 Subject: Change FXTEXT_CHARPOS to use CFX_PointF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL updates the Origin x,y coordinates in FXTEXT_CHARPOS to be an CFX_PointF. Change-Id: I67281db2cb82687e12490145f7c99aee908e5fa8 Reviewed-on: https://pdfium-review.googlesource.com/2718 Commit-Queue: dsinclair Reviewed-by: Nicolás Peña --- core/fpdfapi/render/cpdf_charposlist.cpp | 32 +++++++++++++++++------------- core/fpdfapi/render/cpdf_renderstatus.cpp | 4 ++-- core/fxge/apple/fx_apple_platform.cpp | 8 +++----- core/fxge/cfx_renderdevice.h | 10 +++++++--- core/fxge/ge/cfx_renderdevice.cpp | 24 ++++++++++++++++++---- core/fxge/ifx_renderdevicedriver.h | 2 +- core/fxge/skia/fx_skia_device.cpp | 9 +++++---- core/fxge/skia/fx_skia_device.h | 2 +- core/fxge/skia/fx_skia_device_unittest.cpp | 3 +-- core/fxge/win32/cfx_psrenderer.cpp | 2 +- core/fxge/win32/cfx_psrenderer.h | 2 +- core/fxge/win32/win32_int.h | 2 +- 12 files changed, 61 insertions(+), 39 deletions(-) (limited to 'core') diff --git a/core/fpdfapi/render/cpdf_charposlist.cpp b/core/fpdfapi/render/cpdf_charposlist.cpp index 64176fb054..639bdcf17b 100644 --- a/core/fpdfapi/render/cpdf_charposlist.cpp +++ b/core/fpdfapi/render/cpdf_charposlist.cpp @@ -32,10 +32,12 @@ void CPDF_CharPosList::Load(const std::vector& charCodes, uint32_t CharCode = charCodes[iChar]; if (CharCode == static_cast(-1)) continue; + bool bVert = false; FXTEXT_CHARPOS& charpos = m_pCharPos[m_nChars++]; if (pCIDFont) charpos.m_bFontStyle = true; + charpos.m_GlyphIndex = pFont->GlyphFromCharCode(CharCode, &bVert); if (charpos.m_GlyphIndex != static_cast(-1)) { charpos.m_FallbackFontPosition = -1; @@ -45,39 +47,41 @@ void CPDF_CharPosList::Load(const std::vector& charCodes, charpos.m_GlyphIndex = pFont->FallbackGlyphFromCharcode( charpos.m_FallbackFontPosition, CharCode); } + // TODO(npm): Figure out how this affects m_ExtGID #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode); #endif - if (!pFont->IsEmbedded() && !pFont->IsCIDFont()) { + if (!pFont->IsEmbedded() && !pFont->IsCIDFont()) charpos.m_FontCharWidth = pFont->GetCharWidthF(CharCode); - } else { + else charpos.m_FontCharWidth = 0; - } - charpos.m_OriginX = iChar ? charPos[iChar - 1] : 0; - charpos.m_OriginY = 0; + + charpos.m_Origin = CFX_PointF(iChar ? charPos[iChar - 1] : 0, 0); charpos.m_bGlyphAdjust = false; - if (!pCIDFont) { + if (!pCIDFont) continue; - } + uint16_t CID = pCIDFont->CIDFromCharCode(CharCode); if (bVertWriting) { - charpos.m_OriginY = charpos.m_OriginX; - charpos.m_OriginX = 0; - short vx, vy; + charpos.m_Origin = CFX_PointF(0, charpos.m_Origin.x); + + short vx; + short vy; pCIDFont->GetVertOrigin(CID, vx, vy); - charpos.m_OriginX -= FontSize * vx / 1000; - charpos.m_OriginY -= FontSize * vy / 1000; + charpos.m_Origin.x -= FontSize * vx / 1000; + charpos.m_Origin.y -= FontSize * vy / 1000; } + const uint8_t* pTransform = pCIDFont->GetCIDTransform(CID); if (pTransform && !bVert) { charpos.m_AdjustMatrix[0] = pCIDFont->CIDTransformToFloat(pTransform[0]); charpos.m_AdjustMatrix[2] = pCIDFont->CIDTransformToFloat(pTransform[2]); charpos.m_AdjustMatrix[1] = pCIDFont->CIDTransformToFloat(pTransform[1]); charpos.m_AdjustMatrix[3] = pCIDFont->CIDTransformToFloat(pTransform[3]); - charpos.m_OriginX += + charpos.m_Origin.x += pCIDFont->CIDTransformToFloat(pTransform[4]) * FontSize; - charpos.m_OriginY += + charpos.m_Origin.y += pCIDFont->CIDTransformToFloat(pTransform[5]) * FontSize; charpos.m_bGlyphAdjust = true; } diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp index 60b57600c2..fd44d42484 100644 --- a/core/fpdfapi/render/cpdf_renderstatus.cpp +++ b/core/fpdfapi/render/cpdf_renderstatus.cpp @@ -2001,8 +2001,8 @@ void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); } - matrix.Concat(CFX_Matrix(font_size, 0, 0, font_size, charpos.m_OriginX, - charpos.m_OriginY)); + matrix.Concat(CFX_Matrix(font_size, 0, 0, font_size, charpos.m_Origin.x, + charpos.m_Origin.y)); path.m_Path.Append(pPath, &matrix); path.m_Matrix = *pTextMatrix; path.m_bStroke = bStroke; diff --git a/core/fxge/apple/fx_apple_platform.cpp b/core/fxge/apple/fx_apple_platform.cpp index d6867384e6..f576eb0ba2 100644 --- a/core/fxge/apple/fx_apple_platform.cpp +++ b/core/fxge/apple/fx_apple_platform.cpp @@ -39,9 +39,7 @@ bool CGDrawGlyphRun(CGContextRef pContext, if (bNegSize) font_size = -font_size; - FX_FLOAT ori_x = pCharPos[0].m_OriginX, ori_y = pCharPos[0].m_OriginY; CFX_Matrix new_matrix; - new_matrix.TransformPoint(ori_x, ori_y); if (pObject2Device) new_matrix.Concat(*pObject2Device); @@ -63,10 +61,10 @@ bool CGDrawGlyphRun(CGContextRef pContext, glyph_indices[i] = pCharPos[i].m_ExtGID ? pCharPos[i].m_ExtGID : pCharPos[i].m_GlyphIndex; if (bNegSize) - glyph_positions[i].x = -pCharPos[i].m_OriginX; + glyph_positions[i].x = -pCharPos[i].m_Origin.x; else - glyph_positions[i].x = pCharPos[i].m_OriginX; - glyph_positions[i].y = pCharPos[i].m_OriginY; + glyph_positions[i].x = pCharPos[i].m_Origin.x; + glyph_positions[i].y = pCharPos[i].m_Origin.y; } if (bNegSize) { new_matrix.a = -new_matrix.a; diff --git a/core/fxge/cfx_renderdevice.h b/core/fxge/cfx_renderdevice.h index 2144206e19..2e9abf9963 100644 --- a/core/fxge/cfx_renderdevice.h +++ b/core/fxge/cfx_renderdevice.h @@ -62,10 +62,14 @@ class IFX_RenderDeviceDriver; enum class FXPT_TYPE : uint8_t { LineTo, BezierTo, MoveTo }; -struct FXTEXT_CHARPOS { +class FXTEXT_CHARPOS { + public: + FXTEXT_CHARPOS(); + FXTEXT_CHARPOS(const FXTEXT_CHARPOS&); + ~FXTEXT_CHARPOS(); + FX_FLOAT m_AdjustMatrix[4]; - FX_FLOAT m_OriginX; - FX_FLOAT m_OriginY; + CFX_PointF m_Origin; uint32_t m_GlyphIndex; int32_t m_FontCharWidth; #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ diff --git a/core/fxge/ge/cfx_renderdevice.cpp b/core/fxge/ge/cfx_renderdevice.cpp index d2c677ecc2..f2bf48912c 100644 --- a/core/fxge/ge/cfx_renderdevice.cpp +++ b/core/fxge/ge/cfx_renderdevice.cpp @@ -346,6 +346,21 @@ bool ShouldDrawDeviceText(const CFX_Font* pFont, uint32_t text_flags) { } // namespace +FXTEXT_CHARPOS::FXTEXT_CHARPOS() + : m_GlyphIndex(0), + m_FontCharWidth(0), +#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ + m_ExtGID(0), +#endif + m_FallbackFontPosition(0), + m_bGlyphAdjust(false), + m_bFontStyle(false) { +} + +FXTEXT_CHARPOS::FXTEXT_CHARPOS(const FXTEXT_CHARPOS&) = default; + +FXTEXT_CHARPOS::~FXTEXT_CHARPOS(){}; + CFX_RenderDevice::CFX_RenderDevice() : m_pBitmap(nullptr), m_Width(0), @@ -912,8 +927,9 @@ 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_OriginX; - glyph.m_fOriginY = charpos.m_OriginY; + glyph.m_fOriginX = charpos.m_Origin.x; + glyph.m_fOriginY = charpos.m_Origin.y; + text2Device.TransformPoint(glyph.m_fOriginX, glyph.m_fOriginY); if (anti_alias < FXFT_RENDER_MODE_LCD) glyph.m_OriginX = FXSYS_round(glyph.m_fOriginX); @@ -1069,8 +1085,8 @@ bool CFX_RenderDevice::DrawTextPath(int nChars, charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); } - matrix.Concat(CFX_Matrix(font_size, 0, 0, font_size, charpos.m_OriginX, - charpos.m_OriginY)); + matrix.Concat(CFX_Matrix(font_size, 0, 0, font_size, charpos.m_Origin.x, + charpos.m_Origin.y)); const CFX_PathData* pPath = pFont->LoadGlyphPath(charpos.m_GlyphIndex, charpos.m_FontCharWidth); if (!pPath) diff --git a/core/fxge/ifx_renderdevicedriver.h b/core/fxge/ifx_renderdevicedriver.h index 6a5b63ba32..fd35149e42 100644 --- a/core/fxge/ifx_renderdevicedriver.h +++ b/core/fxge/ifx_renderdevicedriver.h @@ -16,8 +16,8 @@ class CFX_GraphStateData; class CFX_Matrix; class CFX_PathData; class CPDF_ShadingPattern; +class FXTEXT_CHARPOS; class IFX_Pause; -struct FXTEXT_CHARPOS; struct FX_RECT; class IFX_RenderDeviceDriver { diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index 8263cf66f5..431491d826 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp @@ -802,8 +802,9 @@ class SkiaState { vFlip *= -1; for (int index = 0; index < nChars; ++index) { const FXTEXT_CHARPOS& cp = pCharPos[index]; - m_positions[index + count] = {cp.m_OriginX * flip, cp.m_OriginY * vFlip}; - m_glyphs[index + count] = (uint16_t)cp.m_GlyphIndex; + m_positions[index + count] = {cp.m_Origin.x * flip, + cp.m_Origin.y * vFlip}; + m_glyphs[index + count] = static_cast(cp.m_GlyphIndex); } SkPoint delta; if (MatrixOffset(pMatrix, &delta)) { @@ -1289,8 +1290,8 @@ 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 * vFlip}; - glyphs[index] = (uint16_t)cp.m_GlyphIndex; + positions[index] = {cp.m_Origin.x * flip, cp.m_Origin.y * vFlip}; + glyphs[index] = static_cast(cp.m_GlyphIndex); } #ifdef _SKIA_SUPPORT_PATHS_ m_pBitmap->PreMultiply(); diff --git a/core/fxge/skia/fx_skia_device.h b/core/fxge/skia/fx_skia_device.h index ff81daef46..ecb1104518 100644 --- a/core/fxge/skia/fx_skia_device.h +++ b/core/fxge/skia/fx_skia_device.h @@ -13,13 +13,13 @@ #include "core/fxge/cfx_pathdata.h" #include "core/fxge/ifx_renderdevicedriver.h" +class FXTEXT_CHARPOS; class SkCanvas; class SkMatrix; class SkPaint; class SkPath; class SkPictureRecorder; class SkiaState; -struct FXTEXT_CHARPOS; struct SkIRect; class CFX_SkiaDeviceDriver : public IFX_RenderDeviceDriver { diff --git a/core/fxge/skia/fx_skia_device_unittest.cpp b/core/fxge/skia/fx_skia_device_unittest.cpp index 3b799e6190..afd47780d7 100644 --- a/core/fxge/skia/fx_skia_device_unittest.cpp +++ b/core/fxge/skia/fx_skia_device_unittest.cpp @@ -36,8 +36,7 @@ void EmptyTest(CFX_SkiaDeviceDriver* driver, const State&) { void CommonTest(CFX_SkiaDeviceDriver* driver, const State& state) { FXTEXT_CHARPOS charPos[1]; - charPos[0].m_OriginX = 0; - charPos[0].m_OriginY = 1; + charPos[0].m_Origin = CFX_PointF(0, 1); charPos[0].m_GlyphIndex = 1; charPos[0].m_FontCharWidth = 4; diff --git a/core/fxge/win32/cfx_psrenderer.cpp b/core/fxge/win32/cfx_psrenderer.cpp index d5f1f4d91c..32da090ed6 100644 --- a/core/fxge/win32/cfx_psrenderer.cpp +++ b/core/fxge/win32/cfx_psrenderer.cpp @@ -662,7 +662,7 @@ bool CFX_PSRenderer::DrawText(int nChars, buf << "/X" << ps_fontnum << " Ff " << font_size << " Fs Sf "; last_fontnum = ps_fontnum; } - buf << pCharPos[i].m_OriginX << " " << pCharPos[i].m_OriginY << " m"; + buf << pCharPos[i].m_Origin.x << " " << pCharPos[i].m_Origin.y << " m"; CFX_ByteString hex; hex.Format("<%02X>", ps_glyphindex); buf << hex.AsStringC() << "Tj\n"; diff --git a/core/fxge/win32/cfx_psrenderer.h b/core/fxge/win32/cfx_psrenderer.h index e941739f44..163c6180af 100644 --- a/core/fxge/win32/cfx_psrenderer.h +++ b/core/fxge/win32/cfx_psrenderer.h @@ -22,7 +22,7 @@ class CFX_FontCache; class CFX_Matrix; class CFX_PathData; class CPSFont; -struct FXTEXT_CHARPOS; +class FXTEXT_CHARPOS; class CFX_PSRenderer { public: diff --git a/core/fxge/win32/win32_int.h b/core/fxge/win32/win32_int.h index 974a1200e6..f8eae87308 100644 --- a/core/fxge/win32/win32_int.h +++ b/core/fxge/win32/win32_int.h @@ -17,7 +17,7 @@ #include "core/fxge/win32/cpsoutput.h" #include "core/fxge/win32/dwrite_int.h" -struct FXTEXT_CHARPOS; +class FXTEXT_CHARPOS; struct WINDIB_Open_Args_; typedef HANDLE(__stdcall* FuncType_GdiAddFontMemResourceEx)(PVOID pbFont, -- cgit v1.2.3