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

Side by Side Diff: fpdfsdk/src/fsdk_baseform.cpp

Issue 1422503012: Merge to XFA: Fix incorrect CPDFSDK_PageView::CountAnnots(). (try 2) (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: nit Created 5 years, 1 month 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 | « fpdfsdk/include/fsdk_mgr.h ('k') | fpdfsdk/src/fsdk_mgr.cpp » ('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 "../../third_party/base/nonstd_unique_ptr.h" 7 #include "../../third_party/base/nonstd_unique_ptr.h"
8 #include "../include/fsdk_define.h" 8 #include "../include/fsdk_define.h"
9 #include "../include/fpdfxfa/fpdfxfa_doc.h" 9 #include "../include/fpdfxfa/fpdfxfa_doc.h"
10 #include "../include/fpdfxfa/fpdfxfa_util.h" 10 #include "../include/fpdfxfa/fpdfxfa_util.h"
(...skipping 3098 matching lines...) Expand 10 before | Expand all | Expand 10 after
3109 CPDF_Rect rcAnnot2 = GetAnnotRect(p2); 3109 CPDF_Rect rcAnnot2 = GetAnnotRect(p2);
3110 3110
3111 if (rcAnnot1.top < rcAnnot2.top) 3111 if (rcAnnot1.top < rcAnnot2.top)
3112 return -1; 3112 return -1;
3113 if (rcAnnot1.top > rcAnnot2.top) 3113 if (rcAnnot1.top > rcAnnot2.top)
3114 return 1; 3114 return 1;
3115 return 0; 3115 return 0;
3116 } 3116 }
3117 3117
3118 void CBA_AnnotIterator::GenerateResults() { 3118 void CBA_AnnotIterator::GenerateResults() {
3119 ASSERT(m_pPageView != NULL);
3120
3121 switch (m_nTabs) { 3119 switch (m_nTabs) {
3122 case BAI_STRUCTURE: { 3120 case BAI_STRUCTURE: {
3123 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { 3121 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
3124 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); 3122 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
3125 ASSERT(pAnnot != NULL);
3126
3127 if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType) 3123 if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType)
3128 m_Annots.Add(pAnnot); 3124 m_Annots.Add(pAnnot);
3129 } 3125 }
3130 } break; 3126 break;
3127 }
3131 case BAI_ROW: { 3128 case BAI_ROW: {
3132 CPDFSDK_SortAnnots sa; 3129 CPDFSDK_SortAnnots sa;
3133 3130 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
3134 { 3131 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
3135 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { 3132 if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType)
3136 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); 3133 sa.Add(pAnnot);
3137 ASSERT(pAnnot != NULL);
3138
3139 if (pAnnot->GetType() == m_sType &&
3140 pAnnot->GetSubType() == m_sSubType)
3141 sa.Add(pAnnot);
3142 }
3143 } 3134 }
3144 3135
3145 if (sa.GetSize() > 0) { 3136 if (sa.GetSize() > 0)
3146 sa.Sort(CBA_AnnotIterator::CompareByLeft); 3137 sa.Sort(CBA_AnnotIterator::CompareByLeft);
3147 }
3148 3138
3149 while (sa.GetSize() > 0) { 3139 while (sa.GetSize() > 0) {
3150 int nLeftTopIndex = -1; 3140 int nLeftTopIndex = -1;
3141 FX_FLOAT fTop = 0.0f;
3151 3142
3152 { 3143 for (int i = sa.GetSize() - 1; i >= 0; i--) {
3153 FX_FLOAT fTop = 0.0f; 3144 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
3145 ASSERT(pAnnot);
3154 3146
3155 for (int i = sa.GetSize() - 1; i >= 0; i--) { 3147 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
3156 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
3157 ASSERT(pAnnot != NULL);
3158 3148
3159 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot); 3149 if (rcAnnot.top > fTop) {
3160 3150 nLeftTopIndex = i;
3161 if (rcAnnot.top > fTop) { 3151 fTop = rcAnnot.top;
3162 nLeftTopIndex = i;
3163 fTop = rcAnnot.top;
3164 }
3165 } 3152 }
3166 } 3153 }
3167 3154
3168 if (nLeftTopIndex >= 0) { 3155 if (nLeftTopIndex >= 0) {
3169 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex); 3156 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);
3170 ASSERT(pLeftTopAnnot != NULL); 3157 ASSERT(pLeftTopAnnot);
3171 3158
3172 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot); 3159 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
3173 3160
3174 m_Annots.Add(pLeftTopAnnot); 3161 m_Annots.Add(pLeftTopAnnot);
3175 sa.RemoveAt(nLeftTopIndex); 3162 sa.RemoveAt(nLeftTopIndex);
3176 3163
3177 CFX_ArrayTemplate<int> aSelect; 3164 CFX_ArrayTemplate<int> aSelect;
3178 3165
3179 { 3166 for (int i = 0, sz = sa.GetSize(); i < sz; ++i) {
3180 for (int i = 0, sz = sa.GetSize(); i < sz; i++) { 3167 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
3181 CPDFSDK_Annot* pAnnot = sa.GetAt(i); 3168 ASSERT(pAnnot);
3182 ASSERT(pAnnot != NULL);
3183 3169
3184 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot); 3170 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
3185 3171 FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;
3186 FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f; 3172 if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)
3187 3173 aSelect.Add(i);
3188 if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)
3189 aSelect.Add(i);
3190 }
3191 } 3174 }
3192 3175
3193 { 3176 for (int i = 0, sz = aSelect.GetSize(); i < sz; ++i)
3194 for (int i = 0, sz = aSelect.GetSize(); i < sz; i++) { 3177 m_Annots.Add(sa[aSelect[i]]);
3195 m_Annots.Add(sa[aSelect[i]]);
3196 }
3197 }
3198 3178
3199 { 3179 for (int i = aSelect.GetSize() - 1; i >= 0; --i)
3200 for (int i = aSelect.GetSize() - 1; i >= 0; i--) {
3201 sa.RemoveAt(aSelect[i]); 3180 sa.RemoveAt(aSelect[i]);
3202 }
3203 }
3204 3181
3205 aSelect.RemoveAll(); 3182 aSelect.RemoveAll();
3206 } 3183 }
3207 } 3184 }
3208 sa.RemoveAll(); 3185 sa.RemoveAll();
3209 } break; 3186 break;
3187 }
3210 case BAI_COLUMN: { 3188 case BAI_COLUMN: {
3211 CPDFSDK_SortAnnots sa; 3189 CPDFSDK_SortAnnots sa;
3212 3190 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) {
3213 { 3191 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
3214 for (size_t i = 0; i < m_pPageView->CountAnnots(); ++i) { 3192 if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType)
3215 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); 3193 sa.Add(pAnnot);
3216 ASSERT(pAnnot != NULL);
3217
3218 if (pAnnot->GetType() == m_sType &&
3219 pAnnot->GetSubType() == m_sSubType)
3220 sa.Add(pAnnot);
3221 }
3222 } 3194 }
3223 3195
3224 if (sa.GetSize() > 0) { 3196 if (sa.GetSize() > 0)
3225 sa.Sort(CBA_AnnotIterator::CompareByTop, FALSE); 3197 sa.Sort(CBA_AnnotIterator::CompareByTop, FALSE);
3226 }
3227 3198
3228 while (sa.GetSize() > 0) { 3199 while (sa.GetSize() > 0) {
3229 int nLeftTopIndex = -1; 3200 int nLeftTopIndex = -1;
3201 FX_FLOAT fLeft = -1.0f;
3230 3202
3231 { 3203 for (int i = sa.GetSize() - 1; i >= 0; --i) {
3232 FX_FLOAT fLeft = -1.0f; 3204 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
3205 ASSERT(pAnnot);
3233 3206
3234 for (int i = sa.GetSize() - 1; i >= 0; i--) { 3207 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
3235 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
3236 ASSERT(pAnnot != NULL);
3237 3208
3238 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot); 3209 if (fLeft < 0) {
3239 3210 nLeftTopIndex = 0;
3240 if (fLeft < 0) { 3211 fLeft = rcAnnot.left;
3241 nLeftTopIndex = 0; 3212 } else if (rcAnnot.left < fLeft) {
3242 fLeft = rcAnnot.left; 3213 nLeftTopIndex = i;
3243 } else if (rcAnnot.left < fLeft) { 3214 fLeft = rcAnnot.left;
3244 nLeftTopIndex = i;
3245 fLeft = rcAnnot.left;
3246 }
3247 } 3215 }
3248 } 3216 }
3249 3217
3250 if (nLeftTopIndex >= 0) { 3218 if (nLeftTopIndex >= 0) {
3251 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex); 3219 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);
3252 ASSERT(pLeftTopAnnot != NULL); 3220 ASSERT(pLeftTopAnnot);
3253 3221
3254 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot); 3222 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
3255 3223
3256 m_Annots.Add(pLeftTopAnnot); 3224 m_Annots.Add(pLeftTopAnnot);
3257 sa.RemoveAt(nLeftTopIndex); 3225 sa.RemoveAt(nLeftTopIndex);
3258 3226
3259 CFX_ArrayTemplate<int> aSelect; 3227 CFX_ArrayTemplate<int> aSelect;
3228 for (int i = 0, sz = sa.GetSize(); i < sz; ++i) {
3229 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
3230 ASSERT(pAnnot);
3260 3231
3261 { 3232 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
3262 for (int i = 0, sz = sa.GetSize(); i < sz; i++) { 3233 FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;
3263 CPDFSDK_Annot* pAnnot = sa.GetAt(i); 3234 if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right)
3264 ASSERT(pAnnot != NULL); 3235 aSelect.Add(i);
3265
3266 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
3267
3268 FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;
3269
3270 if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right)
3271 aSelect.Add(i);
3272 }
3273 } 3236 }
3274 3237
3275 { 3238 for (int i = 0, sz = aSelect.GetSize(); i < sz; ++i)
3276 for (int i = 0, sz = aSelect.GetSize(); i < sz; i++) { 3239 m_Annots.Add(sa[aSelect[i]]);
3277 m_Annots.Add(sa[aSelect[i]]);
3278 }
3279 }
3280 3240
3281 { 3241 for (int i = aSelect.GetSize() - 1; i >= 0; --i)
3282 for (int i = aSelect.GetSize() - 1; i >= 0; i--) { 3242 sa.RemoveAt(aSelect[i]);
3283 sa.RemoveAt(aSelect[i]);
3284 }
3285 }
3286 3243
3287 aSelect.RemoveAll(); 3244 aSelect.RemoveAll();
3288 } 3245 }
3289 } 3246 }
3290 sa.RemoveAll(); 3247 sa.RemoveAll();
3291 } break; 3248 break;
3249 }
3292 } 3250 }
3293 } 3251 }
3294 3252
3295 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) { 3253 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) {
3296 ASSERT(pAnnot != NULL);
3297
3298 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
3299 ASSERT(pPDFAnnot != NULL);
3300
3301 CPDF_Rect rcAnnot; 3254 CPDF_Rect rcAnnot;
3302 pPDFAnnot->GetRect(rcAnnot); 3255 pAnnot->GetPDFAnnot()->GetRect(rcAnnot);
3303
3304 return rcAnnot; 3256 return rcAnnot;
3305 } 3257 }
OLDNEW
« no previous file with comments | « fpdfsdk/include/fsdk_mgr.h ('k') | fpdfsdk/src/fsdk_mgr.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698