void CFFL_InteractiveFormFiller::QueryWherePopup( const CPWL_Wnd::PrivateData* pAttached, float fPopupMin, float fPopupMax, bool* bBottom, float* fPopupRet) { auto* pData = static_cast<const CFFL_PrivateData*>(pAttached); CPDFSDK_Widget* pWidget = pData->pWidget; CPDF_Page* pPage = pWidget->GetPDFPage(); CFX_FloatRect rcPageView(0, pPage->GetPageHeight(), pPage->GetPageWidth(), 0); rcPageView.Normalize(); CFX_FloatRect rcAnnot = pWidget->GetRect(); float fTop = 0.0f; float fBottom = 0.0f; switch (pWidget->GetRotate() / 90) { default: case 0: fTop = rcPageView.top - rcAnnot.top; fBottom = rcAnnot.bottom - rcPageView.bottom; break; case 1: fTop = rcAnnot.left - rcPageView.left; fBottom = rcPageView.right - rcAnnot.right; break; case 2: fTop = rcAnnot.bottom - rcPageView.bottom; fBottom = rcPageView.top - rcAnnot.top; break; case 3: fTop = rcPageView.right - rcAnnot.right; fBottom = rcAnnot.left - rcPageView.left; break; } constexpr float kMaxListBoxHeight = 140; const float fMaxListBoxHeight = pdfium::clamp(kMaxListBoxHeight, fPopupMin, fPopupMax); if (fBottom > fMaxListBoxHeight) { *fPopupRet = fMaxListBoxHeight; *bBottom = true; return; } if (fTop > fMaxListBoxHeight) { *fPopupRet = fMaxListBoxHeight; *bBottom = false; return; } if (fTop > fBottom) { *fPopupRet = fTop; *bBottom = false; } else { *fPopupRet = fBottom; *bBottom = true; } }
static void CheckRotate(CPDF_Page& page, CFX_FloatRect& page_bbox) { int total_count = 0, rotated_count[3] = {0, 0, 0}; FX_POSITION pos = page.GetFirstObjectPosition(); while (pos) { CPDF_PageObject* pObj = page.GetNextObject(pos); if (pObj->m_Type != PDFPAGE_TEXT) { continue; } total_count ++; CPDF_TextObject* pText = (CPDF_TextObject*)pObj; FX_FLOAT angle = pText->m_TextState.GetBaselineAngle(); if (angle == 0.0) { continue; } int degree = (int)(angle * 180 / PI + 0.5); if (degree % 90) { continue; } if (degree < 0) { degree += 360; } int index = degree / 90 % 3 - 1; if (index < 0) { continue; } rotated_count[index] ++; } if (total_count == 0) { return; } CFX_AffineMatrix matrix; if (rotated_count[0] > total_count * 2 / 3) { matrix.Set(0, -1, 1, 0, 0, page.GetPageHeight()); } else if (rotated_count[1] > total_count * 2 / 3) { matrix.Set(-1, 0, 0, -1, page.GetPageWidth(), page.GetPageHeight()); } else if (rotated_count[2] > total_count * 2 / 3) { matrix.Set(0, 1, -1, 0, page.GetPageWidth(), 0); } else { return; } page.Transform(matrix); page_bbox.Transform(&matrix); }
DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document, int page_index, double* width, double* height) { CPDF_Document* pDoc = (CPDF_Document*)document; if(pDoc == NULL) return FALSE; CPDF_Dictionary* pDict = pDoc->GetPage(page_index); if (pDict == NULL) return FALSE; CPDF_Page page; page.Load(pDoc, pDict); *width = page.GetPageWidth(); *height = page.GetPageHeight(); return TRUE; }