From d5e7b355b8c4c22ff770547797cbc536bdc95d5b Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 29 Feb 2016 11:24:29 -0800 Subject: Fixup FX_RECT and FX_SMALL_RECT classes. Put these first, so later on more complicated classes can have constructors that take these as arguments. Add better constructors, and call appropriately. Also don't be afraid to return these from methods since RVO. R=dsinclair@chromium.org Review URL: https://codereview.chromium.org/1745683002 . --- core/src/fpdftext/fpdf_text_int.cpp | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'core/src/fpdftext') diff --git a/core/src/fpdftext/fpdf_text_int.cpp b/core/src/fpdftext/fpdf_text_int.cpp index 77b610a7e8..4a0aae501c 100644 --- a/core/src/fpdftext/fpdf_text_int.cpp +++ b/core/src/fpdftext/fpdf_text_int.cpp @@ -884,21 +884,18 @@ void CPDF_TextPage::ProcessFormObject(CPDF_FormObject* pFormObj, } int CPDF_TextPage::GetCharWidth(FX_DWORD charCode, CPDF_Font* pFont) const { - if (charCode == -1) { + if (charCode == -1) return 0; - } - int w = pFont->GetCharWidthF(charCode); - if (w == 0) { - CFX_ByteString str; - pFont->AppendChar(str, charCode); - w = pFont->GetStringWidth(str, 1); - if (w == 0) { - FX_RECT BBox; - pFont->GetCharBBox(charCode, BBox); - w = BBox.right - BBox.left; - } - } - return w; + + if (int w = pFont->GetCharWidthF(charCode)) + return w; + + CFX_ByteString str; + pFont->AppendChar(str, charCode); + if (int w = pFont->GetStringWidth(str, 1)) + return w; + + return pFont->GetCharBBox(charCode).Width(); } void CPDF_TextPage::OnPiece(CFX_BidiChar* pBidi, CFX_WideString& str) { @@ -1464,9 +1461,8 @@ void CPDF_TextPage::ProcessTextObject(PDFTEXT_Obj Obj) { charinfo.m_OriginX = 0, charinfo.m_OriginY = 0; matrix.Transform(item.m_OriginX, item.m_OriginY, charinfo.m_OriginX, charinfo.m_OriginY); - FX_RECT rect(0, 0, 0, 0); - rect.Intersect(0, 0, 0, 0); - charinfo.m_pTextObj->GetFont()->GetCharBBox(charinfo.m_CharCode, rect); + FX_RECT rect = + charinfo.m_pTextObj->GetFont()->GetCharBBox(charinfo.m_CharCode); charinfo.m_CharBox.top = rect.top * pTextObj->GetFontSize() / 1000 + item.m_OriginY; charinfo.m_CharBox.left = -- cgit v1.2.3