Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(551)

Side by Side Diff: core/src/fpdftext/fpdf_text_int.cpp

Issue 1567343002: Switch most min/max macros to std::min/max. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: actually compile Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fpdfdoc/pdf_vt.h ('k') | core/src/fxcrt/extension.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <cctype> 8 #include <cctype>
9 #include <cwctype> 9 #include <cwctype>
10 #include <memory> 10 #include <memory>
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 int nCount = m_charList.GetSize(); 154 int nCount = m_charList.GetSize();
155 if (nCount) { 155 if (nCount) {
156 m_CharIndex.Add(0); 156 m_CharIndex.Add(0);
157 } 157 }
158 for (int i = 0; i < nCount; i++) { 158 for (int i = 0; i < nCount; i++) {
159 int indexSize = m_CharIndex.GetSize(); 159 int indexSize = m_CharIndex.GetSize();
160 FX_BOOL bNormal = FALSE; 160 FX_BOOL bNormal = FALSE;
161 PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(i); 161 PAGECHAR_INFO charinfo = *(PAGECHAR_INFO*)m_charList.GetAt(i);
162 if (charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) { 162 if (charinfo.m_Flag == FPDFTEXT_CHAR_GENERATED) {
163 bNormal = TRUE; 163 bNormal = TRUE;
164 } else if (charinfo.m_Unicode == 0 || IsControlChar(charinfo)) 164 } else if (charinfo.m_Unicode == 0 || IsControlChar(charinfo)) {
165 bNormal = FALSE; 165 bNormal = FALSE;
166 else { 166 } else {
167 bNormal = TRUE; 167 bNormal = TRUE;
168 } 168 }
169 if (bNormal) { 169 if (bNormal) {
170 if (indexSize % 2) { 170 if (indexSize % 2) {
171 m_CharIndex.Add(1); 171 m_CharIndex.Add(1);
172 } else { 172 } else {
173 if (indexSize <= 0) { 173 if (indexSize <= 0) {
174 continue; 174 continue;
175 } 175 }
176 m_CharIndex.SetAt(indexSize - 1, 176 m_CharIndex.SetAt(indexSize - 1,
(...skipping 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 PAGECHAR_INFO preChar; 1800 PAGECHAR_INFO preChar;
1801 if (size) { 1801 if (size) {
1802 preChar = (PAGECHAR_INFO)m_TempCharList[size - 1]; 1802 preChar = (PAGECHAR_INFO)m_TempCharList[size - 1];
1803 } else { 1803 } else {
1804 size = m_charList.GetSize(); 1804 size = m_charList.GetSize();
1805 if (size == 0) { 1805 if (size == 0) {
1806 return FALSE; 1806 return FALSE;
1807 } 1807 }
1808 preChar = (PAGECHAR_INFO)m_charList[size - 1]; 1808 preChar = (PAGECHAR_INFO)m_charList[size - 1];
1809 } 1809 }
1810 if (FPDFTEXT_CHAR_PIECE == preChar.m_Flag) 1810 if (FPDFTEXT_CHAR_PIECE == preChar.m_Flag &&
1811 if (0xAD == preChar.m_Unicode || 0x2D == preChar.m_Unicode) { 1811 (0xAD == preChar.m_Unicode || 0x2D == preChar.m_Unicode)) {
1812 return TRUE; 1812 return TRUE;
1813 } 1813 }
1814 } 1814 }
1815 return FALSE; 1815 return FALSE;
1816 } 1816 }
1817 int CPDF_TextPage::ProcessInsertObject(const CPDF_TextObject* pObj, 1817 int CPDF_TextPage::ProcessInsertObject(const CPDF_TextObject* pObj,
1818 const CFX_Matrix& formMatrix) { 1818 const CFX_Matrix& formMatrix) {
1819 FindPreviousTextObject(); 1819 FindPreviousTextObject();
1820 FX_BOOL bNewline = FALSE; 1820 FX_BOOL bNewline = FALSE;
1821 int WritingMode = GetTextObjectWritingMode(pObj); 1821 int WritingMode = GetTextObjectWritingMode(pObj);
1822 if (WritingMode == -1) { 1822 if (WritingMode == -1) {
1823 WritingMode = GetTextObjectWritingMode(m_pPreTextObj); 1823 WritingMode = GetTextObjectWritingMode(m_pPreTextObj);
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1913 CFX_FloatRect re(0, pObj->m_Bottom, 1000, pObj->m_Top); 1913 CFX_FloatRect re(0, pObj->m_Bottom, 1000, pObj->m_Top);
1914 if (re.Contains(m_pPreTextObj->GetPosX(), 1914 if (re.Contains(m_pPreTextObj->GetPosX(),
1915 m_pPreTextObj->GetPosY())) { 1915 m_pPreTextObj->GetPosY())) {
1916 bNewline = FALSE; 1916 bNewline = FALSE;
1917 } 1917 }
1918 } 1918 }
1919 } 1919 }
1920 } 1920 }
1921 } 1921 }
1922 } 1922 }
1923 if (bNewline) { 1923 if (bNewline)
1924 if (IsHyphen(curChar)) { 1924 return IsHyphen(curChar) ? 3 : 2;
1925 return 3; 1925
1926 } 1926 int32_t nChars = pObj->CountChars();
1927 return 2; 1927 if (nChars == 1 && (0x2D == curChar || 0xAD == curChar) &&
1928 IsHyphen(curChar)) {
1929 return 3;
1928 } 1930 }
1929 int32_t nChars = pObj->CountChars();
1930 if (nChars == 1 && (0x2D == curChar || 0xAD == curChar))
1931 if (IsHyphen(curChar)) {
1932 return 3;
1933 }
1934 CFX_WideString PrevStr = 1931 CFX_WideString PrevStr =
1935 m_pPreTextObj->GetFont()->UnicodeFromCharCode(PrevItem.m_CharCode); 1932 m_pPreTextObj->GetFont()->UnicodeFromCharCode(PrevItem.m_CharCode);
1936 FX_WCHAR preChar = PrevStr.GetAt(PrevStr.GetLength() - 1); 1933 FX_WCHAR preChar = PrevStr.GetAt(PrevStr.GetLength() - 1);
1937 CFX_Matrix matrix; 1934 CFX_Matrix matrix;
1938 pObj->GetTextMatrix(&matrix); 1935 pObj->GetTextMatrix(&matrix);
1939 matrix.Concat(formMatrix); 1936 matrix.Concat(formMatrix);
1940 threshold = (FX_FLOAT)(nLastWidth > nThisWidth ? nLastWidth : nThisWidth); 1937 threshold = (FX_FLOAT)(nLastWidth > nThisWidth ? nLastWidth : nThisWidth);
1941 threshold = threshold > 400 1938 threshold = threshold > 400
1942 ? (threshold < 700 1939 ? (threshold < 700
1943 ? threshold / 4 1940 ? threshold / 4
1944 : (threshold > 800 ? threshold / 6 : threshold / 5)) 1941 : (threshold > 800 ? threshold / 6 : threshold / 5))
1945 : (threshold / 2); 1942 : (threshold / 2);
1946 if (nLastWidth >= nThisWidth) { 1943 if (nLastWidth >= nThisWidth) {
1947 threshold *= FXSYS_fabs(m_pPreTextObj->GetFontSize()); 1944 threshold *= FXSYS_fabs(m_pPreTextObj->GetFontSize());
1948 } else { 1945 } else {
1949 threshold *= FXSYS_fabs(pObj->GetFontSize()); 1946 threshold *= FXSYS_fabs(pObj->GetFontSize());
1950 threshold = matrix.TransformDistance(threshold); 1947 threshold = matrix.TransformDistance(threshold);
1951 threshold = prev_reverse.TransformDistance(threshold); 1948 threshold = prev_reverse.TransformDistance(threshold);
1952 } 1949 }
1953 threshold /= 1000; 1950 threshold /= 1000;
1954 if ((threshold < 1.4881 && threshold > 1.4879) || 1951 if ((threshold < 1.4881 && threshold > 1.4879) ||
1955 (threshold < 1.39001 && threshold > 1.38999)) { 1952 (threshold < 1.39001 && threshold > 1.38999)) {
1956 threshold *= 1.5; 1953 threshold *= 1.5;
1957 } 1954 }
1958 if (FXSYS_fabs(last_pos + last_width - x) > threshold && curChar != L' ' && 1955 if (FXSYS_fabs(last_pos + last_width - x) > threshold && curChar != L' ' &&
1959 preChar != L' ') 1956 preChar != L' ') {
1960 if (curChar != L' ' && preChar != L' ') { 1957 if (curChar != L' ' && preChar != L' ') {
1961 if ((x - last_pos - last_width) > threshold || 1958 if ((x - last_pos - last_width) > threshold ||
1962 (last_pos - x - last_width) > threshold) { 1959 (last_pos - x - last_width) > threshold) {
1963 return 1; 1960 return 1;
1964 } 1961 }
1965 if (x < 0 && (last_pos - x - last_width) > threshold) { 1962 if (x < 0 && (last_pos - x - last_width) > threshold) {
1966 return 1; 1963 return 1;
1967 } 1964 }
1968 if ((x - last_pos - last_width) > this_width || 1965 if ((x - last_pos - last_width) > this_width ||
1969 (x - last_pos - this_width) > last_width) { 1966 (x - last_pos - this_width) > last_width) {
1970 return 1; 1967 return 1;
1971 } 1968 }
1972 } 1969 }
1970 }
1973 return 0; 1971 return 0;
1974 } 1972 }
1975 FX_BOOL CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1, 1973 FX_BOOL CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1,
1976 CPDF_TextObject* pTextObj2) { 1974 CPDF_TextObject* pTextObj2) {
1977 if (!pTextObj1 || !pTextObj2) { 1975 if (!pTextObj1 || !pTextObj2) {
1978 return FALSE; 1976 return FALSE;
1979 } 1977 }
1980 CFX_FloatRect rcPreObj(pTextObj2->m_Left, pTextObj2->m_Bottom, 1978 CFX_FloatRect rcPreObj(pTextObj2->m_Left, pTextObj2->m_Bottom,
1981 pTextObj2->m_Right, pTextObj2->m_Top); 1979 pTextObj2->m_Right, pTextObj2->m_Top);
1982 CFX_FloatRect rcCurObj(pTextObj1->m_Left, pTextObj1->m_Bottom, 1980 CFX_FloatRect rcCurObj(pTextObj1->m_Left, pTextObj1->m_Bottom,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 pTextObj2->GetItemInfo(i, &itemPer); 2014 pTextObj2->GetItemInfo(i, &itemPer);
2017 pTextObj1->GetItemInfo(i, &itemCur); 2015 pTextObj1->GetItemInfo(i, &itemCur);
2018 if (itemCur.m_CharCode != itemPer.m_CharCode) { 2016 if (itemCur.m_CharCode != itemPer.m_CharCode) {
2019 return FALSE; 2017 return FALSE;
2020 } 2018 }
2021 } 2019 }
2022 if (FXSYS_fabs(pTextObj1->GetPosX() - pTextObj2->GetPosX()) > 2020 if (FXSYS_fabs(pTextObj1->GetPosX() - pTextObj2->GetPosX()) >
2023 GetCharWidth(itemPer.m_CharCode, pTextObj2->GetFont()) * 2021 GetCharWidth(itemPer.m_CharCode, pTextObj2->GetFont()) *
2024 pTextObj2->GetFontSize() / 1000 * 0.9 || 2022 pTextObj2->GetFontSize() / 1000 * 0.9 ||
2025 FXSYS_fabs(pTextObj1->GetPosY() - pTextObj2->GetPosY()) > 2023 FXSYS_fabs(pTextObj1->GetPosY() - pTextObj2->GetPosY()) >
2026 FX_MAX(FX_MAX(rcPreObj.Height(), rcPreObj.Width()), 2024 std::max(std::max(rcPreObj.Height(), rcPreObj.Width()),
2027 pTextObj2->GetFontSize()) / 2025 pTextObj2->GetFontSize()) /
2028 8) { 2026 8) {
2029 return FALSE; 2027 return FALSE;
2030 } 2028 }
2031 return TRUE; 2029 return TRUE;
2032 } 2030 }
2033 FX_BOOL CPDF_TextPage::IsSameAsPreTextObject(CPDF_TextObject* pTextObj, 2031 FX_BOOL CPDF_TextPage::IsSameAsPreTextObject(CPDF_TextObject* pTextObj,
2034 FX_POSITION ObjPos) { 2032 FX_POSITION ObjPos) {
2035 if (!pTextObj) { 2033 if (!pTextObj) {
2036 return FALSE; 2034 return FALSE;
2037 } 2035 }
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
2716 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) { 2714 if (!m_bIsParsed || index < 0 || index >= m_LinkList.GetSize()) {
2717 return; 2715 return;
2718 } 2716 }
2719 CPDF_LinkExt* link = NULL; 2717 CPDF_LinkExt* link = NULL;
2720 link = m_LinkList.GetAt(index); 2718 link = m_LinkList.GetAt(index);
2721 if (!link) { 2719 if (!link) {
2722 return; 2720 return;
2723 } 2721 }
2724 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects); 2722 m_pTextPage->GetRectArray(link->m_Start, link->m_Count, rects);
2725 } 2723 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/pdf_vt.h ('k') | core/src/fxcrt/extension.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698