CFX_FloatRect CPDF_ClipPath::GetClipBox() const { CFX_FloatRect rect; bool bStarted = false; if (GetPathCount() > 0) { rect = GetPath(0).GetBoundingBox(); for (size_t i = 1; i < GetPathCount(); ++i) { CFX_FloatRect path_rect = GetPath(i).GetBoundingBox(); rect.Intersect(path_rect); } bStarted = true; } CFX_FloatRect layer_rect; bool bLayerStarted = false; for (size_t i = 0; i < GetTextCount(); ++i) { CPDF_TextObject* pTextObj = GetText(i); if (pTextObj) { if (bLayerStarted) { layer_rect.Union(CFX_FloatRect(pTextObj->GetBBox())); } else { layer_rect = CFX_FloatRect(pTextObj->GetBBox()); bLayerStarted = true; } } else { if (bStarted) { rect.Intersect(layer_rect); } else { rect = layer_rect; bStarted = true; } bLayerStarted = false; } } return rect; }
void CPWL_ListBox::DrawThisAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device) { CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); if (m_pList) { CFX_FloatRect rcPlate = m_pList->GetPlateRect(); CFX_FloatRect rcList = GetListRect(); CFX_FloatRect rcClient = GetClientRect(); for (int32_t i = 0, sz = m_pList->GetCount(); i < sz; i++) { CFX_FloatRect rcItem = m_pList->GetItemRect(i); if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom) continue; CFX_FloatPoint ptOffset(rcItem.left, (rcItem.top + rcItem.bottom) * 0.5f); if (IFX_Edit* pEdit = m_pList->GetItemEdit(i)) { CFX_FloatRect rcContent = pEdit->GetContentRect(); if (rcContent.Width() > rcClient.Width()) rcItem.Intersect(rcList); else rcItem.Intersect(rcClient); } if (m_pList->IsItemSelected(i)) { CFX_SystemHandler* pSysHandler = GetSystemHandler(); if (pSysHandler && pSysHandler->IsSelectionImplemented()) { IFX_Edit::DrawEdit( pDevice, pUser2Device, m_pList->GetItemEdit(i), CPWL_Utils::PWLColorToFXColor(GetTextColor()), CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor()), rcList, ptOffset, nullptr, pSysHandler, m_pFormFiller); pSysHandler->OutputSelectedRect(m_pFormFiller, rcItem); } else { CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcItem, ArgbEncode(255, 0, 51, 113)); IFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), ArgbEncode(255, 255, 255, 255), 0, rcList, ptOffset, nullptr, pSysHandler, m_pFormFiller); } } else { CFX_SystemHandler* pSysHandler = GetSystemHandler(); IFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), CPWL_Utils::PWLColorToFXColor(GetTextColor()), CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor()), rcList, ptOffset, nullptr, pSysHandler, nullptr); } } } }
void CPWL_Caret::DrawThisAppearance(CFX_RenderDevice* pDevice, CFX_Matrix* pUser2Device) { if (IsVisible() && m_bFlash) { CFX_FloatRect rcRect = GetCaretRect(); CFX_FloatRect rcClip = GetClipRect(); CFX_PathData path; path.SetPointCount(2); FX_FLOAT fCaretX = rcRect.left + m_fWidth * 0.5f; FX_FLOAT fCaretTop = rcRect.top; FX_FLOAT fCaretBottom = rcRect.bottom; if (!rcClip.IsEmpty()) { rcRect.Intersect(rcClip); if (!rcRect.IsEmpty()) { fCaretTop = rcRect.top; fCaretBottom = rcRect.bottom; path.SetPoint(0, fCaretX, fCaretBottom, FXPT_MOVETO); path.SetPoint(1, fCaretX, fCaretTop, FXPT_LINETO); } else { return; } } else { path.SetPoint(0, fCaretX, fCaretBottom, FXPT_MOVETO); path.SetPoint(1, fCaretX, fCaretTop, FXPT_LINETO); } CFX_GraphStateData gsd; gsd.m_LineWidth = m_fWidth; pDevice->DrawPath(&path, pUser2Device, &gsd, 0, ArgbEncode(255, 0, 0, 0), FXFILL_ALTERNATE); } }
CFX_FloatRect CPWL_ListBox::GetFocusRect() const { if (m_pList->IsMultipleSel()) { CFX_FloatRect rcCaret = m_pList->GetItemRect(m_pList->GetCaret()); rcCaret.Intersect(GetClientRect()); return rcCaret; } return CPWL_Wnd::GetFocusRect(); }
bool CPDF_TextPage::IsSameTextObject(CPDF_TextObject* pTextObj1, CPDF_TextObject* pTextObj2) { if (!pTextObj1 || !pTextObj2) return false; CFX_FloatRect rcPreObj = pTextObj2->GetRect(); const CFX_FloatRect& rcCurObj = pTextObj1->GetRect(); if (rcPreObj.IsEmpty() && rcCurObj.IsEmpty()) { float dbXdif = fabs(rcPreObj.left - rcCurObj.left); size_t nCount = m_CharList.size(); if (nCount >= 2) { PAGECHAR_INFO perCharTemp = m_CharList[nCount - 2]; float dbSpace = perCharTemp.m_CharBox.Width(); if (dbXdif > dbSpace) return false; } } if (!rcPreObj.IsEmpty() || !rcCurObj.IsEmpty()) { rcPreObj.Intersect(rcCurObj); if (rcPreObj.IsEmpty()) return false; if (fabs(rcPreObj.Width() - rcCurObj.Width()) > rcCurObj.Width() / 2) { return false; } if (pTextObj2->GetFontSize() != pTextObj1->GetFontSize()) return false; } size_t nPreCount = pTextObj2->CountItems(); if (nPreCount != pTextObj1->CountItems()) return false; // If both objects have no items, consider them same. if (nPreCount == 0) return true; CPDF_TextObjectItem itemPer; CPDF_TextObjectItem itemCur; for (size_t i = 0; i < nPreCount; ++i) { pTextObj2->GetItemInfo(i, &itemPer); pTextObj1->GetItemInfo(i, &itemCur); if (itemCur.m_CharCode != itemPer.m_CharCode) return false; } CFX_PointF diff = pTextObj1->GetPos() - pTextObj2->GetPos(); float font_size = pTextObj2->GetFontSize(); float char_size = GetCharWidth(itemPer.m_CharCode, pTextObj2->GetFont()); float max_pre_size = std::max(std::max(rcPreObj.Height(), rcPreObj.Width()), font_size); return fabs(diff.x) <= 0.9 * char_size * font_size / 1000 && fabs(diff.y) <= max_pre_size / 8; }
CFX_FloatRect CPDF_ClipPath::GetClipBox() const { CFX_FloatRect rect; bool bStarted = false; int count = GetPathCount(); if (count) { rect = GetPath(0).GetBoundingBox(); for (int i = 1; i < count; i++) { CFX_FloatRect path_rect = GetPath(i).GetBoundingBox(); rect.Intersect(path_rect); } bStarted = true; } count = GetTextCount(); if (count) { CFX_FloatRect layer_rect; bool bLayerStarted = false; for (int i = 0; i < count; i++) { CPDF_TextObject* pTextObj = GetText(i); if (!pTextObj) { if (!bStarted) { rect = layer_rect; bStarted = true; } else { rect.Intersect(layer_rect); } bLayerStarted = false; } else { if (!bLayerStarted) { layer_rect = CFX_FloatRect(pTextObj->GetBBox(nullptr)); bLayerStarted = true; } else { layer_rect.Union(CFX_FloatRect(pTextObj->GetBBox(nullptr))); } } } } return rect; }
void CPDF_StreamContentParser::Handle_ShadeFill() { if (m_Options.m_bTextOnly) { return; } CPDF_Pattern* pPattern = FindPattern(GetString(0), TRUE); if (!pPattern) { return; } if (pPattern->m_PatternType != CPDF_Pattern::SHADING) { return; } CPDF_ShadingPattern* pShading = static_cast<CPDF_ShadingPattern*>(pPattern); if (!pShading->m_bShadingObj) { return; } if (!pShading->Load()) { return; } CPDF_ShadingObject* pObj = new CPDF_ShadingObject; pObj->m_pShading = pShading; SetGraphicStates(pObj, FALSE, FALSE, FALSE); pObj->m_Matrix = m_pCurStates->m_CTM; pObj->m_Matrix.Concat(m_mtContentToUser); CFX_FloatRect bbox; if (!pObj->m_ClipPath.IsNull()) { bbox = pObj->m_ClipPath.GetClipBox(); } else { bbox = m_BBox; } if (pShading->IsMeshShading()) { bbox.Intersect(GetShadingBBox(ToStream(pShading->m_pShadingObj), pShading->m_ShadingType, &pObj->m_Matrix, pShading->m_pFunctions, pShading->m_nFuncs, pShading->m_pCS)); } pObj->m_Left = bbox.left; pObj->m_Right = bbox.right; pObj->m_Top = bbox.top; pObj->m_Bottom = bbox.bottom; m_pObjectList->m_ObjectList.AddTail(pObj); }
void CPWL_Wnd::InvalidateRect(CFX_FloatRect* pRect) { if (IsValid()) { CFX_FloatRect rcRefresh = pRect ? *pRect : GetWindowRect(); if (!HasFlag(PWS_NOREFRESHCLIP)) { CFX_FloatRect rcClip = GetClipRect(); if (!rcClip.IsEmpty()) { rcRefresh.Intersect(rcClip); } } FX_RECT rcWin = PWLtoWnd(rcRefresh); rcWin.left -= PWL_INVALIDATE_INFLATE; rcWin.top -= PWL_INVALIDATE_INFLATE; rcWin.right += PWL_INVALIDATE_INFLATE; rcWin.bottom += PWL_INVALIDATE_INFLATE; if (CFX_SystemHandler* pSH = GetSystemHandler()) { if (FX_HWND hWnd = GetAttachedHWnd()) { pSH->InvalidateRect(hWnd, rcWin); } } } }